/* Mesmos tokens do painel do cliente (app/src/web/public/styles.css), para as duas telas parecerem uma família. */
:root {
  color-scheme: light dark;

  --bg: light-dark(#f6f7f8, #0b0c0e);
  --surface: light-dark(#ffffff, #131418);
  --surface-2: light-dark(#f1f2f4, #1a1c21);
  --surface-3: light-dark(#e8eaed, #23262c);
  --border: light-dark(#e4e6e9, #24272d);
  --border-strong: light-dark(#d3d6db, #33373e);
  --text: light-dark(#0e1116, #eceef2);
  --text-2: light-dark(#454b55, #b9bec8);
  --muted: light-dark(#6b717c, #8b919c);

  --accent: light-dark(#0c9467, #34d399);
  --accent-hover: light-dark(#0a7f58, #5eead4);
  --accent-contrast: light-dark(#ffffff, #04241a);
  --accent-soft: light-dark(#e6f6ef, #0f2a21);
  --accent-soft-text: light-dark(#086848, #6ee7b7);

  --danger: light-dark(#d4383a, #f87171);
  --danger-soft: light-dark(#fdecec, #341618);
  --danger-soft-text: light-dark(#a92527, #fca5a5);
  --warn-soft: light-dark(#fdf3e1, #33260d);
  --warn-soft-text: light-dark(#94600c, #fcd34d);
  --info-soft: light-dark(#e9f0fd, #132036);
  --info-soft-text: light-dark(#2554b8, #93c5fd);

  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px light-dark(rgb(16 24 40 / 0.05), rgb(0 0 0 / 0.4));
  --shadow-lg: 0 24px 64px -16px light-dark(rgb(16 24 40 / 0.28), rgb(0 0 0 / 0.7));

  --font: "Inter", "InterVariable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.015em; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
svg { display: block; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px clamp(16px, 3.5vw, 40px);
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, #10b981, #0b7f5a); color: #fff;
  box-shadow: 0 6px 16px -6px rgb(16 185 129 / 0.6), inset 0 1px 0 rgb(255 255 255 / 0.25);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 13px; }

.main { max-width: 1180px; margin: 0 auto; padding: clamp(20px, 3.5vw, 40px) clamp(16px, 3.5vw, 40px) 64px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { font-size: clamp(22px, 2.4vw, 28px); font-weight: 700; }
.page-header p { color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 18px 20px; }
.stat-value { display: block; font-size: 26px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.stat-sub { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); margin-top: 12px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.4s var(--ease); }
.meter.is-warn > span { background: #e0a100; }
.meter.is-danger > span { background: var(--danger); }

.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.card-header h2 { font-size: 15px; font-weight: 650; }
.search { width: min(260px, 100%); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: 0 1px 0 rgb(255 255 255 / 0.15) inset, var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"]::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite;
}
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.badge-success { background: var(--accent-soft); color: var(--accent-soft-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-soft-text); }
.badge-warn { background: var(--warn-soft); color: var(--warn-soft-text); }
.badge-info { background: var(--info-soft); color: var(--info-soft-text); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; container-type: inline-size; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 12px 22px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 14px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; }
.tenant-name { font-weight: 600; }
.tenant-link { display: block; font-size: 13px; color: var(--muted); text-decoration: none; }
.tenant-link:hover { color: var(--accent); text-decoration: underline; }
.muted { color: var(--muted); font-size: 13px; }
.cell-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty strong { color: var(--text); font-size: 16px; }

@container (max-width: 720px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 16px 18px; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { padding: 3px 0; border: 0; }
  .table td[data-label] { display: flex; gap: 12px; align-items: baseline; }
  .table td[data-label]::before { content: attr(data-label); flex: 0 0 96px; font-size: 12px; color: var(--muted); font-weight: 600; }
  .table td[data-label="Cliente"]::before { display: none; }
  .table td[data-label="Cliente"] { display: block; padding-bottom: 8px; }
  .table .num { text-align: left; }
  .table .actions { text-align: left; padding-top: 10px; }
}

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13.5px; font-weight: 600; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input, .textarea {
  width: 100%; min-height: 40px; padding: 9px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 10px; font: inherit; font-size: 14px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.textarea { min-height: 80px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent); }
.input-affix { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); }
.input-affix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent); }
.input-affix .input { border: 0; box-shadow: none; min-width: 0; }
.input-affix span { display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-size: 14px; border-left: 1px solid var(--border); white-space: nowrap; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }
.form-error { font-size: 13.5px; color: var(--danger); }
.form-error:empty { display: none; }
.mono { font-family: var(--mono); }

/* ---------- Login ---------- */
.login { width: min(400px, calc(100% - 32px)); margin: 14vh auto 0; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.login h1 { font-size: 20px; font-weight: 700; }
.login p { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgb(8 10 14 / 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dialog[open] { animation: dialog-in 0.22s var(--ease); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px 4px; }
.dialog-head h2 { font-size: 18px; font-weight: 700; }
.dialog-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.dialog-body { padding: 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 4px 24px 22px; flex-wrap: wrap; }
.dialog-foot .spacer { flex: 1; }
.dialog-sm { width: min(440px, calc(100vw - 32px)); }

.actions-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.action-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; text-align: left;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.action-tile:hover { border-color: var(--border-strong); background: var(--surface-2); }
.action-tile strong { font-size: 14px; }
.action-tile small { font-size: 12.5px; color: var(--muted); }
.action-tile.is-danger strong { color: var(--danger); }
.section-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.secret { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.secret-body { flex: 1; min-width: 0; }
.secret-body small { display: block; font-size: 12px; color: var(--muted); }
.secret-body span { display: block; font-family: var(--mono); font-size: 15px; overflow-wrap: anywhere; }
.message-box { white-space: pre-wrap; font-size: 13.5px; line-height: 1.55; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.notice { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn-soft-text); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  max-width: min(420px, calc(100vw - 40px)); padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toast-in 0.28s var(--ease); pointer-events: auto;
}
.toast-error { background: var(--danger); color: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .form-row, .actions-grid { grid-template-columns: minmax(0, 1fr); }
  .brand small { display: none; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .card-header { flex-wrap: wrap; }
  .search { width: 100%; }
  .toasts { left: 12px; right: 12px; align-items: stretch; }
  .toast { max-width: none; }
}
