:root {
  color-scheme: light dark;

  /* navy-forward palette — deliberately distinct from the admin panel's
     brighter royal-blue/slate look */
  --bg: #eef1f8;
  --card-bg: #ffffff;
  --sidebar-bg: #0b1c3a;
  --sidebar-text: #9fb3d6;
  --sidebar-active-bg: #1c3f76;
  --sidebar-active-text: #ffffff;
  --text: #101b30;
  --muted: #5b6b8c;
  --border: #d7dfef;
  --primary: #1c3f76;
  --primary-hover: #142c56;
  --danger: #c23b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #060d1c;
    --card-bg: #0d1930;
    --sidebar-bg: #050e1f;
    --sidebar-text: #7f93bd;
    --sidebar-active-bg: #2c539c;
    --sidebar-active-text: #ffffff;
    --text: #e6ecfa;
    --muted: #8497c0;
    --border: #1c2c4d;
    --primary: #4d78c4;
    --primary-hover: #6c92d6;
    --danger: #ea6b6b;
  }
}

@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Light.ttf") format("truetype");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IRANSans";
  src: url("fonts/IRANSans(FaNum)_Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

/* .login-wrap/.app-shell below set their own `display`, which — being an
   author-stylesheet rule — outranks the browser's default `[hidden]{display:none}`
   (a user-agent rule) despite matching specificity. Without this, toggling
   `.hidden` in JS has no visual effect and both views stay on screen. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IRANSans", Tahoma, "Segoe UI", sans-serif;
}

button, input {
  font-family: inherit;
}

option {
  background: var(--card-bg);
  color: var(--text);
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 8px 24px rgba(11, 28, 58, 0.1);
}

.login-logo {
  display: block;
  height: 40px;
  width: auto;
  margin: 0 0 16px;
}

.card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.9rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  direction: ltr;
  text-align: left;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button:hover { background: var(--primary-hover); }

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
  padding: 4px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-icon {
  font-size: 0.95rem;
  width: 1.2em;
  text-align: center;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar h2 {
  margin: 0;
  font-size: 1.1rem;
}

.profile {
  position: relative;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px 6px 12px;
  color: var(--text);
  cursor: pointer;
}

.profile-btn:hover {
  background: rgba(11, 28, 58, 0.04);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: bold;
  flex-shrink: 0;
}

.profile-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.3;
}

.profile-name {
  font-size: 0.85rem;
}

.profile-username {
  font-size: 0.75rem;
  color: var(--muted);
  direction: ltr;
}

.chevron {
  color: var(--muted);
  font-size: 0.75rem;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 140px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(11, 28, 58, 0.15);
  overflow: hidden;
  z-index: 10;
}

.profile-menu button {
  width: 100%;
  text-align: right;
  background: transparent;
  color: var(--danger);
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 0.85rem;
}

.profile-menu button:hover {
  background: rgba(11, 28, 58, 0.05);
}

.content {
  flex: 1;
  padding: 28px;
}

.placeholder {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* ---------- Pages ---------- */

.card-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.balance-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 32px;
}

.balance-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.balance-value {
  font-size: 2.2rem;
  font-weight: bold;
  color: var(--primary);
  direction: ltr;
}

.balance-card button {
  padding: 10px 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 320px;
}

.field input {
  font-size: 0.95rem;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
}

.hint {
  width: 100%;
  font-size: 0.85rem;
  margin: 4px 0 0;
  color: var(--muted);
}

.hint.success { color: #1a8d5c; }
.hint.error { color: var(--danger); }

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-weight: 500;
}

.table-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.table-action-btn:hover {
  background: rgba(11, 28, 58, 0.05);
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 11, 26, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(5, 11, 26, 0.35);
}

.modal-box h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.modal-box button {
  width: 100%;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  width: auto;
  flex: 1;
  margin-top: 0;
}

/* ---------- Technical docs ---------- */

.doc-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.doc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.doc-header h3 {
  margin: 0;
  font-size: 1rem;
}

.doc-method {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--sidebar-active-bg);
  color: #fff;
  direction: ltr;
}

.doc-path {
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
  color: var(--muted);
  direction: ltr;
}

.doc-description {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.doc-block-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 12px 0 4px;
}

.doc-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.doc-copy-btn {
  width: auto;
  padding: 3px 10px;
  font-size: 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  margin: 0;
}

.doc-copy-btn:hover {
  background: rgba(11, 28, 58, 0.05);
}

pre.doc-code {
  direction: ltr;
  text-align: left;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 4px 0 0;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
}
