:root {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --text: #17201d;
  --muted: #63706b;
  --line: #dfe7e3;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b42318;
  --soft: #e7f4f1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; color: var(--text); background: var(--bg); }
body.logged-out .sidebar,
body.logged-out .app,
body.logged-out .install-footer { display: none; }
button, input, select { font: inherit; }
button { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; min-height: 42px; padding: 0 14px; cursor: pointer; }
button:hover { border-color: #b7c8c2; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.primary:hover { background: var(--brand-dark); }
.danger-btn { color: var(--danger); border-color: #f0b8b2; }

.sidebar { width: 248px; min-height: 100vh; background: #fff; border-right: 1px solid var(--line); padding: 22px 16px; position: sticky; top: 0; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-mark { width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 800; }
.brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.nav { display: grid; gap: 8px; }
.nav-item { text-align: left; border: 0; background: transparent; color: var(--muted); }
.nav-item.active { background: var(--soft); color: var(--brand-dark); font-weight: 800; }

.app { flex: 1; padding: 26px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.user-chip { min-height: 42px; display: grid; align-content: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.user-chip span { font-weight: 800; line-height: 1.1; }
.user-chip small { color: var(--muted); text-transform: uppercase; font-weight: 800; font-size: 11px; }
.eyebrow { margin: 0 0 4px; color: var(--brand); font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 3vw, 38px); }
h2 { font-size: 18px; margin-bottom: 14px; }
.view { display: none; }
.view.active { display: block; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat, .panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.stat { padding: 18px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; font-size: 28px; margin-top: 8px; }
.stat.danger strong { color: var(--danger); }
.content-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.panel { padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.list { display: grid; gap: 10px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px; background: #f9fbfa; border-radius: 8px; border: 1px solid var(--line); }
.list-item small, .muted { color: var(--muted); }

.toolbar { display: flex; gap: 12px; margin-bottom: 14px; align-items: center; }
.toolbar input, .toolbar select { max-width: 360px; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 8px; min-height: 42px; padding: 0 12px; background: #fff; color: var(--text); }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 14px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; background: #fbfcfc; }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.icon-action { width: 42px; min-width: 42px; height: 42px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); text-decoration: none; }
.icon-action svg { width: 20px; height: 20px; fill: currentColor; }
.icon-action.whatsapp { color: #128c7e; border-color: #b9e7dd; background: #f0fdf9; }
.icon-action.call { color: var(--brand-dark); border-color: #b7d8d2; background: var(--soft); }
.icon-action:hover { border-color: currentColor; }
.tag { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; font-weight: 800; font-size: 12px; }
.tag.paid { background: #dcfce7; color: #166534; }
.tag.partial { background: #fef3c7; color: #92400e; }
.tag.due { background: #fee2e2; color: #991b1b; }
.tag.planned { background: #e0f2fe; color: #075985; }
.tag.done { background: #dcfce7; color: #166534; }
.tag.cancelled { background: #fee2e2; color: #991b1b; }
.session-side { display: grid; justify-items: end; gap: 8px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.card { padding: 16px; }
.card h3 { margin: 0 0 6px; }
.card-meta { color: var(--muted); line-height: 1.6; }
.card-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }
.settings-panel { max-width: 720px; }
.settings-panel + .settings-panel { margin-top: 18px; max-width: none; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.file-btn input { display: none; }
.logo-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.logo-preview { width: 84px; height: 84px; display: grid; place-items: center; overflow: hidden; border-radius: 8px; background: var(--brand); color: #fff; font-size: 26px; font-weight: 900; border: 1px solid var(--line); }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.install-footer { position: fixed; z-index: 8; left: 272px; right: 24px; bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; max-width: 560px; margin-left: auto; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 16px 40px rgba(15, 23, 42, .14); }
.install-footer[hidden] { display: none; }
.install-footer span { color: var(--muted); font-weight: 700; }

dialog { width: min(94vw, 480px); border: 0; border-radius: 8px; padding: 0; box-shadow: 0 30px 80px rgba(0,0,0,.22); }
dialog::backdrop { background: rgba(15, 23, 42, .38); }
.modal-form { padding: 20px; display: grid; gap: 12px; }
.modal-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.login-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: var(--bg); }
body:not(.logged-out) .login-screen { display: none; }
.login-card { width: min(100%, 420px); display: grid; gap: 14px; padding: 22px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 20px 70px rgba(15, 23, 42, .12); }
.login-brand { margin-bottom: 6px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
.login-error { margin: 0; color: var(--danger); font-weight: 800; }
.admin-only { display: none; }
body.is-admin .admin-only { display: block; }

@media (max-width: 900px) {
  body { display: block; padding-bottom: 72px; }
  .sidebar { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; top: auto; width: auto; min-height: 0; padding: 8px; border-right: 0; border-top: 1px solid var(--line); }
  .brand { display: none; }
  .nav { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .nav-item { text-align: center; padding: 0 6px; font-size: 12px; min-height: 48px; }
  .app { padding: 18px; }
  .install-footer { left: 12px; right: 12px; bottom: 78px; max-width: none; }
  .topbar { align-items: flex-start; }
  .top-actions { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar, .toolbar, .list-item, .button-row, .install-footer, .top-actions, .logo-form { flex-direction: column; align-items: stretch; }
  .session-side { justify-items: stretch; }
  .stats-grid { grid-template-columns: 1fr; }
  .app { padding: 14px; }
  .nav-item { font-size: 11px; }
}
