:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #17203a;
  --muted: #6b7590;
  --line: #dfe4ef;
  --primary: #3157d5;
  --primary-soft: #e7ecff;
  --success: #16855c;
  --success-soft: #e4f6ee;
  --warn: #a86400;
  --warn-soft: #fff2d9;
  --danger: #c43545;
  --danger-soft: #fdeaec;
  --shadow: 0 10px 30px rgba(24, 38, 86, 0.08);
  --radius: 14px;
}

[data-theme='dark'] {
  --bg: #0d1220;
  --surface: #151d30;
  --surface-2: #1d2740;
  --text: #eef2ff;
  --muted: #9aa6c2;
  --line: #2a3552;
  --primary: #7f9cff;
  --primary-soft: #232f55;
  --success: #55d6a0;
  --success-soft: #17392e;
  --warn: #f3bd63;
  --warn-soft: #3b2e16;
  --danger: #ff8390;
  --danger-soft: #402028;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, 'Segoe UI', Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { direction: ltr; unicode-bidi: embed; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 13px; }
.hint { color: var(--warn); font-size: 12px; }

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 15%, rgba(49, 87, 213, 0.16), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(22, 133, 92, 0.12), transparent 40%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.brand.compact { margin: 0; padding: 20px; border-bottom: 1px solid var(--line); }
.brand.compact strong { display: block; }
.brand.compact small { color: var(--muted); }
.brand-mark {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--primary); color: #fff;
  font-weight: 800; letter-spacing: 0.5px;
}
.footnote { margin: 22px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Form controls */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 80px; }
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: transform 0.1s, background 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.full { width: 100%; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

/* Shell */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.nav { padding: 14px 12px; overflow: auto; flex: 1; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; margin-bottom: 4px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); cursor: pointer; font: inherit; text-align: right;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 19px; }
.topbar p { margin: 0; font-size: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.content { padding: 24px 28px 60px; }

/* Cards / tables */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.card .value { font-size: 28px; font-weight: 800; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-body { padding: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 700;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }

/* Modal + toast */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(8, 14, 30, 0.55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  width: min(620px, 100%); max-height: 90vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; }
.modal .body { padding: 20px; }
.modal footer { display: flex; gap: 10px; justify-content: flex-start; padding: 16px 20px; border-top: 1px solid var(--line); }
.toast-root { position: fixed; bottom: 20px; left: 20px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; max-width: 360px;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav button { width: auto; white-space: nowrap; }
  .sidebar-foot { flex-direction: row; }
  .topbar { padding: 16px; }
  .content { padding: 16px; }
}
