/* ═══════════════════════════════════════════════════════════
   P84 Platform — Base CSS
   ═══════════════════════════════════════════════════════════ */

/* ── Self-hosted fonts ────────────────────────────────────── */
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/plus-jakarta-sans/PlusJakartaSans-VariableFont.woff2') format('woff2');
}
@font-face {
  font-family: 'DM Serif Display';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/dm-serif/DMSerifDisplay-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/ibm-plex-mono/IBMPlexMono-Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/ibm-plex-mono/IBMPlexMono-SemiBold.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2') format('woff2');
}
@font-face {
  font-family: 'Vazirmatn';
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/vazirmatn/Vazirmatn-VariableFont.woff2') format('woff2'),
       url('/assets/fonts/vazirmatn/Vazirmatn-Regular.woff2') format('woff2');
}
/* Alias Vazir -> Vazirmatn (used in planner) */
@font-face {
  font-family: 'Vazir';
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
  src: url('/assets/fonts/vazirmatn/Vazirmatn-VariableFont.woff2') format('woff2'),
       url('/assets/fonts/vazirmatn/Vazirmatn-Regular.woff2') format('woff2');
}

/* ── Design tokens ────────────────────────────────────────── */
:root {
  /* Colors */
  --bg:          #f4f1ec;
  --bg2:         #ede9e0;
  --surface:     #ffffff;
  --surface2:    #f9f7f4;
  --surface3:    #f0ede7;
  --border:      rgba(26, 22, 18, 0.10);
  --border2:     rgba(26, 22, 18, 0.18);

  --text:        #1a1612;
  --text2:       #5a524a;
  --text3:       #9a9088;

  --accent:      #2d5be3;
  --accent2:     #1a3fa0;
  --accent-bg:   rgba(45, 91, 227, 0.08);
  --accent-text: #1e40af;

  --gold:        #c9922a;
  --gold-bg:     rgba(201, 146, 42, 0.10);

  --green:       #1e8a5a;
  --green-bg:    rgba(30, 138, 90, 0.10);

  --danger:      #c0392b;
  --danger-bg:   rgba(192, 57, 43, 0.08);

  /* Tracker variables (maps to tracker original CSS) */
  --best:        #0ea86e;
  --best-bg:     rgba(14, 168, 110, 0.11);
  --worst:       #e8424a;
  --worst-bg:    rgba(232, 66, 74, 0.10);
  --f-num:       'IBM Plex Mono', 'Courier New', monospace;
  --f-fa:        'Vazirmatn', 'Tahoma', sans-serif;

  --warn:        #d97706;
  --warn-bg:     rgba(217, 119, 6, 0.09);

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06), 0 1px 8px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);

  /* Typography */
  --font-ui:      'Plus Jakarta Sans', system-ui, sans-serif;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-mono:    'IBM Plex Mono', 'Courier New', monospace;
  --font-fa:      'Vazirmatn', system-ui, sans-serif;

  /* Radii */
  --r:     12px;
  --r-sm:  7px;
  --r-xs:  4px;
  --r-lg:  18px;

  /* Transitions */
  --t:     0.15s ease;
  --t-med: 0.25s ease;
}

/* Dark mode */
.dark {
  --bg:        #0f0e0c;
  --bg2:       #161410;
  --surface:   #1c1a16;
  --surface2:  #232018;
  --surface3:  #2a261e;
  --border:    rgba(255, 250, 240, 0.08);
  --border2:   rgba(255, 250, 240, 0.14);
  --text:      #f0ede6;
  --text2:     #9a9080;
  --text3:     #5a5248;
  --accent:    #6b8ef0;
  --accent2:   #8aaaf5;
  --accent-bg: rgba(107, 142, 240, 0.12);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.55);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, video { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Typography ───────────────────────────────────────────── */
.font-display { font-family: var(--font-display); }
.font-mono    { font-family: var(--font-mono); }
.font-fa      { font-family: var(--font-fa); direction: rtl; }

/* ── Layout ───────────────────────────────────────────────── */
.container { max-width: 1140px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 680px; margin: 0 auto; padding: 0 20px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  transition: background var(--t), opacity var(--t), transform var(--t), box-shadow var(--t);
  white-space: nowrap;
  outline: none;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); box-shadow: 0 4px 14px rgba(30,107,69,0.3); }

.btn-dark     { background: #232018; color: #f0ece3; }
.btn-dark:hover { opacity: 0.85; }

.btn-ghost    { background: transparent; color: var(--text2); border: 1.5px solid var(--border2); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

.btn-sm { padding: 7px 14px; font-size: 12.5px; }
.btn-lg { padding: 14px 28px; font-size: 15.5px; }
.btn-icon { padding: 9px; border-radius: var(--r-sm); aspect-ratio: 1; }
.btn-full { width: 100%; }

/* ── Loading spinner ──────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner-dark {
  border-color: rgba(26,22,18,0.2);
  border-top-color: var(--text);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form elements ────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text2); }
.form-label .req { color: var(--danger); margin-left: 2px; }

.input {
  background: var(--surface);
  border: 1.5px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
  outline: none;
  width: 100%;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.input::placeholder { color: var(--text3); }
.input.error { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

select.input { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239a9088' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-error { font-size: 12px; color: var(--danger); margin-top: 2px; }
.form-hint  { font-size: 12px; color: var(--text3); }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 24px; }
.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 14.5px; font-weight: 700; color: var(--text); }

/* ── Badge / Tag ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge-pending  { background: var(--warn-bg);   color: var(--warn); }
.badge-active   { background: var(--green-bg);  color: var(--green); }
.badge-suspended{ background: var(--danger-bg); color: var(--danger); }
.badge-accent   { background: var(--accent-bg); color: var(--accent); }

/* ── Toast notifications ──────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #232018;
  color: #f0ece3;
  padding: 12px 18px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease, toastOut 0.3s ease forwards;
  animation-delay: 0s, 3.5s;
  max-width: 320px;
  pointer-events: all;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warn    { border-left: 3px solid var(--warn); }
@keyframes toastIn  { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: none; } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform: translateY(-8px); } }

/* ── Table ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); }
table.p84-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.p84-table thead th {
  background: var(--surface2);
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.p84-table tbody tr { transition: background var(--t); }
.p84-table tbody tr:hover td { background: var(--surface2); }
.p84-table tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.p84-table tbody tr:last-child td { border-bottom: none; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 14, 12, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  animation: modalIn 0.2s ease;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { color: var(--text3); font-size: 20px; line-height: 1; cursor: pointer; transition: color var(--t); padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body  { padding: 24px; }
.modal-footer{ padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Divider ──────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text3);
  font-size: 12px;
  font-weight: 500;
  margin: 20px 0;
}
.divider-text::before,
.divider-text::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Utilities ────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-accent  { color: var(--accent); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--green); }
.text-muted   { color: var(--text3); }
.text-sm      { font-size: 12.5px; }
.text-xs      { font-size: 11px; }
.font-bold    { font-weight: 700; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.gap-4        { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Mobile input auto-zoom guard ─────────────────────────────
   Focusing any field with font-size < 16px makes mobile browsers (Firefox
   Android, iOS Safari) zoom the page in — and the zoom STICKS after blur,
   so later screens (e.g. flashcard review) render with their right side
   pushed off-screen. Keep every focusable field at ≥16px on phones;
   max(16px, 1em) preserves fields that are already larger. */
@media (max-width: 640px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select, textarea { font-size: max(16px, 1em) !important; }
}
