/* Medi-Cal Wire - vanilla CSS, no build step */

:root {
  color-scheme: dark;
  --bg: #0b0d0f;
  --surface: #15181c;
  --surface-2: #1c2025;
  --ink: #edf1f3;
  accent-color: var(--accent);
  --muted: #98a2a9;
  --subtle: #7c848a;
  --line: rgba(237, 241, 243, .07);
  --line-strong: rgba(237, 241, 243, .14);
  --accent: #00d38c;
  --accent-ink: #04170f;
  --accent-soft: rgba(0, 211, 140, .13);
  --danger: #f06262;
  --danger-soft: rgba(240, 98, 98, .15);
  --warn: #d9a13e;
  --warn-soft: rgba(217, 161, 62, .14);

  --font-sans: "General Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-control: 10px;
  --radius-card: 16px;
  --radius-pill: 999px;
  --shadow-float: 0 12px 40px rgba(0, 0, 0, .4);

  --header-h: 52px;
  --tabs-h: 44px;
  --bar-h: 60px;

  /* house scale tokens (names from taste/tokens/tokens.json; values are our own where they
     diverge from the house repo's specific numbers, e.g. motion) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 4px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-md: 18px;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --leading-normal: 1.5;
  --tracking-wide: 0.04em;
  --container-sm: 640px;
  --container-content: 720px;
  --duration-fast: 150ms;
  --duration-base: 240ms;
  --duration-slow: 280ms;
  --ease-standard: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  overflow: hidden;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

a { color: inherit; }

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

/* ---------- app shell ---------- */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
  background: var(--bg);
}

/* ---------- header ---------- */

#header {
  position: relative;
  min-height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: calc(env(safe-area-inset-top) + 8px) var(--space-4) var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.wordmark {
  font-size: 17px;
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
}

.wordmark-accent {
  color: var(--accent);
  margin-left: 0.3em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-control);
  color: var(--ink);
  transition: background-color var(--duration-fast);
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn { transition: none; }
}

.icon-btn:hover { background: var(--surface-2); }

.chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.chip--alert {
  background: var(--danger-soft);
  color: var(--danger);
}

.search-row-wrap {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 250ms ease;
  z-index: 5;
}

@media (prefers-reduced-motion: reduce) {
  .search-row-wrap { transition: none; }
}

.search-row-wrap.is-open {
  grid-template-rows: 1fr;
}

.search-row {
  overflow: hidden;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 var(--space-4);
}

.search-row-wrap.is-open .search-row {
  padding: var(--space-2) var(--space-4);
}

#searchInput {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  padding: 0 var(--space-3);
}

#searchInput::-webkit-search-cancel-button { display: none; }

/* ---------- source tabs ---------- */

#sourceTabs {
  display: flex;
  align-items: center;
  height: var(--tabs-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 var(--space-2) 0 var(--space-4);
  gap: var(--space-2);
}

.tabs-track {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
  padding-right: var(--space-4);
  mask-image: linear-gradient(to right, var(--ink) calc(100% - var(--space-4)), transparent);
  -webkit-mask-image: linear-gradient(to right, var(--ink) calc(100% - var(--space-4)), transparent);
}

.tabs-track::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  height: 100%;
  padding: 0 2px;
  font-size: 12.5px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: color var(--duration-fast);
  min-width: 44px;
}

@media (prefers-reduced-motion: reduce) {
  .tab { transition: none; }
}

.tab.is-active {
  color: var(--ink);
}

.filters-btn {
  flex: 0 0 auto;
  margin-left: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: var(--space-6);
  border-radius: var(--radius-control);
  border: 1px solid var(--line-strong);
  color: var(--muted);
  min-height: 44px;
}

.filters-btn .badge {
  position: absolute;
  top: 2px;
  right: 2px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: var(--space-4);
  height: var(--space-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-1);
}

.badge[hidden] { display: none; }

/* ---------- feed row / rail ---------- */

#feedRow {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

#feed {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* ---------- live alerts rail ---------- */

.alert-rail {
  padding: var(--space-3) 0 0;
}

.alert-rail[hidden] { display: none; }

.rail-heading {
  margin: 0 var(--space-4) var(--space-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--danger);
}

.rail-track {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 var(--space-4);
  mask-image: linear-gradient(to right, var(--ink) calc(100% - var(--space-4)), transparent);
  -webkit-mask-image: linear-gradient(to right, var(--ink) calc(100% - var(--space-4)), transparent);
}

.rail-track::-webkit-scrollbar { display: none; }

.rail-card {
  flex: 0 0 auto;
  width: 240px;
  padding: 14px var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
}

.rail-card:hover { background: var(--surface-2); }

.rail-card .card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rail-alert-label {
  color: var(--danger);
}

#feedList {
  list-style: none;
  margin: 0;
  padding: var(--space-3) var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ---------- month section headers ---------- */

.month-header {
  margin-top: var(--space-3);
  padding: 0 var(--space-1);
}

.month-header:first-child { margin-top: 0; }

.month-header h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted);
}

.feed-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--subtle);
  text-align: center;
  padding: var(--space-4) 0 calc(24px + env(safe-area-inset-bottom));
}

/* ---------- cards ---------- */

.card {
  padding: 14px var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
}

.card:hover { background: var(--surface-2); }

@media (prefers-reduced-motion: no-preference) {
  .card.is-entering {
    animation: card-in var(--duration-base) var(--ease-standard) both;
  }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 2ch;
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--subtle);
  margin: 0 0 var(--space-1);
}

.meta-line .revised {
  color: var(--warn);
}

.meta-line .source-alert {
  color: var(--danger);
}

.card-title {
  font-size: 15.5px;
  font-weight: var(--weight-bold);
  line-height: 1.35;
  margin: 0 0 var(--space-1);
}

.card-summary {
  font-size: var(--text-sm);
  color: var(--muted);
  margin: 0 0 var(--space-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px var(--space-2);
  border-radius: var(--radius-control);
}

.tag--action { background: var(--accent-soft); color: var(--accent); }
.tag--deadline { background: var(--warn-soft); color: var(--warn); }
.tag--category { background: var(--surface-2); color: var(--muted); }

/* ---------- state messages ---------- */

.state-msg {
  padding: 40px var(--space-5);
  text-align: center;
  color: var(--muted);
  font-size: var(--text-sm);
}

.state-msg .btn { margin-top: var(--space-3); }

/* ---------- skeleton ---------- */

.skeleton .sk-line {
  height: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: var(--space-2);
}

.sk-meta { width: 40%; height: 9px; }
.sk-title { width: 80%; height: 13px; }
.sk-summary { width: 95%; }
.sk-summary + .sk-summary { width: 60%; margin-bottom: 0; }

@media (prefers-reduced-motion: no-preference) {
  .skeleton .sk-line {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--line-strong) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
  }
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ---------- new pill ---------- */

.new-pill {
  position: sticky;
  top: var(--space-2);
  z-index: 3;
  margin: 0 auto var(--space-2);
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-2) 14px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: var(--weight-bold);
  box-shadow: var(--shadow-float);
  border: none;
}

.new-pill[hidden] { display: none; }

/* ---------- sheets (filters + detail) ---------- */

.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .55);
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-standard);
}

.sheet.is-open .sheet-backdrop { opacity: 1; }

.sheet-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-height: 70%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top-left-radius: var(--radius-card);
  border-top-right-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-standard);
}

.sheet.is-open .sheet-panel {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop, .sheet-panel { transition: none; }
}

.sheet-grabber {
  width: 36px;
  height: var(--space-1);
  border-radius: 999px;
  background: var(--line-strong);
  margin: 10px auto var(--space-1);
  flex: 0 0 auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-4) var(--space-2);
  flex: 0 0 auto;
}

.sheet-title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  margin: 0;
}

.sheet-body {
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-1) var(--space-4) var(--space-4);
}

.sheet-footer {
  display: flex;
  gap: 10px;
  padding: var(--space-3) var(--space-4) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.filter-group {
  display: block;
  margin-bottom: 18px;
}

.filter-group legend, .filter-group > span:first-child {
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--subtle);
  margin-bottom: var(--space-2);
  display: block;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
}

.select-row select {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-control);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  padding: 0 10px;
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transition: opacity var(--duration-fast);
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

.btn:hover { opacity: 0.9; }
.btn[hidden] { display: none; }

.btn--ghost {
  background: var(--surface-2);
  color: var(--ink);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

/* detail sheet */

.detail-meta {
  margin-bottom: var(--space-2);
}

.detail-meta .meta-line {
  gap: 1ch;
  flex-wrap: wrap;
}

.detail-title {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  line-height: 1.35;
  margin: 0 0 var(--space-3);
}

.action-callout {
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: var(--radius-control);
  padding: var(--space-3);
  margin-bottom: 14px;
  font-size: var(--text-sm);
}

.action-callout strong {
  display: block;
  font-size: 11.5px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--accent);
  margin-bottom: var(--space-1);
}

.detail-body {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: var(--space-4);
}

.detail-body p { margin: 0 0 10px; }
.detail-body a { color: var(--accent); text-decoration: underline; }

.detail-sheet #detailLink {
  width: 100%;
  margin-bottom: var(--space-2);
}

/* ---------- bottom bar ---------- */

.bottom-bar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}

.bar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  color: var(--muted);
}

.bar-btn span {
  font-size: 10.5px;
}

.bar-btn:hover, .bar-btn:active { color: var(--accent); }

/* ---------- responsive ---------- */

@media (min-width: 768px) {
  .bottom-bar { display: none; }

  #app {
    grid-template-rows: auto auto 1fr;
  }

  #header, #sourceTabs {
    max-width: var(--container-content);
    margin: 0 auto;
    width: 100%;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  #feedRow {
    max-width: var(--container-content);
    margin: 0 auto;
    width: 100%;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .detail-sheet .sheet-panel {
    left: 50%;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, calc(-50% + 24px));
    width: 90%;
    max-width: var(--container-sm);
    max-height: 80vh;
    border-radius: var(--radius-card);
  }

  .detail-sheet.is-open .sheet-panel {
    transform: translate(-50%, -50%);
  }

  .detail-sheet .sheet-grabber { display: none; }
}

@media (min-width: 1024px) {
  /* 240px rail + 720px feed column, matching the ≥768px feed width */
  #header, #sourceTabs, #feedRow {
    max-width: 960px;
  }

  #feedRow {
    grid-template-columns: 240px minmax(0, 720px);
  }

  #filtersBtn, #filtersBtnMobile {
    display: none;
  }

  #filterSheet.sheet {
    position: static;
    display: block;
  }

  #filterSheet .sheet-backdrop {
    display: none;
  }

  #filterSheet .sheet-panel {
    position: static;
    transform: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border-right: 1px solid var(--line);
    box-shadow: none;
  }

  #filterSheet .sheet-grabber {
    display: none;
  }

  #filterSheet .sheet-body {
    overflow-y: auto;
  }
}
