:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }

.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 17px; color: var(--text); }
.topbar .brand span { color: var(--primary); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: 13px; }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.checks { display: flex; gap: 10px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 5px; font-weight: 400; margin: 4px 0; }
.checks input { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  background: var(--primary); color: #fff; transition: background .15s;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: #eff6ff; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border); font-size: 12px; text-transform: uppercase; color: var(--muted); }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-wrap { overflow-x: auto; }

/* toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 1000; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }
#toast.success { background: var(--green); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.hidden { display: none !important; }

/* map */
.map-wrap { position: relative; width: 100%; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; }
.map-wrap svg { display: block; width: 100%; height: auto; touch-action: pinch-zoom; }
svg .area-rect { stroke-width: 2; cursor: pointer; transition: fill-opacity .15s; }
svg .area-label { font-size: 17px; font-weight: 700; pointer-events: none; }
svg .desk { cursor: pointer; outline: none; }
svg .desk circle.vis { stroke: #fff; stroke-width: 2; }
svg .desk text { font-size: 10px; fill: #fff; font-weight: 800; text-anchor: middle; pointer-events: none; }
svg .desk text.sym { font-size: 11px; fill: #1e293b; font-weight: 900; }
svg .desk.available circle.vis { fill: var(--green); }
svg .desk.occupied circle.vis { fill: #64748b; }
svg .desk.mine circle.vis { fill: var(--primary); }
svg .desk.blocked circle.vis { fill: #cbd5e1; stroke: #94a3b8; stroke-dasharray: 3 2; }
svg .desk.occupied, svg .desk.blocked { cursor: not-allowed; }
svg .desk.dimmed { opacity: .25; pointer-events: none; }
svg .desk.selected circle.vis { stroke: #1e293b; stroke-width: 3; }
/* foco visível para navegação por teclado no mapa */
svg .desk:focus-visible circle.vis { stroke: #1e293b; stroke-width: 3.5; }
svg .area-g { outline: none; }
svg .area-g:focus-visible .area-rect { stroke-width: 4; stroke-dasharray: 8 4; }
.map-wrap.loading { opacity: .5; pointer-events: none; }
.map-wrap.day-blocked .desk { opacity: .3; }

/* lista alternativa de mesas (alvo de toque confortável no celular) */
.desk-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.desk-chips button { background: #f0fdf4; color: #166534; border: 2px solid var(--green); min-width: 64px; }
.desk-chips button:hover { background: #dcfce7; }

/* legend */
.legend-item {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px;
  border: 2px solid transparent; cursor: pointer; background: #fff; width: 100%; text-align: left;
}
.legend-item:hover { background: #f8fafc; }
.legend-item.active { border-color: var(--primary); background: #eff6ff; }
.legend-item[aria-disabled="true"] { opacity: .55; }
.legend-swatch { width: 18px; height: 18px; border-radius: 5px; flex-shrink: 0; }
.legend-info { flex: 1; min-width: 0; }
.legend-info b { display: block; font-size: 14px; }
.legend-info small { color: var(--muted); font-size: 12px; display: block; }
.legend-count { font-size: 13px; font-weight: 700; white-space: nowrap; }

.map-key { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.map-key span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* layout app */
.app-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) {
  .app-grid { grid-template-columns: 1fr; }
  .container { padding: 10px; }
}

/* alvos de toque confortáveis em dispositivos touch */
@media (pointer: coarse) {
  button, .btn { min-height: 44px; }
  .btn-sm { padding: 10px 14px; min-height: 44px; }
}

/* tabelas viram cards no celular (use <table class="cards"> + data-label nos <td>) */
@media (max-width: 640px) {
  table.cards thead { display: none; }
  table.cards tr { display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 4px; background: #fff; }
  table.cards td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: none; padding: 5px 10px; text-align: right; }
  table.cards td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: 12px; text-align: left; }
  table.cards td:not([data-label])::before { content: none; }
}

/* tabs (admin) */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
@media (max-width: 700px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs button { white-space: nowrap; border-bottom-width: 4px; }
}
.tabs button {
  background: transparent; color: var(--muted); border-radius: 8px 8px 0 0; font-weight: 600;
  padding: 10px 14px; border-bottom: 3px solid transparent;
}
.tabs button:hover { background: #eff6ff; color: var(--primary); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* auth pages */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { text-align: center; font-size: 26px; font-weight: 800; margin-bottom: 14px; }
.auth-card .logo span { color: var(--primary); }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat .num { font-size: 26px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.bar-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.bar-row .bar-label { width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-track { flex: 1; background: #e2e8f0; border-radius: 4px; height: 16px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 4px; }
.bar-row .bar-val { width: 40px; text-align: right; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty .icon { font-size: 36px; margin-bottom: 8px; }

/* editor */
.editor-grid { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 960px) { .editor-grid { grid-template-columns: 1fr; } }
.editor-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.editor-toolbar button.mode-active { background: #1e293b; }
svg .handle { fill: #fff; stroke: #1e293b; stroke-width: 1.5; cursor: nwse-resize; }
svg .area-rect.selected { stroke-dasharray: 6 3; stroke: #1e293b !important; }

.desk-status-line { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.big-state { font-size: 42px; text-align: center; margin: 10px 0 4px; }
