:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f8fc;
  --border: #e7e7ef;
  --text: #17171f;
  --text-muted: #6b6b7a;
  --brand: #6d4aff;
  --brand-hover: #5a38f0;
  --brand-soft: #f0ecff;
  --danger: #e5484d;
  --danger-soft: #fdeceb;
  --success: #17b26a;
  --pending: #9a9aa8;
  --matched: #3b82f6;
  --processed: #17b26a;
  --archived: #9a9aa8;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 40, 0.04), 0 1px 1px rgba(20, 20, 40, 0.03);
  --shadow-md: 0 8px 24px rgba(30, 20, 70, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101017;
    --surface: #17171f;
    --surface-2: #1c1c26;
    --border: #2a2a37;
    --text: #f1f1f6;
    --text-muted: #9b9baa;
    --brand: #8b6bff;
    --brand-hover: #a186ff;
    --brand-soft: #241c47;
    --danger: #ff6b6f;
    --danger-soft: #3a1e21;
    --success: #35d68a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.topnav-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.topnav-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topnav-links a {
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.topnav-links a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topnav-links a.active { color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.logout-form { margin-inline-start: 6px; }
.logout-form button {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font: inherit; padding: 8px 14px; margin: 0; width: auto; border-radius: 999px;
}
.logout-form button:hover { color: var(--danger); background: var(--danger-soft); }

/* Layout */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

h1 { font-size: 1.5rem; margin: 8px 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 16px; font-weight: 700; }
h3 { font-size: 1rem; margin: 20px 0 8px; font-weight: 600; }

/* Forms */
label { display: block; margin-bottom: 14px; font-size: 0.88rem; color: var(--text-muted); font-weight: 500; }
input, select, textarea, button {
  font: inherit;
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 6px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; font-family: inherit; }
button {
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  width: auto;
  padding: 11px 20px;
  margin-top: 8px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
button:hover { background: var(--brand-hover); }
button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
  box-shadow: none;
}
button.secondary:hover { background: var(--border); }
button.danger { background: var(--danger); }
button.danger.secondary { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
button.danger.secondary:hover { background: var(--danger); color: #fff; }
.inline-form { display: flex; gap: 10px; align-items: flex-start; }
.inline-form input { margin-top: 0; }
.checkbox-label { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
.checkbox-label input { width: auto; }

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-bar .field { flex: 1 1 160px; min-width: 140px; }
.filter-bar label { margin-bottom: 6px; }
.filter-bar input, .filter-bar select { margin-top: 0; }
.filter-bar .filter-actions { display: flex; gap: 8px; }
.filter-bar .filter-actions button { margin-top: 0; }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.login-box h1 { margin-top: 0; }
.error { color: var(--danger); font-size: 0.88rem; }

/* Video grid & cards */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.video-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.video-card:hover { border-color: var(--brand); box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.video-card h3 { margin: 8px 0 4px; font-size: 1.02rem; }
.video-card-top { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.note-preview { color: var(--text-muted); font-size: 0.85rem; margin: 0; }
.video-card-date { color: var(--text-muted); font-size: 0.78rem; margin-top: 6px; }

.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
}
.status-pending { background: var(--pending); }
.status-matched { background: var(--matched); }
.status-processed { background: var(--processed); }
.status-archived { background: var(--archived); }

.category-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
}

/* Category list */
.category-list { list-style: none; padding: 0; margin: 0; }
.category-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.category-list li:last-child { border-bottom: none; }
.category-list .category-name { font-weight: 500; }
.category-list .category-actions { display: flex; gap: 6px; flex-shrink: 0; }
.category-list form { margin: 0; }
.category-list button { padding: 6px 14px; margin: 0; font-size: 0.85rem; }
.category-edit-form { display: flex; gap: 8px; flex: 1; }
.category-edit-form input { margin: 0; }

/* Detail page */
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-muted); font-weight: 500; }
.detail-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.detail-actions form { display: inline-block; margin: 0; }
.result-card ul { padding-inline-start: 22px; margin: 0; }
.result-card li { margin-bottom: 8px; }
.full-transcript { white-space: pre-wrap; color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 0.85rem; margin-top: -8px; }
.process-form textarea { margin-bottom: 10px; }
.note-form textarea { margin-bottom: 10px; }

.empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}
