/* Timapple — design tokens, base, utilities. */

:root {
  /* surfaces (warm cream / beige scale) */
  --bg:           oklch(97.5% 0.012 80);
  --surface:      oklch(99%   0.008 85);
  --surface-2:    oklch(94.5% 0.018 75);
  --surface-3:    oklch(90%   0.022 70);
  --surface-4:    oklch(85%   0.024 65);

  /* ink (text) */
  --ink:          oklch(28%   0.02  60);
  --ink-soft:     oklch(46%   0.025 60);
  --ink-faint:    oklch(64%   0.02  60);
  --ink-on-accent: oklch(99% 0.005 90);

  /* accents */
  --sage:         oklch(72%   0.06 145);
  --sage-strong:  oklch(58%   0.09 145);
  --sage-soft:    oklch(92%   0.03 145);
  --terracotta:        oklch(64%   0.13  35);
  --terracotta-strong: oklch(54% 0.15 35);
  --terracotta-soft:   oklch(91% 0.04 35);
  --rose:         oklch(78%   0.07  15);
  --rose-soft:    oklch(94%   0.02  15);
  --ochre:        oklch(78%   0.10  80);
  --ochre-soft:   oklch(94%   0.03  80);
  --slate-blue:   oklch(60%   0.05 250);
  --slate-blue-soft: oklch(93% 0.02 250);

  /* state aliases */
  --success: var(--sage-strong);
  --warning: var(--ochre);
  --danger:  var(--terracotta);
  --info:    var(--slate-blue);

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --lh-tight: 1.2;
  --lh-body: 1.55;

  /* space (4px grid) */
  --s-0: 0;
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;
  --s-16: 4rem;

  /* shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  /* shadows */
  --shadow-sm: 0 1px 2px oklch(28% 0.02 60 / 0.06);
  --shadow-md: 0 6px 18px -8px oklch(28% 0.02 60 / 0.18);
  --shadow-lg: 0 18px 40px -16px oklch(28% 0.02 60 / 0.22);

  /* motion — disabled site-wide for snap */
  --motion-fast: 0s;
  --motion: 0s;
  --motion-slow: 0s;
  --ease: linear;

  /* layout */
  --sidebar-w: 232px;
  --topbar-h: 56px;
  --music-bar-h: 64px;
  --content-max: 1280px;
  --gutter: clamp(0.75rem, 2vw, 1.5rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        oklch(22% 0.012 60);
    --surface:   oklch(26% 0.014 60);
    --surface-2: oklch(30% 0.016 60);
    --surface-3: oklch(34% 0.018 60);
    --surface-4: oklch(40% 0.020 60);
    --ink:       oklch(95% 0.012 80);
    --ink-soft:  oklch(78% 0.014 80);
    --ink-faint: oklch(60% 0.014 80);
    --sage-soft:        oklch(36% 0.05 145);
    --terracotta-soft:  oklch(36% 0.06 35);
    --rose-soft:        oklch(36% 0.04 15);
    --ochre-soft:       oklch(36% 0.06 80);
    --slate-blue-soft:  oklch(36% 0.04 250);
    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.4);
    --shadow-md: 0 6px 18px -8px oklch(0% 0 0 / 0.5);
    --shadow-lg: 0 18px 40px -16px oklch(0% 0 0 / 0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* reset */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  font-feature-settings: "kern", "liga", "ss01", "cv02", "cv11";
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--sage-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible {
  outline: 2px solid var(--sage-strong);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

h1, h2, h3, h4, h5 {
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  color: var(--ink);
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.9em; }

/* layout shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "sidebar main";
  min-height: 100vh;
}

.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-right: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
  padding: var(--s-4) var(--s-3);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.sidebar__nav { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; }

main#content {
  grid-area: main;
  padding: var(--s-6) var(--gutter);
  max-width: var(--content-max);
  width: 100%;
  margin-inline: auto;
  contain: layout;
}

/* Music bar: tucked at the bottom of the sidebar; hidden until something plays */
.music-bar {
  display: none;
  margin: var(--s-3) calc(var(--s-3) * -1) calc(var(--s-3) * -1);
  padding: var(--s-3);
  border-top: 1px solid color-mix(in oklch, var(--surface-3), transparent 40%);
  background: color-mix(in oklch, var(--surface-2), transparent 20%);
}
body.player-on .music-bar { display: block; }

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 84vw;
    max-width: 320px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform var(--motion) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
}

/* nav */
.nav-section { margin-top: var(--s-5); }
.nav-section:first-of-type { margin-top: var(--s-2); }
.nav-section__label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  padding: var(--s-1) var(--s-3);
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-md);
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  font-weight: 500;
  margin-top: 1px;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.nav-link:hover {
  background: color-mix(in oklch, var(--sage-soft), transparent 30%);
  color: var(--ink);
  text-decoration: none;
}
.nav-link.is-active {
  background: var(--sage-soft);
  color: var(--sage-strong);
  font-weight: 600;
}
.nav-link__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3) var(--s-4);
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--sage), var(--terracotta));
  box-shadow: var(--shadow-sm);
}

/* topbar pieces */
.topbar {
  grid-area: topbar;
  min-width: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--gutter);
  background: color-mix(in oklch, var(--bg), transparent 6%);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 55%);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}
.topbar__title {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.topbar__spacer { flex: 1; }
.topbar__user {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
}
.topbar__avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--rose), var(--ochre));
  display: grid; place-items: center;
  color: var(--ink-on-accent);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
}

/* utilities */
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack--sm { gap: var(--s-2); }
.stack--lg { gap: var(--s-6); }
.row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.row--between { justify-content: space-between; }
.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-lg { font-size: var(--fs-lg); }
.mono { font-family: var(--font-mono); }
.right { text-align: right; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* page header */
.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-6);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 60%);
}
.page-header h1 {
  font-size: var(--fs-2xl);
  margin-bottom: var(--s-1);
}
.page-header__sub { color: var(--ink-soft); font-size: var(--fs-sm); }

/* htmx loading state — no transitions, just discrete states */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* Music bar (compact, vertical — fits inside sidebar) */
.player {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: 100%;
  min-width: 0;
}
.player__row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}
.player__art {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  flex-shrink: 0;
  overflow: hidden;
  display: grid; place-items: center;
  font-size: var(--fs-sm);
  color: var(--ink-faint);
}
.player__meta { min-width: 0; flex: 1; }
.player__title { font-size: var(--fs-xs); font-weight: 600; line-height: 1.2; }
.player__artist { font-size: var(--fs-xs); color: var(--ink-soft); line-height: 1.2; }
.player__controls { display: flex; gap: 2px; justify-content: center; }
.player__btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-pill);
  display: grid; place-items: center;
  color: var(--ink-soft);
  transition: background var(--motion-fast) var(--ease);
}
.player__btn:hover { background: var(--sage-soft); color: var(--sage-strong); }
.player__btn--main {
  background: var(--ink);
  color: var(--bg);
  width: 32px; height: 32px;
}
.player__btn--main:hover { background: var(--sage-strong); color: var(--ink-on-accent); }
.player__progress { display: flex; flex-direction: column; gap: 2px; }
.player__bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.player__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sage), var(--sage-strong));
  width: 0;
  transition: width 200ms linear;
}
.player__times {
  display: flex; justify-content: space-between;
  font-size: 10px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* toast region */
.toast-region {
  position: fixed;
  bottom: calc(var(--music-bar-h) + var(--s-4));
  right: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: 50;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--surface-3);
  border-left: 3px solid var(--sage-strong);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  max-width: 360px;
}
.toast--error { border-left-color: var(--terracotta); }
.toast--warn { border-left-color: var(--ochre); }

/* alert */
.alert {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius-md);
  background: var(--rose-soft);
  border-left: 3px solid var(--terracotta);
  color: var(--ink);
  font-size: var(--fs-sm);
}
.alert--ok { background: var(--sage-soft); border-left-color: var(--sage-strong); }
.alert--warn { background: var(--ochre-soft); border-left-color: var(--ochre); }
.alert--info { background: var(--slate-blue-soft); border-left-color: var(--slate-blue); }

/* skeleton — flat tone, no animation */
.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  height: 1em;
  width: 100%;
}

/* long-list optimization */
.lazy-rows > * {
  content-visibility: auto;
  contain-intrinsic-size: 64px;
}

/* Media library */
.upload-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: var(--s-2);
}
.upload-bar__fill {
  height: 100%;
  background: var(--sage-strong);
  width: 0;
  transition: width 100ms linear;
}
.dropzone {
  border: 2px dashed var(--surface-3);
  border-radius: var(--radius-md);
  padding: var(--s-8);
  text-align: center;
  color: var(--ink-soft);
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.dropzone.is-dragover {
  border-color: var(--sage-strong);
  background: var(--sage-soft);
  color: var(--ink);
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--s-2);
}
.media-grid--videos {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.media-tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in oklch, var(--surface-3), transparent 30%);
  border-radius: var(--radius-md);
  background: #0c0c0c;
  cursor: pointer;
}
.media-tile > img,
.media-tile > video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-tile--video {
  aspect-ratio: 1 / 1;
}
.media-podcast-card {
  gap: var(--s-3);
  align-items: flex-start;
  overflow: hidden;
}
.media-podcast-card__art {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex: 0 0 auto;
}
.media-podcast-card__body {
  flex: 1 1 14rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.media-podcast-card__title {
  overflow-wrap: anywhere;
}
.media-podcast-card__description {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* Dashboard 2x2 grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 3fr 1fr;
  gap: var(--s-4);
  height: calc(100vh - 2 * var(--s-6));
  min-height: 600px;
}
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 2fr 1fr 2fr 1fr;
    height: auto;
    min-height: 0;
  }
}
.dashboard-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.dashboard-card > .card__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* News rows */
.news-row {
  display: block;
  padding: var(--s-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease);
  text-decoration: none;
  color: inherit;
}
.news-row:hover { background: color-mix(in oklch, var(--sage-soft), transparent 50%); text-decoration: none; }
.news-row__title {
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
}
.news-row__meta {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}
.news-row__meta a { color: var(--ink-faint); }
.news-row__meta a:hover { color: var(--sage-strong); }

/* Generic modal shell (instant) */
dialog.app-modal, dialog.article-modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(94vw, 760px);
  width: 100%;
  margin: auto;
  max-height: 92vh;
  overscroll-behavior: contain;
}
dialog.app-modal::backdrop, dialog.article-modal::backdrop {
  background: oklch(20% 0.01 60 / 0.55);
}

/* Lock the page scroll while any modal is open. */
body.modal-open { overflow: hidden; }

/* Prevent scroll chain from inside modal content/editors to the page. */
.modal__panel, .modal__body, .article-modal__panel, .article-modal__body,
.editor__body { overscroll-behavior: contain; }
.article-modal__panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--surface-3);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.article-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
}
.article-modal__title {
  font-size: var(--fs-xl);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.article-modal__meta {
  font-size: var(--fs-xs);
  color: var(--ink-faint);
  margin-top: var(--s-1);
}
.article-modal__close {
  width: 32px; height: 32px;
  border-radius: var(--radius-pill);
  display: grid; place-items: center;
  color: var(--ink-soft);
  flex-shrink: 0;
}
.article-modal__close:hover { background: var(--surface-2); color: var(--ink); }
.article-modal__body {
  padding: var(--s-5) var(--s-6);
  overflow-y: auto;
  font-size: var(--fs-md);
  line-height: 1.7;
}
.article-modal__body p { margin-bottom: var(--s-4); }
.article-modal__footer {
  padding: var(--s-3) var(--s-6);
  border-top: 1px solid color-mix(in oklch, var(--surface-3), transparent 50%);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
}
.article-modal__footer .btn {
  height: 36px;
  min-height: 36px;
  padding: 0 var(--s-4);
  font-size: var(--fs-sm);
}
