/* ===== Mestika font family ===== */
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Thin.otf') format('opentype'); font-weight: 100; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-ExtraLight.otf') format('opentype'); font-weight: 200; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Light.otf') format('opentype'); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Regular.otf') format('opentype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Medium.otf') format('opentype'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-SemiBold.otf') format('opentype'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Bold.otf') format('opentype'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-ExtraBold.otf') format('opentype'); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Mestika'; src: url('/fonts/Mestika-Black.otf') format('opentype'); font-weight: 900; font-style: normal; font-display: swap; }

:root {
  --primary: #ffffff;
  --secondary: #9fbcff;
  --text: #2b283b;
  --text-muted: #6b6880;
  --surface: #ffffff;
  --surface-2: #f5f7ff;
  --border: #e3e7f3;
  --danger: #e34d4d;
  --success: #2bb673;
  --warning: #e9a23b;
  --shadow: 0 4px 18px rgba(43, 40, 59, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --font-stack: 'Mestika', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --primary: #2b283b;
  --secondary: #9fbcff;
  --text: #ffffff;
  --text-muted: #a8a3c2;
  --surface: #34314a;
  --surface-2: #3d3a55;
  --border: #4a4663;
  --shadow: 0 4px 18px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-stack);
  background: var(--primary);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background .25s, color .25s;
}
[dir="ltr"] body { font-family: var(--font-stack); }

a { color: var(--secondary); text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== Top bar ===== */
.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
}
.tb-left { display: flex; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.brand img { height: 36px; width: auto; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .3px; color: var(--text); }
.brand-name span { color: var(--secondary); }

.tb-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer; transition: all .18s; font-size: 15px;
}
.icon-btn:hover { border-color: var(--secondary); color: var(--secondary); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }
.menu-btn { background: var(--surface); }
.menu-btn:hover { background: var(--surface-2); }

/* ===== Drawer ===== */
.drawer-bg {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(43,40,59,0); transition: background .22s ease;
  display: flex;
}
[dir="rtl"] .drawer-bg { justify-content: flex-end; }
[dir="ltr"] .drawer-bg { justify-content: flex-start; }
.drawer-bg.open { background: rgba(43,40,59,.55); }
.drawer {
  background: var(--surface); width: 340px; max-width: 92vw;
  height: 100vh; display: flex; flex-direction: column;
  box-shadow: -8px 0 28px rgba(0,0,0,.18);
  transform: translateX(100%); transition: transform .25s ease;
}
[dir="ltr"] .drawer { transform: translateX(-100%); box-shadow: 8px 0 28px rgba(0,0,0,.18); }
.drawer-bg.open .drawer { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head .brand img { height: 34px; }
.drawer-head .brand-name { font-size: 16px; }
.drawer-close { width: 36px; height: 36px; font-size: 16px; }
.drawer-user {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.drawer-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: var(--text); flex-shrink: 0;
}
:root[data-theme="dark"] .drawer-avatar { color: var(--primary); }
.drawer-user-info { flex: 1; min-width: 0; }
.drawer-user-name { font-weight: 700; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-user-email { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 0; }
.drawer-section { padding: 6px 14px 14px; }
.drawer-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); padding: 8px 6px; font-weight: 700;
}
.drawer-list { display: flex; flex-direction: column; gap: 4px; }
.drawer-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px;
  border-radius: 12px; background: transparent; border: 1px solid transparent;
  color: var(--text); cursor: pointer; text-align: start; width: 100%;
  font-family: inherit; transition: all .15s;
  min-height: 44px;
}
.drawer-item:hover { background: var(--surface-2); border-color: var(--border); }
.drawer-item.active { background: rgba(159,188,255,.18); border-color: rgba(159,188,255,.4); }
.drawer-icon {
  width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0;
  color: var(--secondary);
}
.drawer-item.active .drawer-icon { background: var(--secondary); color: var(--text); }
:root[data-theme="dark"] .drawer-item.active .drawer-icon { color: var(--primary); }
.drawer-label { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.drawer-title { font-weight: 700; font-size: 14px; color: var(--text); }
.drawer-desc { font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-chev { color: var(--text-muted); font-size: 20px; opacity: .6; }
[dir="ltr"] .drawer-chev { transform: scaleX(-1); }
.drawer-empty { padding: 14px; color: var(--text-muted); font-size: 13px; text-align: center; }
.drawer-add { width: 100%; margin-top: 10px; padding: 10px; }
.drawer-foot {
  padding: 14px 18px; border-top: 1px solid var(--border);
  background: var(--surface);
}
.drawer-logout { width: 100%; padding: 11px; }

.btn {
  background: var(--secondary); color: var(--text); border: none;
  padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer;
  font-size: 14px; transition: all .15s;
  min-height: 44px;
}
:root[data-theme="dark"] .btn { color: var(--primary); }
.btn:hover { filter: brightness(0.95); }
.btn:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--secondary); color: var(--secondary); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ===== Layout ===== */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 65px); }
.layout.no-sidebar { grid-template-columns: 1fr; }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--border); padding: 18px 12px; }
.side-section { font-size: 11px; text-transform: uppercase; color: var(--text-muted); padding: 14px 12px 6px; letter-spacing: 1px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--text); cursor: pointer; user-select: none;
  font-weight: 600; font-size: 14px; margin-bottom: 2px; transition: all .12s;
  min-height: 40px;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--secondary); color: var(--text); }
:root[data-theme="dark"] .nav-link.active { color: var(--primary); }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.nav-link .dot.off { background: var(--danger); }

.main { padding: 24px; max-width: 1280px; margin: 0 auto; width: 100%; }
@media (max-width: 600px) { .main { padding: 16px; } }
/* HIG-inspired large title */
.page-title { font-size: 28px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.3px; }
.page-sub { color: var(--text-muted); margin: 0; font-size: 13px; }
.page-head {
  display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ===== Cards / Grid ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

.stat { display: flex; flex-direction: column; gap: 6px; padding: 16px; }
.stat .label { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .3px; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1.2; }
.stat .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.stat .value.accent { color: var(--secondary); }
.stat .progress { margin-top: 4px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: start; padding: 12px 14px; background: var(--surface-2);
  font-weight: 700; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
}
tbody td { padding: 12px 14px; border-top: 1px solid var(--border); color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.ok { background: rgba(43,182,115,.12); color: var(--success); border-color: rgba(43,182,115,.3); }
.badge.err { background: rgba(227,77,77,.12); color: var(--danger); border-color: rgba(227,77,77,.3); }
.badge.warn { background: rgba(233,162,59,.12); color: var(--warning); border-color: rgba(233,162,59,.3); }
.badge.ubnt { background: rgba(159,188,255,.18); color: var(--secondary); border-color: rgba(159,188,255,.35); }

/* ===== Auth ===== */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--primary), var(--surface-2));
  padding: 24px;
}
.auth-card { background: var(--surface); border: 1px solid var(--border); padding: 32px; border-radius: 20px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-card .brand { justify-content: center; margin-bottom: 24px; flex-direction: column; }
.auth-card .brand img { height: 80px; }
.auth-card h2 { margin: 0 0 6px; text-align: center; font-size: 22px; letter-spacing: -0.2px; }
.auth-card .muted { color: var(--text-muted); text-align: center; margin: 0 0 22px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--primary); color: var(--text); font-family: inherit; font-size: 15px;
  outline: none; transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
}
.field input:focus, .field select:focus { border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(159,188,255,.18); }
.auth-card .btn { width: 100%; padding: 13px; margin-top: 6px; }
.auth-switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--text-muted); }
.auth-switch a { cursor: pointer; font-weight: 700; }
.err-msg { color: var(--danger); background: rgba(227,77,77,.08); border: 1px solid rgba(227,77,77,.25); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.ok-msg { color: var(--success); background: rgba(43,182,115,.08); border: 1px solid rgba(43,182,115,.25); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }

/* ===== Modal ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(43,40,59,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; backdrop-filter: blur(6px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: 100%; max-width: 520px; padding: 26px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 18px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ===== Loader ===== */
.loader { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--secondary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-loader { display: flex; align-items: center; justify-content: center; padding: 60px; }
.center-loader .loader { width: 32px; height: 32px; border-width: 3px; }

/* progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--secondary); border-radius: 999px; transition: width .3s; }

.empty {
  padding: 50px 20px; text-align: center; color: var(--text-muted);
  border: 2px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { font-size: 36px; margin-bottom: 10px; }
.empty h3 { margin: 0 0 6px; color: var(--text); }

.row-gap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.searchbox {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 220px;
  font-family: inherit; min-height: 40px;
}
.searchbox:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 3px rgba(159,188,255,.15); }

.mac { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }

/* ===== HIG focus / motion ===== */
:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
