:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --line: #e3e8ef;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --allow: #15803d;
  --allow-bg: #dcfce7;
  --block: #b91c1c;
  --block-bg: #fee2e2;
  --request: #b45309;
  --request-bg: #fef3c7;
  --neutral-bg: #eef2f7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; direction: ltr; text-align: left; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; max-height: 480px; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--text); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.nav a.active { background: var(--neutral-bg); font-weight: 600; }
.nav a:hover { text-decoration: none; background: var(--neutral-bg); }
.count { background: var(--request); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 0.75rem; font-weight: 700; line-height: 18px; }

.view { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.compact { padding: 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat { text-align: center; }
.stat .num { font-size: 2rem; font-weight: 700; }
.stat .label { color: var(--muted); }

.login-card { max-width: 380px; margin: 60px auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--neutral-bg); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(0.95); }
.btn.danger { color: var(--block); border-color: #f3b4b4; }
.btn.danger:hover { background: var(--block-bg); }
.btn.success { color: var(--allow); border-color: #b7e4c7; }
.btn.success:hover { background: var(--allow-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > label { font-weight: 600; font-size: 0.9rem; }
.field .hint { color: var(--muted); font-size: 0.8rem; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; margin-bottom: 0; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: 40px; height: 22px; appearance: none; background: #cbd5e1; border-radius: 999px; position: relative; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked { background: var(--allow); }
.switch input:checked::after { transform: translateX(-18px); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.badge.allow { background: var(--allow-bg); color: var(--allow); }
.badge.block { background: var(--block-bg); color: var(--block); }
.badge.request { background: var(--request-bg); color: var(--request); }
.badge.neutral { background: var(--neutral-bg); color: var(--muted); }
.badge.pending { background: var(--request-bg); color: var(--request); }
.badge.approved { background: var(--allow-bg); color: var(--allow); }
.badge.denied { background: var(--block-bg); color: var(--block); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 6px 12px; font: inherit; cursor: pointer; color: var(--muted); border-inline-start: 1px solid var(--line); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on.allow { background: var(--allow-bg); color: var(--allow); font-weight: 700; }
.seg button.on.block { background: var(--block-bg); color: var(--block); font-weight: 700; }
.seg button.on.request { background: var(--request-bg); color: var(--request); font-weight: 700; }
.seg button.on.neutral { background: var(--neutral-bg); color: var(--text); font-weight: 700; }

.rule-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: none; }
.rule-row .info { flex: 1; min-width: 0; }
.rule-row .info .k { color: var(--muted); font-size: 0.75rem; direction: ltr; display: inline-block; }
.rule-row .info .d { color: var(--muted); font-size: 0.82rem; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.savebar { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px; margin: 0 -16px -16px; display: flex; gap: 8px; justify-content: flex-start; align-items: center; border-radius: 0 0 var(--radius) var(--radius); }

.code-big { font-size: 2rem; letter-spacing: 0.15em; font-weight: 700; direction: ltr; text-align: center; padding: 12px; background: var(--neutral-bg); border-radius: 8px; user-select: all; }

.req-card { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.req-card .main { flex: 1 1 280px; }
.req-card .meta { color: var(--muted); font-size: 0.85rem; }

.toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 0.9rem; animation: fade .2s; }
.toast.error { background: var(--block); }
.toast.success { background: var(--allow); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { background: var(--card); border-radius: var(--radius); width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.modal h2 { margin-bottom: 12px; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 14px; flex-wrap: wrap; }

details summary { cursor: pointer; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; direction: ltr; text-align: start; unicode-bidi: plaintext; }
.ltr { direction: ltr; unicode-bidi: plaintext; }

@media (max-width: 640px) {
  .view { padding: 12px 12px 60px; }
  .card { padding: 12px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .rule-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .savebar { margin: 0 -12px -12px; padding: 10px 12px; }
}
