/* ONYX Mail — Tenant Admin Portal
   Customer-facing brand surface, aligned to the onyx.az corporate identity:
   sky-blue accent (the ONYX "x"), Inter type, shared logo + favicon (docs/05 §6).
   Deliberately NOT the grey internal ops-ui. */

:root {
  /* brand palette — onyx.az corporate sky blue (docs/05 §6) */
  --brand: #0284c7;          /* sky-600 — primary buttons, active nav, links */
  --brand-600: #0ea5e9;      /* sky-500 — the ONYX logo accent / hover */
  --brand-700: #0369a1;      /* sky-700 — active nav text, pressed */
  --brand-tint: #e0f2fe;     /* sky-100 — active nav wash */
  --brand-tint-2: #f0f9ff;   /* sky-50 — hovers, table headers */

  --bg: #f8fafc;             /* slate-50 — page background */
  --card: #ffffff;
  --ink: #111827;            /* gray-900 — primary text */
  --muted: #6b7280;          /* gray-500 — secondary text */
  --line: #e5e7eb;           /* gray-200 — borders */
  --line-2: #f1f5f9;         /* slate-100 — subtle dividers */

  --success: #15915b;
  --success-bg: #e6f5ee;
  --warning: #b7791f;
  --warning-bg: #fbf3e3;
  --danger: #d03434;
  --danger-bg: #fbe9e9;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(26,27,46,.05), 0 8px 24px rgba(26,27,46,.06);
  --shadow-lg: 0 12px 48px rgba(26,27,46,.18);
  --sidebar-w: 248px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 0 0 .2rem; }
h3 { font-size: .95rem; font-weight: 700; margin: 0; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------------------------------------------------------------- buttons */
.btn, .btn-ghost, .btn-danger, .btn-sm {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border-radius: var(--radius-sm); font-weight: 600; cursor: pointer;
  padding: .6rem 1.1rem; font-size: .9rem; border: 1px solid transparent;
  transition: filter .12s, background .12s, box-shadow .12s; white-space: nowrap;
}
.btn { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(2,132,199,.3); }
.btn:hover { background: var(--brand-600); }
.btn:disabled { background: #cbd5e1; color:#fff; cursor: not-allowed; filter:none; box-shadow:none; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--brand-tint-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
.btn-danger:disabled { background:#e7b6b6; cursor:not-allowed; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-link {
  background: none; border: 0; color: var(--brand); cursor: pointer;
  font-weight: 600; padding: 0; font-size: .9rem;
}
.btn-link:hover { text-decoration: underline; }
.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.5);
  border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- inputs */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 0 .35rem; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: .62rem .75rem; font-size: .92rem; font-family: inherit;
  color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint);
}
.field { margin-bottom: 1rem; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; font-weight: 400; }
.inline-suffix { display: flex; align-items: stretch; gap: .4rem; }
.inline-suffix input { flex: 1; }
.inline-suffix .suffix {
  display: flex; align-items: center; padding: 0 .7rem; background: var(--brand-tint-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--muted);
  font-size: .9rem; white-space: nowrap;
}
.inline-suffix select { width: auto; }
.radio-row { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; font-weight: 500; color: var(--ink); }
.radio-row input { width: auto; }

/* ---------------------------------------------------------------- toggle */
.toggle { position: relative; display: inline-block; width: 46px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0; background: #cfd2e0; border-radius: 99px; transition: .2s; cursor: pointer;
}
.toggle .track::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .track { background: var(--brand); }
.toggle input:checked + .track::before { transform: translateX(20px); }

/* ---------------------------------------------------------------- layout */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .55rem; padding: .3rem .5rem 1.2rem; }
.brand .logo { height: 24px; width: auto; display: block; flex: none; }
.brand .brand-name { font-weight: 700; letter-spacing: -.01em; color: var(--muted); }
.brand .brand-sub { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .62rem .7rem; border-radius: 9px;
  color: var(--ink); font-weight: 600; font-size: .9rem; text-decoration: none;
}
.nav a .ico { width: 18px; height: 18px; opacity: .65; flex: none; }
.nav a:hover { background: var(--brand-tint-2); }
.nav a.active { background: var(--brand-tint); color: var(--brand-700); }
.nav a.active .ico { opacity: 1; }

.account {
  border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .5rem; position: relative;
}
.account-btn {
  display: flex; align-items: center; gap: .6rem; width: 100%; background: none; border: 0;
  cursor: pointer; padding: .5rem; border-radius: 9px; text-align: left;
}
.account-btn:hover { background: var(--brand-tint-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none;
}
.account-meta { overflow: hidden; }
.account-meta .nm { font-weight: 700; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-meta .rl { font-size: .72rem; color: var(--muted); }
.account-pop {
  position: absolute; bottom: calc(100% + 6px); left: .5rem; right: .5rem;
  background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow-lg);
  padding: .4rem; z-index: 30;
}
.account-pop button, .account-pop .pop-row {
  display: flex; width: 100%; align-items: center; gap: .5rem; background: none; border: 0;
  cursor: pointer; padding: .55rem .6rem; border-radius: 8px; font-size: .88rem; color: var(--ink);
  text-align: left; font-weight: 500;
}
.account-pop button:hover { background: var(--brand-tint-2); }
.account-pop .pop-row { justify-content: space-between; }
.account-pop select { width: auto; padding: .3rem .4rem; font-size: .82rem; }
.account-pop .sep { height: 1px; background: var(--line); margin: .3rem 0; }

/* main column */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar-mobile { display: none; }
.content { padding: 2rem 2.4rem; max-width: 1080px; width: 100%; margin: 0 auto; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem;
}
.page-head .title-wrap { display: flex; align-items: center; gap: .7rem; }
.count-badge {
  font-size: .8rem; font-weight: 700; color: var(--muted); background: var(--line-2);
  padding: .15rem .55rem; border-radius: 99px;
}
.count-badge.danger { color: var(--danger); background: var(--danger-bg); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.3rem;
}
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.section-label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 1.6rem 0 .7rem; }

/* meters */
.meter-card .meter-top { display: flex; justify-content: space-between; align-items: baseline; }
.meter-card .label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.meter-card .big { font-size: 1.7rem; font-weight: 800; margin: .5rem 0 .1rem; letter-spacing: -.02em; }
.meter-card .sub { color: var(--muted); font-size: .85rem; }
.bar { height: 9px; background: var(--line-2); border-radius: 99px; margin: .8rem 0 .2rem; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--success); transition: width .3s; }
.bar.amber > span { background: var(--warning); }
.bar.red > span { background: var(--danger); }

/* quick actions */
.qa-row { display: flex; flex-wrap: wrap; gap: .7rem; }

/* glance */
.glance { display: flex; flex-wrap: wrap; gap: 1.6rem; }
.glance .g { font-size: .9rem; color: var(--muted); }
.glance .g b { color: var(--ink); font-weight: 700; }

/* ---------------------------------------------------------------- banners */
.banner {
  display: flex; align-items: flex-start; gap: .8rem; padding: .9rem 1.1rem; border-radius: var(--radius);
  margin-bottom: 1.2rem; font-size: .9rem;
}
.banner .b-body { flex: 1; }
.banner .b-title { font-weight: 700; }
.banner.warn { background: var(--warning-bg); color: #7a5410; border: 1px solid #f0dcb0; }
.banner.danger { background: var(--danger-bg); color: #9b2020; border: 1px solid #f1c4c4; }
.banner.info { background: var(--brand-tint); color: var(--brand-700); border: 1px solid #d8d2f7; }
.banner .btn-sm { background:#fff; color: var(--ink); border:1px solid rgba(0,0,0,.12); }

/* ---------------------------------------------------------------- tables */
.toolbar { display: flex; gap: .7rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .search { max-width: 340px; flex: 1; min-width: 200px; }
.toolbar .filter { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.toolbar .filter select { width: auto; }

.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: .8rem 1rem; font-size: .9rem; vertical-align: middle; }
.grid thead th {
  background: var(--brand-tint-2); color: var(--muted); font-weight: 700; font-size: .76rem;
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line);
}
.grid tbody tr { border-bottom: 1px solid var(--line-2); }
.grid tbody tr:last-child { border-bottom: 0; }
.grid tbody tr:hover { background: var(--brand-tint-2); }
.grid .actions { text-align: right; white-space: nowrap; }
.user-name { font-weight: 700; }
.user-addr { color: var(--muted); font-size: .83rem; }
.mini-bar { height: 5px; width: 110px; background: var(--line-2); border-radius: 99px; margin-top: .3rem; overflow: hidden; }
.mini-bar > span { display: block; height: 100%; background: var(--brand); }
.mini-bar.amber > span { background: var(--warning); }
.mini-bar.red > span { background: var(--danger); }

.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 99px; font-size: .76rem; font-weight: 700; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { color: var(--success); background: var(--success-bg); }
.pill.off { color: var(--muted); background: var(--line-2); }
.pill.warn { color: var(--warning); background: var(--warning-bg); }
.badge-ext { font-size: .68rem; font-weight: 700; color: var(--warning); background: var(--warning-bg); padding: .1rem .4rem; border-radius: 5px; margin-left: .4rem; }

/* overflow menu */
.menu-wrap { position: relative; display: inline-block; }
.menu-btn {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  padding: .3rem .55rem; font-size: 1rem; line-height: 1; color: var(--muted);
}
.menu-btn:hover { background: var(--brand-tint-2); }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line);
  border-radius: 11px; box-shadow: var(--shadow-lg); padding: .35rem; z-index: 25; min-width: 190px; text-align: left;
}
.menu-pop button {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: .5rem .6rem; border-radius: 7px; font-size: .87rem; color: var(--ink); font-weight: 500;
}
.menu-pop button:hover { background: var(--brand-tint-2); }
.menu-pop button.danger { color: var(--danger); }
.menu-pop .sep { height: 1px; background: var(--line); margin: .3rem 0; }

/* ---------------------------------------------------------------- states */
.state { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.state .icon { font-size: 2rem; opacity: .5; margin-bottom: .5rem; }
.state h3 { color: var(--ink); margin-bottom: .3rem; }
.state .btn { margin-top: 1rem; }
.skeleton { background: linear-gradient(90deg, var(--line-2) 25%, #f3f4fa 37%, var(--line-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.sk-line { height: 14px; margin: .6rem 0; }
.error-text { color: var(--danger); font-size: .85rem; margin: .4rem 0; }
.empty-row td { text-align: center; color: var(--muted); padding: 2rem; }

/* ---------------------------------------------------------------- side panel */
.scrim { position: fixed; inset: 0; background: rgba(26,27,46,.45); z-index: 40; opacity: 0; transition: opacity .2s; }
.scrim.open { opacity: 1; }
.panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 100vw; background: #fff;
  box-shadow: var(--shadow-lg); z-index: 41; transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 1.2rem 1.4rem; border-bottom: 1px solid var(--line); }
.panel-head .x { background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--muted); line-height: 1; }
.panel-body { padding: 1.4rem; overflow-y: auto; flex: 1; }
.panel-foot { padding: 1rem 1.4rem; border-top: 1px solid var(--line); display: flex; gap: .6rem; justify-content: flex-end; }
.panel-foot .btn, .panel-foot .btn-ghost, .panel-foot .btn-danger { flex: 0 0 auto; }

.danger-zone { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.danger-zone .dz-label { color: var(--danger); font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem; }
.sub-link { display: flex; justify-content: space-between; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line-2); }
.sub-link:last-child { border-bottom: 0; }

/* member list inside panel */
.list-rows { margin-top: .8rem; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: .55rem .2rem; border-bottom: 1px solid var(--line-2); font-size: .9rem; }
.list-row:last-child { border-bottom: 0; }

/* ---------------------------------------------------------------- dialog */
.dialog-scrim { position: fixed; inset: 0; background: rgba(26,27,46,.5); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 1rem; }
.dialog { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 460px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.dialog-head { padding: 1.3rem 1.4rem .4rem; }
.dialog-head h2 { font-size: 1.2rem; }
.dialog-body { padding: .4rem 1.4rem 1.2rem; color: var(--muted); font-size: .92rem; }
.dialog-body .ink { color: var(--ink); }
.dialog-foot { padding: 1rem 1.4rem; border-top: 1px solid var(--line); display: flex; gap: .6rem; justify-content: flex-end; }

/* credentials sheet */
.creds-sheet { font-size: .9rem; }
.creds-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); }
.creds-row:last-child { border-bottom: 0; }
.creds-row .k { color: var(--muted); font-weight: 600; }
.creds-row .v { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88rem; text-align: right; word-break: break-all; }
.creds-section-title { font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1rem 0 .2rem; }
.copy-btn {
  background: var(--brand-tint); color: var(--brand-700); border: 0; cursor: pointer; border-radius: 7px;
  padding: .25rem .55rem; font-size: .78rem; font-weight: 700; flex: none;
}
.copy-btn:hover { filter: brightness(.97); }
.copy-btn.ok { background: var(--success-bg); color: var(--success); }
.secret-box {
  background: var(--brand-tint-2); border: 1px dashed #bae6fd; border-radius: 9px; padding: .7rem .8rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .95rem; word-break: break-all;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
}
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .8rem; font-family: ui-monospace, Menlo, monospace; font-size: .9rem; margin: .6rem 0; }
.once-note { font-size: .8rem; color: var(--warning); font-weight: 600; margin: .4rem 0 .8rem; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 80; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; font-size: .88rem;
  box-shadow: var(--shadow-lg); animation: toastIn .2s ease; max-width: 340px;
}
.toast.ok { background: #14724a; }
.toast.err { background: #a72727; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------------------------------------------------------- auth screens */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 50% -10%, #e0f2fe, var(--bg)); }
.auth-card { width: 420px; max-width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 2rem 1.9rem; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .3rem; margin-bottom: 1.6rem; }
.auth-brand .logo { height: 36px; width: auto; display: block; margin-bottom: .2rem; }
.auth-brand .nm { font-weight: 800; font-size: 1.2rem; }
.auth-brand .sub { color: var(--muted); font-size: .85rem; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 1rem; }
.auth-card .lang-mini { position: absolute; top: 1rem; right: 1rem; }
.auth-foot { text-align: center; margin-top: 1.1rem; font-size: .85rem; }
.code-input { letter-spacing: .5em; text-align: center; font-size: 1.3rem; font-weight: 700; }
.qr-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .9rem; width: fit-content; margin: .8rem auto; }
.qr-box svg, .qr-box img { width: 180px; height: 180px; display: block; }
.step { margin: 1.2rem 0; }
.step .step-title { font-weight: 700; font-size: .9rem; margin-bottom: .5rem; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; width: 260px; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .topbar-mobile {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .7rem 1rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  }
  .topbar-mobile .hamburger { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--ink); }
  .content { padding: 1.2rem; }
  .cards-row { grid-template-columns: 1fr; }
  .panel { width: 100vw; }
  .page-head { flex-wrap: wrap; }

  /* tables -> stacked cards */
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { border: 1px solid var(--line); border-radius: 11px; margin-bottom: .7rem; padding: .4rem; }
  table.grid td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .5rem .6rem; }
  table.grid td::before { content: attr(data-label); font-weight: 700; color: var(--muted); font-size: .78rem; }
  table.grid td.actions { justify-content: flex-end; }
  table.grid td.actions::before { content: ""; }
}
@media (min-width: 861px) { .topbar-mobile { display: none; } }

/* print: credentials sheet only */
@media print {
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 2rem; }
  .print-area .copy-btn, .print-area .dialog-foot { display: none !important; }
}
