/* Naqi Dashboard: Arabic RTL, light theme. Fonts are self-hosted (IBM Plex Sans Arabic, SIL OFL). */

@font-face {
  font-family: 'Plex Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/plex-arabic-400.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Plex Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/plex-arabic-600.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Plex Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/plex-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Plex Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/plex-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}

:root {
  --canvas: #f2f6f7;
  --surface: #ffffff;
  --ink: #12303b;
  --muted: #526a74;
  --line: #dbe5e8;
  --line-strong: #c3d2d7;

  --aqua: #0b6e83;
  --aqua-strong: #085a6c;
  --aqua-tint: #e4f2f5;

  --on: #17805a;
  --on-ink: #0f6b48;
  --on-tint: #e3f4ec;
  --off: #b23a2e;
  --off-ink: #9c2f25;
  --off-tint: #fbe9e6;
  --warn: #b7791f;
  --warn-ink: #7a4e05;
  --warn-tint: #fcf1dc;

  --switch-off: #7c929b;

  --radius-panel: 14px;
  --radius-control: 10px;
  --header-h: 60px;
  --sidebar-w: 232px;
  --font: 'Plex Arabic', 'Segoe UI', Tahoma, 'Noto Sans Arabic', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--aqua); }
button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid #4aa3b5;
  outline-offset: 2px;
  border-radius: 6px;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

.skip-link {
  position: absolute;
  inset-inline-start: 12px;
  top: -60px;
  background: var(--ink);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 50;
}
.skip-link:focus { top: 8px; }

/* ------------------------------------------------------------ layout */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-inline: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; fill: var(--aqua); flex: none; }
.brand-name { font-weight: 600; font-size: 18px; letter-spacing: 0.01em; direction: ltr; }
.brand-large .brand-mark { width: 34px; height: 34px; }
.brand-large .brand-name { font-size: 22px; }

.logout-form { margin: 0; }

.sidebar {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  position: sticky;
  top: var(--header-h);
  height: calc(100dvh - var(--header-h));
  align-self: start;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  color: var(--muted);
  text-decoration: none;
  font-weight: 400;
}
.nav-link:hover { background: var(--canvas); color: var(--ink); }
.nav-link[aria-current='page'] { background: var(--aqua-tint); color: var(--aqua-strong); font-weight: 600; }

.nav-count {
  margin-inline-start: auto;
  min-width: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--warn-tint);
  color: var(--warn-ink);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 24px;
}

.main {
  grid-row: 2;
  min-width: 0;
  padding: 28px clamp(16px, 3vw, 40px) 48px;
  max-width: 1180px;
  width: 100%;
  margin-inline: auto;
}
.main:focus { outline: none; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.page-title { font-size: 24px; line-height: 1.4; font-weight: 600; }
.page-sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ----------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--canvas); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--aqua); border-color: var(--aqua); color: #fff; }
.btn-primary:hover { background: var(--aqua-strong); }
.btn-danger { background: var(--off); border-color: var(--off); color: #fff; }
.btn-danger:hover { background: var(--off-ink); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--canvas); color: var(--ink); }
.btn-block { width: 100%; }

/* ------------------------------------------------------------ panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
}
.panel + .panel, .stats + .panel, .panel + .stats { margin-top: 20px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-title { font-size: 17px; font-weight: 600; }
.panel-body { padding: 20px; }

/* --------------------------------------------------------- home stats */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
}
.stat {
  display: block;
  padding: 18px 20px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
a.stat:hover { background: #fafcfc; }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; }
.stat-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.stat-dot.is-on { background: var(--on); }
.stat-dot.is-off { background: var(--off); }
.stat-dot.is-warn { background: var(--warn); }
.stat-value { margin-top: 4px; font-size: 34px; line-height: 1.2; font-weight: 600; }
.stat-value.is-warn { color: var(--warn-ink); }

.gauge { margin-top: 20px; padding: 18px 20px; }
.gauge-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-bottom: 12px; }
.gauge-title { font-weight: 600; }
.gauge-figures { color: var(--muted); }
.gauge-track { height: 12px; border-radius: 999px; background: #dfeaed; overflow: hidden; }
.gauge-fill { display: block; height: 100%; width: var(--p, 0%); background: var(--on); border-radius: 999px; transition: width 0.4s ease; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.recent-item:last-child { border-bottom: 0; }
.recent-who { min-width: 0; }
.recent-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-phone { color: var(--muted); font-size: 14px; }
.recent-time { color: var(--muted); font-size: 14px; white-space: nowrap; }

/* ------------------------------------------------------------ toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search .icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  padding-inline-start: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  direction: ltr;
  text-align: right;
}
.search input::placeholder { direction: rtl; color: #7d9099; }
.search input:focus-visible { outline: 3px solid #4aa3b5; outline-offset: 1px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--canvas);
}
.segmented button {
  min-height: 38px;
  padding: 4px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(18, 48, 59, 0.12); }
.segmented .seg-count { margin-inline-start: 6px; color: var(--muted); font-weight: 400; font-size: 13px; }

.toolbar-end { margin-inline-start: auto; display: flex; gap: 8px; }

/* -------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  padding: 12px 20px;
  text-align: start;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: #f8fbfb;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fafcfc; }
.cell-phone { font-weight: 600; }
.cell-muted { color: var(--muted); }
.cell-time { white-space: nowrap; color: var(--ink); }

.table-foot { padding: 12px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-on { background: var(--on-tint); color: var(--on-ink); }
.badge-off { background: var(--off-tint); color: var(--off-ink); }
.badge-warn { background: var(--warn-tint); color: var(--warn-ink); }
.badge-plain { background: var(--canvas); color: var(--muted); }
.badge-plain::before { display: none; }
.badge-unknown { background: var(--warn-tint); color: var(--warn-ink); }

/* ------------------------------------------------------------- switch */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}
.switch-track {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--switch-off);
  flex: none;
  transition: background 0.15s ease;
}
.switch-knob {
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: inset-inline-start 0.15s ease;
}
.switch[aria-checked='true'] .switch-track { background: var(--on); }
.switch[aria-checked='true'] .switch-knob { inset-inline-start: 23px; }
.switch-label { min-width: 74px; text-align: start; font-size: 15px; }
.switch[aria-busy='true'] { cursor: progress; opacity: 0.75; }
.switch[disabled] { cursor: not-allowed; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--aqua);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- states */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}
.state-title { color: var(--ink); font-weight: 600; font-size: 17px; }
.state-error .state-title { color: var(--off-ink); }
.state-loading { flex-direction: row; justify-content: center; gap: 12px; }

/* ------------------------------------------------------------ settings */

.global-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: center; padding: 24px; }
.global-status { display: flex; align-items: center; gap: 12px; font-size: 24px; font-weight: 600; line-height: 1.4; }
.global-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.global-dot.is-on { background: var(--on); box-shadow: 0 0 0 5px var(--on-tint); }
.global-dot.is-off { background: var(--off); box-shadow: 0 0 0 5px var(--off-tint); }
.global-note { margin-top: 6px; color: var(--muted); }

/* --------------------------------------------------------------- toast */

.toasts {
  position: fixed;
  inset-inline-start: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 40px));
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(18, 48, 59, 0.25);
}
.toast-error { background: var(--off-ink); }
.toast-success { background: #0f5a3f; }

/* -------------------------------------------------------------- dialog */

.dialog {
  border: 0;
  padding: 0;
  border-radius: var(--radius-panel);
  width: min(440px, calc(100vw - 32px));
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(18, 48, 59, 0.35);
}
.dialog::backdrop { background: rgba(18, 48, 59, 0.45); }
.dialog-body { margin: 0; padding: 24px; }
.dialog-title { font-size: 19px; font-weight: 600; line-height: 1.5; }
.dialog-text { margin-top: 8px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-start; gap: 8px; margin-top: 22px; }

/* --------------------------------------------------------------- login */

.login-body { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%);
  padding: 32px 28px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.login-title { margin-top: 26px; font-size: 24px; font-weight: 600; line-height: 1.4; }
.login-hint { margin-top: 4px; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 16px; margin-top: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; font-size: 15px; }
.field input {
  min-height: 46px;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  direction: ltr;
  text-align: right;
}
.form-error {
  padding: 10px 14px;
  border-radius: var(--radius-control);
  background: var(--off-tint);
  color: var(--off-ink);
  font-size: 15px;
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--header-h) 1fr; }

  .sidebar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    top: auto;
    z-index: 30;
    height: auto;
    flex-direction: row;
    justify-content: space-around;
    gap: 2px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-inline-end: 0;
    border-top: 1px solid var(--line);
  }
  .nav-link {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    padding: 6px 4px;
    font-size: 12.5px;
    text-align: center;
    position: relative;
  }
  .nav-count { position: absolute; top: 2px; inset-inline-start: calc(50% + 6px); margin: 0; min-width: 20px; line-height: 20px; font-size: 12px; padding: 0 6px; }

  .main { padding: 20px 16px 96px; }
  .topbar { padding-inline: 14px; }
  .toasts { inset-inline: 16px; bottom: 84px; max-width: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .global-card { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .btn-quiet span { display: none; }
  .logout-form .btn-quiet span { display: inline; }
  .page-title { font-size: 21px; }
  .toolbar-end { margin-inline-start: 0; width: 100%; }
  .toolbar-end .btn { flex: 1; }
  .search { max-width: none; flex-basis: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding-inline: 6px; }

  .table-wrap { overflow: visible; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tbl tbody tr { padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; border: 0; text-align: end; }
  .tbl td::before { content: attr(data-label); color: var(--muted); font-size: 14px; text-align: start; flex: none; }
  .tbl tbody tr:hover td { background: transparent; }

  .recent-item { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .recent-time { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .stat { padding: 14px 14px; }
  .stat-value { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
