@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0f0e17;
  --surface: #1a1826;
  --surface-2: #221f33;
  --border: #2e2a45;
  --text: #f4f1ff;
  --muted: #a79fc7;
  --accent: #c6f24e;
  --accent-ink: #1a2205;
  --danger: #ff7a7a;
  --info: #8fd3ff;
  --ok: #7ce6a4;
  --warn: #ffd166;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
  min-height: 100vh;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
button { font-family: inherit; }
::selection { background: rgba(198, 242, 78, .3); }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
}
.boot-title { font-size: 22px; font-weight: 700; }
.boot-sub { color: var(--muted); }

.noscript { padding: 40px; text-align: center; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.login-card h1 { font-size: 20px; }
.login-note { color: var(--muted); font-size: 12.5px; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { font-size: 16px; font-weight: 700; padding: 6px 10px 14px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text);
  font-size: 13.5px;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.nav-item.disabled { color: var(--muted); opacity: .55; pointer-events: none; }
.nav-group { color: var(--muted); font-size: 11px; padding: 12px 10px 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.topbar .spacer { flex: 1; }
.topbar-title { font-weight: 600; }
.view { padding: 20px; max-width: 1200px; width: 100%; margin: 0 auto; }
.footbar { padding: 12px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); margin-top: auto; }

/* components */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-title .spacer { flex: 1; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; }
.page-head .spacer { flex: 1; }
.page-sub { color: var(--muted); font-size: 12.5px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { border-color: transparent; filter: brightness(1.06); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255, 122, 122, .4); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--info); padding: 0; cursor: pointer; font-size: 13px; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid rgba(198, 242, 78, .4); border-color: var(--accent); }
.textarea { min-height: 90px; resize: vertical; }
.select { appearance: none; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: right;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}
.table td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: rgba(255, 255, 255, .02); }
.table .num { font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; }
.row-link { color: var(--text); font-weight: 500; cursor: pointer; }
.row-link:hover { color: var(--accent); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(124, 230, 164, .35); }
.badge.warn { color: var(--warn); border-color: rgba(255, 209, 102, .35); }
.badge.danger { color: var(--danger); border-color: rgba(255, 122, 122, .35); }
.badge.info { color: var(--info); border-color: rgba(143, 211, 255, .35); }
.badge.muted { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 18px; }
.grid .cell { display: grid; gap: 2px; min-width: 0; }
.grid .cell .k { color: var(--muted); font-size: 11.5px; }
.grid .cell .v { font-size: 13.5px; overflow-wrap: anywhere; }

.muted { color: var(--muted); }
.detail-scalar { font-size: 14px; }
.detail-section { margin-top: 16px; }
.detail-section-title { font-size: 12.5px; font-weight: 600; color: var(--info); margin-bottom: 8px; }
.detail-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.detail-item-title { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }

/* structured editors */
.editor-block { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.editor-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.editor-block-title { font-size: 13px; font-weight: 600; flex: 1; }
.editor-rows { display: grid; gap: 8px; }
.editor-row { display: grid; gap: 8px; align-items: end; }
.editor-field { display: grid; gap: 4px; min-width: 0; }
.mini-label { font-size: 11px; color: var(--muted); }
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--danger); background: rgba(255, 122, 122, .1); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.editor-note { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }

.fact-list { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.fact { font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.fact .k { color: var(--muted); }
.fact .tag-list { display: inline-flex; }

.list-row { display: flex; gap: 8px; align-items: flex-start; }
.list-row .editor-field { flex: 1; }
.list-row .icon-btn { flex: 0 0 auto; margin-top: 1px; }
.list-row .textarea { min-height: 38px; }

/* palette scrollbars */
html { scrollbar-color: var(--surface-2) var(--bg); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.error-box {
  border: 1px solid rgba(255, 122, 122, .4);
  background: rgba(255, 122, 122, .08);
  color: var(--danger);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}
.info-box {
  border: 1px solid rgba(143, 211, 255, .3);
  background: rgba(143, 211, 255, .07);
  color: var(--info);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.loading { padding: 40px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 8px 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  white-space: nowrap;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: 12px; }

/* modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 12, .7);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }

/* toast */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; max-width: min(420px, 90vw); }
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-right: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  animation: toast-in .18s ease-out;
}
.toast.error { border-right-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.perm-group { border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; margin-bottom: 8px; }
.perm-group-title { font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--info); }
.perm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; }
.perm-list .check { font-size: 12px; direction: ltr; justify-content: flex-end; }
.perm-list .check span { direction: ltr; }

.condition-row { display: grid; grid-template-columns: 1.2fr .8fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.pager .info { color: var(--muted); font-size: 12px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    border-left: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
  }
  .brand { width: 100%; padding: 0 6px 8px; }
  .nav-group { display: none; }
  .nav-item { padding: 6px 9px; font-size: 12.5px; }
  .form-grid { grid-template-columns: 1fr; }
  .view { padding: 14px; }
  .condition-row { grid-template-columns: 1fr 1fr; }
}