:root {
  --paper: #f3f4f0;
  --surface: #ffffff;
  --ink: #1d2730;
  --muted: #5f6b70;
  --line: #d8dcd4;
  --accent: #1f6b55;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --online: #2c9a5b;
  --offline: #b4453a;
  --warn: #a86a12;
  --code-bg: #f7f8f5;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", Consolas, "Courier New", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161b1f;
    --surface: #1e252a;
    --ink: #e6ebe8;
    --muted: #9aa6a5;
    --line: #313b40;
    --accent: #4fae8d;
    --accent-ink: #0f1a16;
    --accent-soft: #23362f;
    --online: #4cc07f;
    --offline: #e0705f;
    --warn: #d9a145;
    --code-bg: #192024;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Topo */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; color: var(--muted); }

main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 64px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -0.015em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 7px 14px; border-radius: var(--radius-s); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--offline); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

input[type=text], input[type=password], input[type=search], textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius-s); background: var(--surface);
}
textarea { font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; background: var(--code-bg); }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }

/* Login */
.login {
  max-width: 360px; margin: 12vh auto 0; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
}
.login h1 { margin-bottom: 20px; }
.login .field { margin-bottom: 14px; }
.login .btn { width: 100%; justify-content: center; margin-top: 6px; }
.form-error { color: var(--offline); font-size: 14px; min-height: 21px; margin: 8px 0 0; }

/* Lista de restaurantes */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.add-row { display: flex; gap: 8px; }
.add-row input { width: 260px; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.list-row {
  display: grid; grid-template-columns: 1fr 160px 180px 110px; align-items: center; gap: 16px;
  padding: 14px 18px; border-top: 1px solid var(--line); color: inherit; text-decoration: none;
}
.list-row:first-child { border-top: 0; }
a.list-row:hover { background: var(--accent-soft); }
.list-head { font-size: 13px; color: var(--muted); font-weight: 600; padding-top: 10px; padding-bottom: 10px; }
.list-row .name { font-weight: 600; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* Estado do agente: o ponto é o elemento de destaque do backoffice */
.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--offline); flex: none; }
.status.on .dot { background: var(--online); box-shadow: 0 0 0 0 color-mix(in srgb, var(--online) 60%, transparent); animation: pulse 2s infinite; }
.status.on { color: var(--online); }
.status.off { color: var(--offline); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--online) 55%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .status.on .dot { animation: none; } }

/* Detalhe do restaurante */
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 10px; font-size: 14px; }
.back:hover { color: var(--ink); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.detail-head .status { font-size: 16px; }
.facts { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 10px; font-size: 14px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; font-weight: 500; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.token-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.token { font-family: var(--mono); font-size: 13px; background: var(--code-bg); border: 1px solid var(--line); padding: 6px 10px; border-radius: var(--radius-s); word-break: break-all; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.notice { padding: 10px 14px; border-radius: var(--radius-s); font-size: 14px; margin-top: 10px; }
#app > div > .notice { margin-top: 0; }
.notice.err { background: color-mix(in srgb, var(--offline) 12%, transparent); color: var(--offline); }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }

/* Explorador da estrutura */
.explorer { display: grid; grid-template-columns: 320px 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; min-height: 460px; }
.tables-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tables-tools { padding: 10px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 13px; cursor: pointer; }
.chip[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 400; margin: 0; color: var(--muted); }
.tables { overflow-y: auto; max-height: 560px; }
.table-item {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  padding: 7px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer;
  font-family: var(--mono); font-size: 13px;
}
.table-item:hover { background: var(--accent-soft); }
.table-item[aria-current=true] { background: var(--accent); color: var(--accent-ink); }
.table-item .count { color: var(--muted); font-family: var(--font); font-size: 12px; }
.table-item[aria-current=true] .count { color: inherit; opacity: .85; }
.cols-pane { padding: 16px; overflow: auto; min-width: 0; }
.cols-pane h3 { font-family: var(--mono); font-size: 16px; margin: 0 0 4px; word-break: break-all; }

/* Grelhas */
.grid-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-s); max-height: 520px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
.grid th { position: sticky; top: 0; background: var(--code-bg); font-weight: 600; z-index: 1; }
.grid td { font-family: var(--mono); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.grid td.null { color: var(--muted); font-style: italic; }
.pk { font-size: 11px; font-weight: 700; color: var(--accent); margin-left: 6px; font-family: var(--font); }

.sql-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius-s);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 14px; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .list-row { grid-template-columns: 1fr auto; }
  .list-row .hide-m { display: none; }
  .explorer { grid-template-columns: 1fr; }
  .tables-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .tables { max-height: 280px; }
  .add-row input { width: 100%; }
  .add-row { width: 100%; }
}

/* Registo de teste */
.reg-grid { display: grid; grid-template-columns: repeat(4, minmax(90px, 140px)) 1fr; gap: 10px; margin-bottom: 12px; }
.reg-field label { font-size: 13px; font-weight: 600; }
.reg-field input { margin-top: 4px; font-weight: 400; }
@media (max-width: 860px) { .reg-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- Gestão do menu ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 9px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--ink); }
.tab[aria-current=page] { color: var(--accent); border-bottom-color: var(--accent); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.menu-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.fam-panel { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.fam-list { display: grid; gap: 2px; }
.fam-item { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--radius-s); cursor: pointer; }
.fam-item:hover { background: var(--accent-soft); }
.fam-item.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.fam-item.off .fam-name { color: var(--muted); text-decoration: line-through; }
.fam-name { font-size: 14px; font-weight: 500; }
.count { font-size: 12px; color: var(--muted); }
.mv { display: inline-flex; }
.btn-xs { padding: 2px 7px; font-size: 12px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--warn); border: 1px solid currentColor; border-radius: 999px; padding: 0 6px; margin-left: 6px; vertical-align: middle; }
.prod-rows { display: grid; }
.prod-row { display: grid; grid-template-columns: auto 56px 1fr auto auto auto; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.prod-row:first-child { border-top: 0; }
.prod-row.off .prod-name, .prod-row.off .price { color: var(--muted); }
.prod-row.off .thumb { opacity: .45; }
.thumb { width: 56px; height: 56px; border-radius: var(--radius-s); object-fit: cover; background: var(--code-bg); }
.thumb.empty { display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); }
.prod-name { font-weight: 600; }
.price { font-variant-numeric: tabular-nums; font-weight: 600; }
.modal-wrap { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius-m); width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head, .modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 18px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-body { padding: 18px; overflow: auto; }
.edit-grid { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.img-box { aspect-ratio: 1; border: 1px dashed var(--line); border-radius: var(--radius-m); display: grid; place-items: center; overflow: hidden; background: var(--code-bg); }
.img-box img { width: 100%; height: 100%; object-fit: cover; }
.field { margin-bottom: 14px; }
.field label input, .field label textarea { margin-top: 4px; font-weight: 400; }
textarea.plain { font-family: var(--font); font-size: 14px; background: var(--surface); width: 100%; }
.alerg-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 12px; margin-top: 6px; }
.alerg-grid .check { color: var(--ink); font-size: 14px; }
.mesa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.mesa { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px; display: grid; gap: 8px; }
.mesa.off { opacity: .55; }
.mesa-top { display: flex; gap: 8px; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.panel.empty { text-align: center; color: var(--muted); }
@media (max-width: 860px) {
  .menu-grid, .edit-grid { grid-template-columns: 1fr; }
  .fam-panel { position: static; max-height: none; }
  .prod-row { grid-template-columns: auto 48px 1fr auto; }
  .prod-row .mv, .prod-row .price { display: none; }
}
