/* ==========================================================================
   Maqal.kz Admin — Design System
   Linear-grade dark UI for power users
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------ */
:root {
  /* Backgrounds */
  --bg-0: #08080d;
  --bg-1: #0f0f17;
  --bg-2: #16161f;
  --bg-3: #1c1c28;
  --bg-hover: #1e1e2b;
  --bg-active: #22222f;

  /* Borders */
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.13);
  --border-focus: #5e6ad2;

  /* Text */
  --text-1: #ededf0;
  --text-2: #9898a6;
  --text-3: #5c5c6e;

  /* Accent */
  --accent: #5e6ad2;
  --accent-hover: #6e7ae2;
  --accent-subtle: rgba(94,106,210,0.12);

  /* Semantic */
  --success: #3fba7b;
  --success-subtle: rgba(63,186,123,0.12);
  --danger: #e5534b;
  --danger-subtle: rgba(229,83,75,0.12);
  --warning: #d4a44c;
  --warning-subtle: rgba(212,164,76,0.12);

  /* Spacing scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;
  --sp-8: 32px; --sp-10: 40px;

  /* Radii */
  --r-sm: 4px; --r-md: 6px; --r-lg: 8px; --r-xl: 10px;

  /* Type */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-xs: 11px; --text-sm: 12px; --text-md: 13px;
  --text-lg: 14px; --text-xl: 16px; --text-2xl: 20px;
  --weight-normal: 400; --weight-medium: 500; --weight-semibold: 600;

  /* Layout */
  --sidebar-w: 232px;
  --topbar-h: 0px;
  --bottombar-h: 56px;

  /* Transitions */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --duration: 0.15s;
}

/* --- Reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-1);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }
img, video { display: block; max-width: 100%; }

/* --- Shell ------------------------------------------------------------- */
.shell { display: flex; height: 100vh; }

/* --- Sidebar ----------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-brand {
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
  color: var(--text-1);
}
.sidebar-section {
  padding: var(--sp-1) var(--sp-2);
}
.sidebar-label {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-2);
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
  cursor: pointer;
  user-select: none;
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text-1); }
.sidebar-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
}
.sidebar-item svg {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}
.sidebar-kbd-hint {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 6px var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.sidebar-kbd-hint:hover { background: var(--bg-hover); color: var(--text-2); }
.sidebar-kbd-hint kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); font-size: 10px; font-weight: var(--weight-medium);
  color: var(--text-3); line-height: 1;
}

/* --- Main content ------------------------------------------------------ */
.main {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
}
.page-wide { max-width: 960px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.03em;
  color: var(--text-1);
}

/* --- Card -------------------------------------------------------------- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card + .card { margin-top: var(--sp-3); }
.card-body { padding: var(--sp-5); }

/* --- Proverb card (video generator) ------------------------------------ */
.proverb-id {
  display: inline-flex; align-items: center;
  padding: 1px 6px;
  background: var(--bg-3); border-radius: var(--r-sm);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  color: var(--text-3);
}
.proverb-meta {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.proverb-slug {
  font-size: var(--text-xs); color: var(--text-3);
}
.proverb-body {
  font-size: 18px;
  font-weight: var(--weight-semibold);
  line-height: 1.55;
  letter-spacing: -0.02em;
  color: var(--text-1);
  margin: var(--sp-3) 0;
}
.proverb-translation {
  font-size: var(--text-md);
  color: var(--text-3);
  margin-bottom: var(--sp-4);
}

/* --- Caption block ----------------------------------------------------- */
.caption-block {
  position: relative;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
}
.caption-text {
  font-family: var(--font);
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.caption-copy {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
}
.caption-copy.copied {
  color: var(--success) !important;
  border-color: var(--success) !important;
}

/* --- Section divider --------------------------------------------------- */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-4) 0;
}

/* --- Section label ----------------------------------------------------- */
.section-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-bottom: var(--sp-3);
}

/* --- Theme picker ------------------------------------------------------ */
.theme-grid {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
}
.theme-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-1);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}
.theme-btn:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.theme-btn.loading {
  opacity: 0.5;
  pointer-events: none;
}
.theme-btn .dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

/* --- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 14px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.4;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-1);
  border-color: var(--border-hover);
}
.btn-danger-ghost {
  background: transparent;
  color: var(--text-3);
}
.btn-danger-ghost:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}
.btn-sm { padding: 4px 10px; font-size: var(--text-xs); }
.btn-lg { padding: 8px 18px; font-size: var(--text-md); }

/* --- Video player ------------------------------------------------------ */
.video-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #000;
  margin: var(--sp-4) 0;
}
.video-wrap video { width: 100%; display: block; max-height: 520px; }
.video-actions {
  display: flex; gap: var(--sp-2); margin-top: var(--sp-3);
}

/* --- Alerts / Flash ---------------------------------------------------- */
.flash {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
  border: 1px solid transparent;
}
.flash-success { background: var(--success-subtle); color: var(--success); border-color: rgba(63,186,123,0.2); }
.flash-error { background: var(--danger-subtle); color: var(--danger); border-color: rgba(229,83,75,0.2); }
.flash-info { background: var(--accent-subtle); color: var(--accent); border-color: rgba(94,106,210,0.2); }

/* --- Empty state ------------------------------------------------------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
}
.empty-state-icon {
  width: 40px; height: 40px; margin-bottom: var(--sp-4);
  color: var(--text-3);
}
.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-2);
  margin-bottom: var(--sp-1);
}
.empty-state-desc {
  font-size: var(--text-sm);
  color: var(--text-3);
}

/* --- Loading spinner --------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Command palette --------------------------------------------------- */
.cmd-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
}
.cmd-backdrop.open { display: flex; }
.cmd-dialog {
  width: 520px; max-width: 92vw;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  overflow: hidden;
}
.cmd-input-wrap {
  display: flex; align-items: center;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.cmd-input-wrap svg {
  width: 16px; height: 16px; color: var(--text-3);
  flex-shrink: 0; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.cmd-input {
  flex: 1;
  padding: var(--sp-3) var(--sp-3);
  background: none; border: none; outline: none;
  font-size: var(--text-lg);
  color: var(--text-1);
}
.cmd-input::placeholder { color: var(--text-3); }
.cmd-results {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--sp-1) 0;
}
.cmd-group-label {
  padding: var(--sp-2) var(--sp-4) var(--sp-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cmd-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
  transition: background var(--duration) var(--ease);
  font-size: var(--text-md);
  color: var(--text-2);
}
.cmd-item:hover, .cmd-item.focused {
  background: var(--bg-hover);
  color: var(--text-1);
}
.cmd-item svg {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.cmd-item kbd {
  margin-left: auto;
  font-size: 10px; color: var(--text-3);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 1px 5px;
}
.cmd-footer {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--text-xs); color: var(--text-3);
}
.cmd-footer kbd {
  font-size: 10px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 1px 5px;
}

/* --- Bottom tabs (mobile) ---------------------------------------------- */
.bottom-tabs {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-tabs-inner {
  display: flex; height: var(--bottombar-h);
  max-width: 500px; margin: 0 auto;
  padding: 0 var(--sp-4);
  gap: var(--sp-2);
}
.bottom-tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  font-size: 10px; font-weight: var(--weight-medium);
  color: var(--text-3);
  transition: color var(--duration) var(--ease);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.bottom-tab svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.bottom-tab:hover, .bottom-tab.active { color: var(--accent); }

/* --- Table (for future proverbs list) ---------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-1);
}
table {
  width: 100%; border-collapse: collapse;
}
thead th {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
tbody td {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-md);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr { transition: background var(--duration) var(--ease); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* --- Video grid (library) ---------------------------------------------- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-3);
}
.video-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease);
}
.video-card:hover { border-color: var(--border-hover); }
.video-card-player {
  position: relative;
  background: #000;
  cursor: pointer;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-card-player video {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.video-card-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.3);
  opacity: 1;
  transition: opacity var(--duration) var(--ease);
  pointer-events: none;
}
.video-card-play svg {
  width: 32px; height: 32px;
  stroke: #fff; fill: rgba(255,255,255,0.15);
  stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round;
}
.video-card-player:hover .video-card-play { opacity: 0.8; }
.video-card-player video:not([paused]) ~ .video-card-play,
.video-card-player.playing .video-card-play { opacity: 0; }
.video-card-info { padding: var(--sp-3); }
.video-card-row {
  display: flex; align-items: center; gap: var(--sp-2);
}
.video-card-slug {
  font-size: var(--text-xs); color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.video-card-meta {
  margin-top: var(--sp-2);
  font-size: var(--text-xs); color: var(--text-3);
  justify-content: space-between;
}
.video-card-actions {
  display: flex; gap: 2px;
}
.video-card-actions .btn { padding: 4px 6px; }
.video-card-body {
  font-size: var(--text-sm);
  color: var(--text-1);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  margin: var(--sp-2) 0;
}
.caption-block-sm {
  margin: var(--sp-2) 0;
  padding: var(--sp-2) var(--sp-3);
  padding-right: var(--sp-10);
}
.caption-block-sm .caption-text {
  font-size: var(--text-xs);
  line-height: 1.5;
  max-height: 72px;
  overflow: hidden;
}
.caption-block-sm .caption-copy {
  top: var(--sp-1);
  right: var(--sp-1);
}

/* --- Badge ------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 1px 6px; border-radius: var(--r-sm);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
}
.badge-success { background: var(--success-subtle); color: var(--success); }
.badge-muted { background: var(--bg-3); color: var(--text-3); }

/* --- Responsive -------------------------------------------------------- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-tabs { display: flex; }
  .main { padding-bottom: var(--bottombar-h); }
  .page { padding: var(--sp-5) var(--sp-4); }
  .page-title { font-size: 18px; }
  .proverb-body { font-size: 16px; }
  .video-wrap video { max-height: 400px; }
  .video-actions { flex-direction: column; }
  .video-actions .btn { justify-content: center; }
  .theme-grid { flex-direction: column; }
  .theme-btn { justify-content: center; }
  .cmd-dialog { border-radius: var(--r-lg); }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--sp-2); }
}

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

/* --- Focus ring -------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Selection --------------------------------------------------------- */
::selection { background: rgba(94,106,210,0.3); }
