/* Wared console: the app's palette (ui/theme/Color.kt). Teal structure, gold accents,
   red for errors only. */
:root {
  --teal: #0F766E;
  --teal-strong: #0B5E58;
  --on-teal: #FFFFFF;
  --gold: #D4A017;
  --bg: #F5F8F7;
  --surface: #FFFFFF;
  --surface-2: #EFF4F3;
  --surface-3: #E3ECEA;
  --ink: #101B1A;
  --muted: #475856;
  --line: #D3DFDC;
  --teal-soft: #CCF3EE;
  --on-teal-soft: #042F2C;
  --gold-soft: #FBEFC4;
  --on-gold-soft: #3D2E00;
  --error: #B42318;
  --error-soft: #FDE7E5;
  --on-error-soft: #5A0D07;
  --shadow: 0 1px 2px rgba(16, 27, 26, 0.06), 0 6px 20px rgba(16, 27, 26, 0.05);
  --radius: 16px;
  --radius-s: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --teal: #2DD4BF;
    --teal-strong: #5EEAD4;
    --on-teal: #00201D;
    --gold: #F2C94C;
    --bg: #0A1312;
    --surface: #111D1C;
    --surface-2: #162423;
    --surface-3: #1D2E2C;
    --ink: #E6F0EE;
    --muted: #A3B6B3;
    --line: #2A3D3B;
    --teal-soft: #0D4F4A;
    --on-teal-soft: #CCF3EE;
    --gold-soft: #4D3A00;
    --on-gold-soft: #FBEFC4;
    --error: #FF8A80;
    --error-soft: #5A0D07;
    --on-error-soft: #FDE7E5;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --teal: #2DD4BF; --teal-strong: #5EEAD4; --on-teal: #00201D; --gold: #F2C94C; --bg: #0A1312; --surface: #111D1C;
  --surface-2: #162423; --surface-3: #1D2E2C; --ink: #E6F0EE; --muted: #A3B6B3; --line: #2A3D3B;
  --teal-soft: #0D4F4A; --on-teal-soft: #CCF3EE; --gold-soft: #4D3A00; --on-gold-soft: #FBEFC4;
  --error: #FF8A80; --error-soft: #5A0D07; --on-error-soft: #FDE7E5; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.icon { flex: none; display: block; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.warn-text { color: var(--on-gold-soft); font-weight: 600; }
.danger-text { color: var(--error); }

.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 1.05rem; }
.brand span { display: block; font-size: 0.8rem; color: var(--muted); }
.account { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-name { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 61px); }
body.panel-open .layout { grid-template-columns: 220px minmax(0, 1fr) 400px; }
body.signed-out .layout { grid-template-columns: minmax(0, 1fr); }
body.signed-out .nav { display: none; }

.nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; border-inline-end: 1px solid var(--line); background: var(--surface); }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--teal-soft); color: var(--on-teal-soft); font-weight: 700; }

.main { padding: 24px; min-width: 0; }
.main:focus { outline: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.two-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }

.panel { border-inline-start: 1px solid var(--line); background: var(--surface); overflow-y: auto; max-height: calc(100vh - 61px); position: sticky; top: 61px; }
.panel-content { padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.privacy-note { display: flex; gap: 8px; align-items: center; }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--teal-soft); }
.stat-gold .stat-icon, .stat-warn .stat-icon { background: var(--gold-soft); }
.stat-warn { border-color: var(--gold); }
.stat-label { display: block; color: var(--muted); font-size: 0.85rem; }
.stat-value { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.bars li { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 12px; }
.bar-track { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--teal); }

.attention { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.attention li { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.attention li.attention-warn, .attention li.attention-gold { background: var(--gold-soft); color: var(--on-gold-soft); }
.attention strong { display: block; }
.attention span { font-size: 0.88rem; }

.pill { display: inline-flex; align-items: center; padding: 1px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.pill-teal { background: var(--teal-soft); color: var(--on-teal-soft); }
.pill-gold, .pill-warn { background: var(--gold-soft); color: var(--on-gold-soft); }
.pill-neutral { background: var(--surface-3); color: var(--muted); }
.count { min-width: 28px; text-align: center; padding: 0 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-weight: 700; }
.count-on { background: var(--gold-soft); color: var(--on-gold-soft); }

.notice { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 12px; background: var(--teal-soft); color: var(--on-teal-soft); }
.notice-warning { background: var(--gold-soft); color: var(--on-gold-soft); }
.notice-error { background: var(--error-soft); color: var(--on-error-soft); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 16px; color: var(--muted); }
.empty strong { color: var(--ink); font-size: 1.1rem; }

.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 32px 0; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--teal); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- Buttons and inputs ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.button.primary { background: var(--teal); color: var(--on-teal); }
.button.primary:hover { background: var(--teal-strong); }
.button.quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.button.quiet:hover { background: var(--surface-2); }
.button.danger { background: var(--error); color: #fff; }
.button.small { min-height: 34px; padding: 0 12px; font-size: 0.88rem; }
.button.large { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }
.button:disabled { opacity: 0.6; cursor: progress; }
.icon-button { width: 40px; height: 40px; border-radius: 12px; border: none; background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-button:hover { background: var(--surface-2); }
.link { border: none; background: none; padding: 0; color: var(--teal); font-weight: 600; cursor: pointer; text-align: start; }
.link:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; flex: 1 1 320px; max-width: 520px; }
.search { border: none; background: transparent; min-height: 44px; width: 100%; }
.search:focus { outline: none; }
.search-box:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }

/* ---------- Tables (cards on small screens) ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th { text-align: start; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 12px 16px; background: var(--surface-2); white-space: nowrap; }
td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
tr.inactive td { opacity: 0.6; }
.rows-clickable tbody tr { cursor: pointer; }
.rows-clickable tbody tr:hover td { background: var(--surface-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.cell-stack { display: flex; flex-direction: column; gap: 2px; }
.cell-stack.end { align-items: flex-end; }

.usage { display: flex; flex-direction: column; gap: 4px; min-width: 120px; font-variant-numeric: tabular-nums; }
.meter { display: block; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 999px; }
.meter-teal { background: var(--teal); }
.meter-gold, .meter-warn { background: var(--gold); }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { padding: 4px 12px; border-radius: 999px; background: var(--teal-soft); color: var(--on-teal-soft); font-size: 0.88rem; }
.chips li.inactive { background: var(--surface-3); color: var(--muted); }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.members li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.members li.inactive { opacity: 0.6; }

/* ---------- Dialogs and forms ---------- */
.dialog { border: none; border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.dialog::backdrop { background: rgba(4, 20, 18, 0.45); }
.dialog header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.dialog-body { padding: 16px 20px; max-height: 70vh; overflow-y: auto; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }
.form { display: flex; flex-direction: column; gap: 6px; }
.form label, .form .label { font-weight: 600; margin-top: 8px; }
.form input:not([type="checkbox"]), .form select {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); width: 100%;
}
.form input:focus, .form select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.form input:disabled { background: var(--surface-2); color: var(--muted); }
.form .hint { font-size: 0.82rem; color: var(--muted); }
.form .check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.form .check input { width: 20px; height: 20px; accent-color: var(--teal); }
.form-error { color: var(--error); font-weight: 600; min-height: 1.2em; }
.form-error:empty { display: none; }
.result { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--teal-soft); color: var(--on-teal-soft); font-weight: 600; }
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented button { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--teal); border-color: var(--teal); color: var(--on-teal); font-weight: 700; }

/* ---------- Sign-in gate ---------- */
.gate { max-width: 460px; margin: 10vh auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 40px 28px; box-shadow: var(--shadow); }
.gate p { color: var(--muted); }
.uid { direction: ltr; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); font-size: 0.9rem; word-break: break-all; user-select: all; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 20; padding: 0 16px; }
.toast { display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); transition: opacity 0.3s, transform 0.3s; }
.toast-error { background: var(--error); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(8px); }

/* ---------- Small screens ---------- */
@media (max-width: 1100px) {
  body.panel-open .layout { grid-template-columns: 220px minmax(0, 1fr); }
  body.panel-open .panel { position: fixed; inset-block: 0; inset-inline-end: 0; width: min(420px, 100vw); max-height: none; top: 0; z-index: 15; box-shadow: -10px 0 40px rgba(0, 0, 0, 0.2); }
}

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .account-name { display: none; }
  .layout, body.panel-open .layout { grid-template-columns: minmax(0, 1fr); }
  .nav { flex-direction: row; overflow-x: auto; border-inline-end: none; border-bottom: 1px solid var(--line); padding: 8px 12px; position: sticky; top: 57px; z-index: 4; }
  .nav a { flex: none; padding: 8px 12px; }
  .main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px; }
  .stat-icon { width: 40px; height: 40px; }
  .two-columns { grid-template-columns: minmax(0, 1fr); }
  .bars li { grid-template-columns: 80px 1fr auto; }

  .table-wrap { background: none; border: none; box-shadow: none; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; padding: 8px 4px; }
  td { border: none; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
  td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; flex: none; }
  td:not([data-label]) { justify-content: flex-end; }
  .usage { align-items: flex-end; }
  .card .table-wrap tbody tr { background: var(--surface-2); }
}
