:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --text: #1c231f;
  --muted: #5d6a63;
  --border: #dde2dd;
  --accent: #2c5530;
  --accent-soft: #e3eee4;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #1f7a3a;
  --ok-soft: #e4f4e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 1px 3px rgba(16, 24, 20, 0.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101412;
    --surface: #171c19;
    --surface-2: #1f2622;
    --text: #e5ebe7;
    --muted: #97a39c;
    --border: #2b332e;
    --accent: #7dbb84;
    --accent-soft: #1f3324;
    --accent-text: #0f1a12;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --warn: #f5c451;
    --warn-soft: #362a0d;
    --ok: #6fcf8a;
    --ok-soft: #173020;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0 0; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand span { color: var(--accent); }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
}
#nav a:hover { background: var(--surface-2); }
#nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 6px; }
.main { padding: 24px; min-width: 0; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .brand { padding: 0 0 8px; }
  #nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  #nav a { white-space: nowrap; }
  .sidebar-foot { margin-top: 8px; padding: 0; }
  .main { padding: 16px; }
}

/* Cards, grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tester-grid { grid-template-columns: minmax(240px, 1fr) 2fr; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4, .tester-grid { grid-template-columns: 1fr; }
}

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.arabic { font-family: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Geeza Pro", serif; font-size: 22px; line-height: 1.9; }
[dir="rtl"] { text-align: right; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 6px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border); }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.published, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.review { background: var(--warn-soft); color: var(--warn); }
.badge.draft, .badge.inactive { background: var(--surface-2); color: var(--muted); }
.badge.lang { font-family: var(--mono); font-weight: 500; margin: 0 2px 2px 0; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid var(--border); }

/* Filters, tabs */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 160px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button {
  font: inherit;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-left: 6px; vertical-align: middle; }

/* API tester */
.endpoint-list { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow-y: auto; }
.endpoint { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.endpoint:hover { background: var(--surface-2); }
.endpoint.active { border-color: var(--accent); background: var(--accent-soft); }
.method { font-family: var(--mono); font-size: 11px; font-weight: 700; width: 54px; text-align: center; padding: 2px 0; border-radius: 4px; background: var(--surface-2); }
.method.GET { color: var(--ok); }
.method.POST { color: #2f6fda; }
.method.PUT, .method.PATCH { color: var(--warn); }
.method.DELETE { color: var(--danger); }
.path { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.request-line { display: flex; gap: 8px; }
.request-line select { width: 110px; flex: none; }
pre.response { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
.status-line { display: flex; gap: 12px; align-items: center; font-family: var(--mono); font-size: 12.5px; }
.status-ok { color: var(--ok); font-weight: 700; }
.status-err { color: var(--danger); font-weight: 700; }
.results-list { font-family: var(--mono); font-size: 12.5px; display: flex; flex-direction: column; gap: 2px; }

/* Login, toast, misc */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-ad { border-radius: 10px; border: 1px solid var(--border); padding: 12px 14px; display: flex; gap: 12px; align-items: center; background: var(--surface); }
.preview-ad .icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
