/* ASTROLOGY APP — UI STYLESHEET v1.0
   Design tokens are imported separately via /static/tokens.css.
   All colors come from semantic tokens — NEVER raw palette. */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

html {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-feature-settings: var(--features-ui);
  background: var(--bg-page);
  color: var(--fg-primary);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-app);
  color: var(--fg-primary);
}

.mono { font-family: var(--font-mono); font-feature-settings: var(--features-data); }

/* ── TOPBAR ───────────────────────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-6);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  height: 56px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: var(--z-raised);
}

.brand { display: flex; align-items: center; gap: var(--sp-3); }
.brand-mark { width: 28px; height: 28px; color: var(--fg-accent); }
.brand-title { font-family: var(--font-display); font-size: var(--fs-heading-md); font-weight: var(--w-semibold); letter-spacing: var(--tracking-tight); }
.brand-subtitle { font-size: var(--fs-caption); color: var(--fg-tertiary); margin-top: 1px; letter-spacing: var(--tracking-wide); text-transform: uppercase; }

.nav-tabs { display: flex; gap: var(--sp-1); overflow-x: auto; }
.nav-tab {
  background: transparent;
  border: 0;
  color: var(--fg-tertiary);
  padding: var(--sp-2) var(--sp-4);
  font-family: var(--font-ui);
  font-size: var(--fs-body-sm);
  font-weight: var(--w-medium);
  letter-spacing: var(--tracking-wide);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.nav-tab:hover { color: var(--fg-primary); background: var(--bg-row-hover); }
.nav-tab.is-active { color: var(--fg-on-primary); background: var(--bg-button-primary); }

.topbar-actions { display: flex; gap: var(--sp-2); }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  color: var(--fg-secondary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--bg-row-hover); color: var(--fg-primary); border-color: var(--border-default); }

/* ── LAYOUT ───────────────────────────────────────────────────────────────── */
.layout {
  flex: 1;
  padding: var(--sp-8) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  max-width: 1480px;
  margin: 0 auto;
  width: 100%;
}

.view { display: none; }
.view.is-active { display: grid; }

[data-view="birth"].is-active { grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-6); align-items: start; }
[data-view="wheel"].is-active { grid-template-columns: 1fr; }
[data-view="table"].is-active { grid-template-columns: 1fr; }
[data-view="grid"].is-active { grid-template-columns: 1fr; }
[data-view="transits"].is-active { grid-template-columns: 1fr; }
[data-view="clients"].is-active { grid-template-columns: 1fr; }

/* ── PANELS ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-1);
}

.panel-head { margin-bottom: var(--sp-5); }
.panel-title {
  font-family: var(--font-display);
  font-size: var(--fs-heading-lg);
  font-weight: var(--w-semibold);
  margin: 0 0 var(--sp-1);
  letter-spacing: var(--tracking-tight);
  color: var(--fg-primary);
}
.panel-sub { font-size: var(--fs-body-sm); color: var(--fg-tertiary); margin: 0; }

/* ── FORM ─────────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: var(--sp-5); }
.form-row {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
  margin: 0;
}
.form-row legend {
  font-size: var(--fs-caption);
  font-weight: var(--w-medium);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-tertiary);
  padding: 0 var(--sp-2);
  margin-left: -2px;
}
.field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.field span {
  font-size: var(--fs-caption);
  font-weight: var(--w-medium);
  letter-spacing: var(--tracking-wide);
  color: var(--fg-tertiary);
}
.field input, .field select {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  padding: var(--sp-control-y) var(--sp-control-x);
  background: var(--bg-input);
  color: var(--fg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
  width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.field input[type="number"] { font-feature-settings: var(--features-data); }
.field-checkbox { flex-direction: row; align-items: center; gap: var(--sp-2); }
.field-checkbox span { letter-spacing: 0; text-transform: none; font-size: var(--fs-body-sm); }
.field-search { width: 100%; }

.form-actions { display: flex; gap: var(--sp-3); align-items: center; }
.btn {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-weight: var(--w-medium);
  letter-spacing: var(--tracking-wide);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn-primary { background: var(--bg-button-primary); color: var(--fg-on-primary); }
.btn-primary:hover { background: var(--bg-button-primary-hover); }
.btn-ghost { background: transparent; color: var(--fg-secondary); border-color: var(--border-default); }
.btn-ghost:hover { background: var(--bg-row-hover); color: var(--fg-primary); }

/* ── META PANEL ───────────────────────────────────────────────────────────── */
.panel-meta dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  row-gap: var(--sp-3);
  column-gap: var(--sp-4);
}
.panel-meta dt { color: var(--fg-tertiary); font-size: var(--fs-caption); letter-spacing: var(--tracking-caps); text-transform: uppercase; padding-top: 3px; }
.panel-meta dd { margin: 0; color: var(--fg-primary); font-size: var(--fs-body); font-weight: var(--w-medium); }
.panel-meta dd.mono { font-family: var(--font-mono); font-size: var(--fs-body-sm); }

/* ── WHEEL ────────────────────────────────────────────────────────────────── */
.panel-wheel { display: flex; flex-direction: column; gap: var(--sp-5); }

/* Licensed glyph fonts (Astrolog 7.70 wheel pack). Loaded once, cached by the
   browser. Used for sign and planet glyphs on the wheel. The fall-through
   keeps Noto Sans Symbols 2 if the licensed font has no glyph for a codepoint. */
@font-face {
  font-family: "AstrologStar";
  src: url("/static/fonts/WSTARXP_.TTF") format("truetype"),
       url("/static/fonts/WStarTT2.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "AstrologMatrix";
  src: url("/static/fonts/MXWSTARXP.ttf") format("truetype"),
       url("/static/fonts/MXWSGLYPXP.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "AstrologGlyph";
  src: url("/static/fonts/ASTROMTX.TTF") format("truetype"),
       url("/static/fonts/ALMAFONT.TTF") format("truetype"),
       url("/static/fonts/ASMASTR.TTF") format("truetype");
  font-display: swap;
}

.wheel-controls {
  display: flex; align-items: center; gap: var(--sp-3);
  flex-wrap: wrap; padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev-1); border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}
.wheel-controls label {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-caption); color: var(--fg-secondary);
  font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
}
.wheel-controls select,
.wheel-controls button {
  font-family: var(--font-ui); font-size: var(--fs-body-sm);
  color: var(--fg-primary); background: var(--bg-elev-2);
  border: 1px solid var(--border-subtle); border-radius: var(--r-sm);
  padding: 6px 10px; cursor: pointer;
}
.wheel-controls button:hover { border-color: var(--brand); }
.wheel-controls .spacer { flex: 1 1 auto; }
.wheel-controls .export-btn {
  background: var(--brand); color: var(--bg-app);
  border: none; font-weight: 600;
}

.wheel-host {
  /* The whole wheel must be visible without scrolling: aspect-ratio is 1/1, so
     capping the WIDTH also caps the height. Size it against the viewport MINUS
     the real chrome (header + controls + subject bar ≈ 290px) rather than a flat
     52vh — 52vh on an 800px window gave a 416px wheel with dead space all round. */
  width: min(100%, 880px, calc(100vh - 290px));
  max-width: 880px;
  min-width: 300px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  background: var(--bg-app);
  border-radius: var(--r-lg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.wheel-host svg { width: 100%; height: 100%; display: block; }
.wheel-host .zodiac text {
  font-family: "AstrologStar", "Noto Sans Symbols 2", "DejaVu Sans", var(--font-glyph), sans-serif;
  /* His licensed fonts have NO glyph at U+2648–U+2653, so the browser was falling
     through to a COLOUR EMOJI font and drawing each sign as a filled coloured disc.
     Forcing text presentation makes it render a plain vector glyph instead. */
  font-variant-emoji: text;
}
.wheel-host .planets text {
  font-family: "AstrologStar", "Noto Sans Symbols 2", "DejaVu Sans", var(--font-glyph), sans-serif;
  font-variant-emoji: text;
}

/* Aspect line styling — colors are inline via PLT palette, this is base */
.wheel-host line[data-aspect] { stroke-linecap: round; }
.wheel-host line[data-aspect="1"] { stroke: #5e6ad2; }  /* conjunction */
.wheel-host line[data-aspect="2"] { stroke: #c2410c; }  /* opposition */
.wheel-host line[data-aspect="3"] { stroke: #c2410c; }  /* square */
.wheel-host line[data-aspect="4"] { stroke: #15803d; }  /* trine */
.wheel-host line[data-aspect="5"] { stroke: #1d4ed8; }  /* sextile */
.wheel-host line[data-aspect][data-minor="1"] { stroke-opacity: 0.55; }

/* Subject bar — the chart's subject data lives HERE, above the wheel.
   The interior of the wheel carries only the aspect field. */
.wheel-subject {
  display: flex; align-items: baseline; justify-content: center;
  flex-wrap: wrap; gap: var(--sp-2) var(--sp-3);
  max-width: 880px; margin: 0 auto var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
  border-radius: var(--r-md, 6px);
  text-align: center;
}
.wheel-subject .ws-place {
  font-family: var(--font-display); font-size: var(--fs-heading-sm, 17px);
  font-weight: var(--w-semibold, 600); color: var(--fg-primary);
}
.wheel-subject .ws-date, .wheel-subject .ws-geo {
  font-size: var(--fs-body-sm, 12px); color: var(--fg-secondary);
}
.wheel-subject .ws-sys {
  font-size: 10px; letter-spacing: 0.12em; color: var(--fg-tertiary);
  text-transform: uppercase;
}

.wheel-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-2); }
.wheel-legend .legend-item {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-body-sm); color: var(--fg-secondary);
}
.wheel-legend .legend-glyph { font-family: "AstrologStar", var(--font-glyph); font-size: 20px; line-height: 1; }

/* ── TABLE ────────────────────────────────────────────────────────────────── */
.table-host, .grid-host, .transits-host, .clients-host { width: 100%; }
.table-row {
  display: grid;
  grid-template-columns: 32px 1fr 1.2fr 1fr 1fr 80px;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-body-sm);
}
.table-row.header {
  font-size: var(--fs-caption);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-tertiary);
  font-weight: var(--w-medium);
  background: var(--bg-elevated);
  position: sticky;
  top: 56px;
}
.table-row .glyph {
  font-family: var(--font-glyph);
  font-size: 24px;
  line-height: 1;
}
.table-row .pos { font-family: var(--font-mono); font-feature-settings: var(--features-data); }
.table-row .retro { color: var(--copper-500); font-size: var(--fs-caption); letter-spacing: var(--tracking-caps); text-transform: uppercase; }
.table-row .sign { font-weight: var(--w-medium); }

/* ── ASPECT GRID ──────────────────────────────────────────────────────────── */
.grid-host {
  display: grid;
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
}
.aspect-cell {
  aspect-ratio: 1 / 1;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-glyph);
  font-size: 14px;
  color: var(--fg-tertiary);
  cursor: default;
  transition: background var(--dur-fast) var(--ease-out);
}
.aspect-cell.has-aspect { cursor: pointer; }
.aspect-cell.has-aspect:hover { background: var(--bg-row-hover); }
.aspect-cell.header { background: var(--bg-elevated); color: var(--fg-secondary); }
.aspect-cell.header .glyph { font-size: 18px; }
.aspect-cell.empty { background: var(--bg-app); }

/* ── TRANSITS ─────────────────────────────────────────────────────────────── */
.transits-toolbar { display: flex; gap: var(--sp-4); align-items: center; margin-bottom: var(--sp-5); }
.transits-clock { font-family: var(--font-mono); font-feature-settings: var(--features-data); color: var(--fg-tertiary); font-size: var(--fs-body-sm); }
.transit-row {
  display: grid;
  /* minmax(0, …) not 1fr: a bare 1fr track has min-width:auto, so long content
     overflows the track and prints on top of the next cell. */
  grid-template-columns: 32px minmax(0, 1.4fr) 28px minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-body-sm);
  transition: background var(--dur-fast) var(--ease-out);
}
/* every cell must be allowed to shrink, and long names must truncate rather than collide */
.transit-row > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.transit-row > .glyph { overflow: visible; }
.transit-row.header {
  font-size: var(--fs-caption);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-tertiary);
  font-weight: var(--w-medium);
  background: var(--bg-elevated);
}
.transit-row .glyph { font-family: var(--font-glyph); font-size: 22px; line-height: 1; }
.transit-row .pos { font-family: var(--font-mono); font-feature-settings: var(--features-data); }
.transit-row:hover { background: var(--bg-row-hover); }
.transit-row.exact { border-left: 2px solid var(--fg-accent); }
.transit-row.applying .orb::before { content: "↓ "; color: var(--fg-info); }
.transit-row.separating .orb::before { content: "↑ "; color: var(--fg-tertiary); }

/* ── CLIENTS ──────────────────────────────────────────────────────────────── */
.clients-toolbar { display: flex; gap: var(--sp-4); align-items: end; margin-bottom: var(--sp-5); }
.clients-count { font-size: var(--fs-caption); color: var(--fg-tertiary); }
.clients-host {
  display: grid;
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
}
.client-row {
  display: grid;
  /* id | NAME | year | place | tz — the name column is the one that carries the
     record now, so it gets the room. minmax(0, …) so a long name truncates
     instead of overflowing onto the year. */
  grid-template-columns: 52px minmax(0, 1.6fr) 56px minmax(0, 1fr) 64px;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  align-items: center;
  background: var(--bg-panel);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
  font-size: var(--fs-body-sm);
}
.client-row:hover { background: var(--bg-row-hover); }
.client-row.is-active { background: var(--bg-row-selected); }
.client-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-row .id { font-family: var(--font-mono); color: var(--fg-tertiary); font-size: var(--fs-body-sm); }
.client-row .cname { font-weight: var(--w-semibold); color: var(--fg-primary); }
.client-row .cplace { color: var(--fg-secondary); }
.client-row .year { font-family: var(--font-mono); font-feature-settings: var(--features-data); }
.client-row .tz { font-size: var(--fs-caption); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--fg-tertiary); text-align: right; }
.clients-pager { display: flex; gap: var(--sp-3); align-items: center; justify-content: center; margin-top: var(--sp-4); }
.clients-pager span { font-size: var(--fs-caption); color: var(--fg-tertiary); }

/* ── EMPTY / TOAST ────────────────────────────────────────────────────────── */
.empty-state {
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--fg-tertiary);
  font-size: var(--fs-body);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--r-md);
  width: 100%;
}
.toast-host {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--fg-accent);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-body-sm);
  box-shadow: var(--shadow-2);
  animation: toast-in var(--dur-base) var(--ease-out);
  max-width: 360px;
}
.toast.error { border-left-color: var(--fg-error); }
.toast.info { border-left-color: var(--fg-info); }

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

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  [data-view="birth"].is-active { grid-template-columns: 1fr; }
  /* The nav drops to a SECOND grid row here, so the bar must be allowed to grow.
     A fixed 56px height crushed both rows into one and made the nav overlap the
     subtitle and the theme button. */
  .topbar { grid-template-columns: 1fr auto; gap: var(--sp-3); height: auto; min-height: 56px; padding: var(--sp-3) var(--sp-4); }
  .nav-tabs { grid-column: 1 / -1; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tab { white-space: nowrap; flex: 0 0 auto; }
  .layout { padding: var(--sp-4); }
}
@media (max-width: 600px) {
  .topbar { align-items: start; }
  .brand-subtitle { display: none; }   /* the two-line brand collides with the nav on a phone */

  /* The aspect matrix is (N+1) square — 15x15 for a 14-body chart. On a phone the
     cells get small, so keep a legible floor and let the matrix scroll sideways
     rather than crush the glyphs. */
  .grid-host {
    grid-template-columns: repeat(var(--cols, 14), minmax(24px, 1fr));
    overflow-x: auto;
    overflow-y: hidden;
  }
  .aspect-cell { font-size: 11px; }
  .aspect-cell.header .glyph { font-size: 14px; }

  /* Transits: a row carries SIX cells (planet, name, aspect glyph, natal name,
     aspect, orb). Four narrow columns made the last two collapse onto each other.
     Give it a deliberate two-line layout instead of a generic column count. */
  .transit-row {
    grid-template-columns: 26px minmax(0, 1fr) 20px minmax(0, 1fr);
    gap: 2px var(--sp-2);
    padding: var(--sp-3);
  }
  .transit-row > span:nth-child(5) { grid-column: 2 / 4; }
  .transit-row > span:nth-child(6) { grid-column: 4 / -1; text-align: right; }
  .transit-row.header > span:nth-child(5) { grid-column: 2 / 4; }
  .transit-row.header > span:nth-child(6) { grid-column: 4 / -1; text-align: right; }

  /* Planets table keeps its columns but the track sizes must be shrinkable. */
  .table-row { grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr); }
  .table-row .vel, .transit-row .vel { display: none; }

  .client-row { grid-template-columns: 50px minmax(0, 1fr) minmax(0, 1fr) 60px; }
  .client-row .id { display: none; }

  /* Nothing in any of these grids may overflow its track. */
  .table-row > span, .client-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .table-row > .glyph, .client-row > .glyph { overflow: visible; }
}
