:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2430;
  --muted: #667085;
  --accent: #1f6f6b;
  --accent-soft: #e3f1ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  --tier-primary: #1f6f6b;   --tier-primary-bg: #e3f1ef;
  --tier-secondary: #2557a7; --tier-secondary-bg: #e7eefb;
  --tier-watch: #a15c07;     --tier-watch-bg: #fdf1df;
  --tier-unclassified: #555e6b; --tier-unclassified-bg: #eceef1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151a;
    --surface: #181d24;
    --surface-2: #202631;
    --border: #2b3240;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --accent: #4fb3ab;
    --accent-soft: #173533;
    --danger: #f97066;
    --danger-soft: #3a1a18;
    --tier-primary: #6fd0c6;   --tier-primary-bg: #173533;
    --tier-secondary: #8fb3f5; --tier-secondary-bg: #1c2a44;
    --tier-watch: #f3b25b;     --tier-watch-bg: #3a2a14;
    --tier-unclassified: #b2bac6; --tier-unclassified-bg: #262c36;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; font-weight: 600; }
p { margin: .25rem 0; }
.muted { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.pre { white-space: pre-wrap; }
.icon { width: 20px; height: 20px; flex: none; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  flex: none;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 0 .5rem; }
.brand strong { display: block; font-size: 1.05rem; }
.brand small { display: block; color: var(--muted); font-size: .8rem; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .75rem; border-radius: 10px;
  color: var(--text); font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .soon {
  margin-inline-start: auto; font-size: .72rem; color: var(--muted);
  background: var(--surface-2); padding: 0 .5rem; border-radius: 999px;
}
.main { flex: 1; min-width: 0; padding: 2rem clamp(1rem, 3vw, 2.5rem) 3rem; max-width: 1200px; }
.topbar, .nav-toggle, .scrim { display: none; }

@media (max-width: 860px) {
  .topbar {
    display: flex; align-items: center; gap: .75rem;
    position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .6rem 1rem;
  }
  .menu-btn { display: inline-flex; padding: .35rem; border-radius: 8px; cursor: pointer; }
  .menu-btn:hover { background: var(--surface-2); }
  .brand-mini { font-weight: 700; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40;
    transform: translateX(100%); transition: transform .2s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .15);
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:checked ~ .shell .scrim {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .3);
  }
  .main { padding: 1.25rem 1rem 2.5rem; }
  .hide-sm { display: none; }
}

/* ---------- Building blocks ---------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.crumbs { color: var(--muted); font-size: .85rem; margin: 0 0 .2rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem;
}
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.section-title { margin: 2rem 0 .75rem; display: flex; align-items: center; gap: .5rem; }
.count { font-size: .8rem; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 0 .6rem; }

.flash {
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1.25rem; font-weight: 500;
}
.alert {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 500; line-height: 1.2;
  padding: .6rem 1.05rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-small { padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.badge {
  display: inline-block; font-size: .78rem; font-weight: 600; line-height: 1.6;
  padding: 0 .6rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge-muted { font-weight: 500; }
.tier-primary { background: var(--tier-primary-bg); color: var(--tier-primary); }
.tier-secondary { background: var(--tier-secondary-bg); color: var(--tier-secondary); }
.tier-watch { background: var(--tier-watch-bg); color: var(--tier-watch); }
.tier-unclassified { background: var(--tier-unclassified-bg); color: var(--tier-unclassified); }

/* ---------- Stats ---------- */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stats-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat {
  display: flex; flex-direction: column; gap: .2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.25rem; color: var(--text);
  box-shadow: var(--shadow);
}
.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat-label { color: var(--muted); font-size: .9rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: .82rem; }

.list-card { padding: .25rem 0; }
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1.25rem; border-bottom: 1px solid var(--border);
}
.link-list li:last-child { border-bottom: 0; }

/* ---------- Tabs & filters ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab { padding: .55rem 1rem; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; margin-bottom: 1rem; }
.filters.card { padding: .9rem 1rem; }
.field-inline { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); min-width: 140px; flex: 1 1 140px; }
.filter-actions { display: flex; gap: .5rem; }
.chip { padding: .3rem .9rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip:hover { text-decoration: none; }

/* ---------- Table ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: start; padding: .7rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .actions { text-align: end; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; max-width: 760px; }
.field { display: flex; flex-direction: column; gap: .35rem; font-weight: 500; }
input[type="text"], input[type="password"], select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .75rem; width: 100%;
}
input[dir="ltr"] { text-align: left; }
input[dir="ltr"]::placeholder { text-align: left; }
textarea { resize: vertical; }
.field-error { color: var(--danger); font-size: .85rem; font-weight: 500; margin: 0; }
.form-actions { display: flex; gap: .5rem; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Site detail ---------- */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .6rem 1.5rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) {
  .details { grid-template-columns: 1fr; gap: .1rem; }
  .details dd { margin-bottom: .6rem; }
}
.placeholders { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-top: 1rem; }
.placeholder { border-style: dashed; box-shadow: none; }
.danger-zone { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }

/* ---------- Bare pages (login, setup, errors) ---------- */
.bare-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem 1rem; gap: 1.25rem; }
.bare-brand { display: flex; align-items: center; gap: .6rem; font-size: 1.2rem; }
.bare-card { width: 100%; max-width: 400px; padding: 1.75rem; }
.bare-card h1 { margin-bottom: .75rem; }
.bare-card .form { margin-top: 1rem; }
