/* My Workspace — component styles.
   Built to ui/UI_BASELINE.md. Every value comes from tokens.css.
   Section order matches the baseline document. */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  -webkit-text-size-adjust: 100%;
}
body { overflow-x: hidden; }            /* PRD §45 — never a horizontal scrollbar */
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button { font-family: inherit; }
svg.ico { width: var(--icon); height: var(--icon); flex: none; }

/* ======================================================= 1. APP SHELL ==== */
.app-header {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 60;
  display: flex; align-items: center; gap: var(--gap);
  padding: 0 14px;
  background: var(--shell-bg);
  border-bottom: 1px solid var(--shell-border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand__mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
}
.brand__name { color: #fff; font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand__sub { display: none; }

.header-search {
  flex: 1; max-width: 620px; margin: 0 auto; position: relative;
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 10px 0 12px;
  background: var(--shell-bg-2); border: 1px solid var(--shell-border);
  border-radius: var(--radius-pill);
}
.header-search input {
  flex: 1; min-width: 0; height: 100%;
  background: none; border: 0; outline: none;
  color: var(--shell-fg); font-size: var(--fs-body);
}
.header-search input::placeholder { color: var(--shell-fg-muted); }
.header-search .ico { color: var(--shell-fg-muted); }
.header-search button { background: none; border: 0; padding: 4px; cursor: pointer; color: var(--shell-fg-muted); }
.header-search button:hover { color: #fff; }

.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 0; cursor: pointer;
  background: none; color: var(--shell-fg-muted);
  display: grid; place-items: center; position: relative;
}
.icon-btn:hover { background: var(--shell-bg-2); color: #fff; }
.icon-btn__dot {
  position: absolute; top: 7px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--red-fg); border: 2px solid var(--shell-bg);
}
.avatar {
  width: var(--avatar); height: var(--avatar); border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700; letter-spacing: .3px;
}

/* ---- sidebar ---- */
.sidebar {
  position: fixed; top: var(--header-h); bottom: 0; left: 0; width: var(--sidebar-w);
  z-index: 50; background: var(--shell-bg);
  border-right: 1px solid var(--shell-border);
  padding: 10px 10px 20px; overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--shell-border); border-radius: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  height: 38px; padding: 0 11px; margin-bottom: 2px;
  border-radius: var(--radius-tile);
  color: var(--shell-fg); font-size: var(--fs-body); font-weight: 500;
  white-space: nowrap; overflow: hidden;
}
.nav-item .ico { color: var(--shell-fg-muted); }
.nav-item:hover { background: var(--shell-bg-2); color: #fff; }
.nav-item:hover .ico { color: #fff; }
.nav-item.is-active { background: var(--shell-active); color: #fff; font-weight: 600; }
.nav-item.is-active .ico { color: #fff; }

.app-main {
  padding: calc(var(--header-h) + var(--gap)) var(--gap) var(--gap);
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

/* ======================================================== 2. PRIMITIVES == */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--pad-card);
}
.card--flush { padding: 0; overflow: hidden; }
.card__head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
}
.card__title { font-size: var(--fs-card-title); font-weight: 600; margin: 0; min-width: 0; }
.card__sub { font-size: var(--fs-meta); color: var(--text-muted); margin-top: 2px; }
/* A card head can carry three or four buttons (the prompt styles do). Without
   a wrap they march off the right edge of a 320px phone. */
.card__action { margin-left: auto; display: flex; align-items: center; gap: 8px;
                flex-wrap: wrap; justify-content: flex-end; }
.see-all { font-size: var(--fs-meta); font-weight: 600; color: var(--primary); }

.icon-tile {
  width: var(--icon-tile); height: var(--icon-tile); flex: none;
  border-radius: var(--radius-tile);
  display: grid; place-items: center;
}

.badge {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-small); font-weight: 600; white-space: nowrap;
}
.badge--green  { color: var(--green-fg);  background: var(--green-bg); }
.badge--amber  { color: var(--amber-fg);  background: var(--amber-bg); }
.badge--red    { color: var(--red-fg);    background: var(--red-bg); }
.badge--purple { color: var(--purple-fg); background: var(--purple-bg); }
.badge--blue   { color: var(--blue-fg);   background: var(--blue-bg); }
.badge--slate  { color: var(--slate-fg);  background: var(--slate-bg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-button); padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-input);
  font-size: var(--fs-body); font-weight: 600; cursor: pointer;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); color: #fff; }
.btn--ghost { background: var(--card-bg); color: var(--text); border-color: var(--card-border); }
.btn--ghost:hover { background: var(--row-bg); }
.btn--danger { background: var(--red-fg); color: #fff; }
.btn--sm { height: 30px; padding: 0 11px; font-size: var(--fs-meta); }

.input, .select, textarea.input {
  width: 100%; height: var(--h-input); padding: 0 11px;
  background: var(--card-bg); color: var(--text);
  border: 1px solid var(--card-border); border-radius: var(--radius-input);
  font-size: var(--fs-body); font-family: inherit; outline: none;
}
textarea.input { height: auto; min-height: 84px; padding: 9px 11px; resize: vertical; }
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field { display: block; margin-bottom: 12px; }
.field__label { display: block; font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field__error { font-size: var(--fs-small); color: var(--red-fg); margin-top: 4px; }

.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-tab {
  height: 30px; padding: 0 13px;
  display: inline-flex; align-items: center;
  border-radius: var(--radius-pill); border: 1px solid transparent;
  background: var(--row-bg); color: var(--text-muted);
  font-size: var(--fs-meta); font-weight: 600; cursor: pointer;
}
.pill-tab:hover { background: var(--row-hover); color: var(--text); }
.pill-tab.is-active { background: var(--primary); color: #fff; }

.segmented { display: inline-flex; gap: 4px; background: var(--row-bg); padding: 3px; border-radius: var(--radius-pill); }
.segmented a, .segmented button {
  height: 26px; padding: 0 12px; border: 0; background: none; cursor: pointer;
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted);
  display: inline-flex; align-items: center;
}
.segmented .is-active { background: var(--card-bg); color: var(--text); box-shadow: var(--shadow-card); }

/* ---- list rows (Today's Overview, Recent Activity) ---- */
.list-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; margin-bottom: 7px;
  background: var(--row-bg); border-radius: var(--radius-tile);
}
.list-row:last-child { margin-bottom: 0; }
.list-row:hover { background: var(--row-hover); }
.list-row__body { min-width: 0; flex: 1; }
/* These are <span>s so a whole row can be an <a>. Without an explicit
   display:block they stay inline: the title and meta share a line, and
   text-overflow — which only applies to block boxes — does nothing. */
.list-row__title {
  display: block;
  font-size: var(--fs-body); font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-row__meta {
  display: block;
  font-size: var(--fs-meta); color: var(--text-muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-row__right { margin-left: auto; text-align: right; font-size: var(--fs-meta); color: var(--text-muted); white-space: nowrap; }
.money-red   { color: var(--red-fg);   font-weight: 600; }
.money-green { color: var(--green-fg); font-weight: 600; }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
.table th {
  text-align: left; font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted);
  padding: 9px 10px; background: var(--row-bg);
  border-bottom: 1px solid var(--card-border); white-space: nowrap;
}
.table th:first-child { border-top-left-radius: var(--radius-tile); }
.table th:last-child  { border-top-right-radius: var(--radius-tile); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--card-border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--row-bg); }
.table__scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* A table that must fit a one-third-width card (dashboard row 3, baseline §3.3):
   headers may wrap and long values break, so it does not scroll sideways on a
   desktop. The scroll container stays as the fallback for narrow screens. */
.table--fit th { white-space: normal; }
.table--fit th, .table--fit td { padding-left: 7px; padding-right: 7px; }
.table--fit td { overflow-wrap: anywhere; }
.table--fit .badge { white-space: nowrap; }

/* ---- empty / loading / error states (PRD §61, §62, §43) ---- */
.empty-state { text-align: center; padding: 38px 20px; }
.empty-state__icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  border-radius: 14px; display: grid; place-items: center;
}
.empty-state__icon .ico { width: 24px; height: 24px; }
.empty-state__title { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.empty-state__text { font-size: var(--fs-body); color: var(--text-muted); margin: 0 auto 18px; max-width: 380px; }
/* An empty state or a flash can echo what was typed ("Nothing matches …"), and
   one unbroken word would push the page past a phone's edge (BUG-017). */
.empty-state__title, .empty-state__text, .flash { overflow-wrap: anywhere; }

.skeleton {
  background: linear-gradient(90deg, #EEF2F7 25%, #F8FAFC 37%, #EEF2F7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.flash { padding: 11px 14px; border-radius: var(--radius-tile); margin-bottom: var(--gap); font-weight: 500; }
.flash--info    { background: var(--blue-bg);  color: var(--blue-fg); }
.flash--success { background: var(--green-bg); color: var(--green-fg); }
.flash--error   { background: var(--red-bg);   color: var(--red-fg); }

/* ======================================================== 3. DASHBOARD === */
.page-title { font-size: var(--fs-page-title); font-weight: 700; margin: 0 0 4px; }
.page-sub { font-size: var(--fs-meta); color: var(--text-muted); margin: 0 0 var(--gap); }

.stat-row {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--gap); margin-bottom: var(--gap);
}
.stat-card {
  display: flex; align-items: center; gap: 12px;
  padding: 15px var(--pad-card);
  border: 1px solid var(--card-border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.stat-card__label { font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted); }
.stat-card__value { font-size: var(--fs-stat); font-weight: 700; line-height: 1.15; }
.stat-card__sub { font-size: var(--fs-small); color: var(--text-muted); margin-top: 1px; }

.grid-3-cal { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) minmax(0, 1.5fr); gap: var(--gap); margin-bottom: var(--gap); }
.grid-3     { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));   gap: var(--gap); margin-bottom: var(--gap); }
.grid-2     { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));   gap: var(--gap); margin-bottom: var(--gap); }

.thumb-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.thumb { display: block; }
.thumb img, .thumb__ph {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 8px; background: var(--row-bg); display: block;
}
.thumb__ph { display: grid; place-items: center; color: var(--text-faint); }
/* The caption is a <span> inside the link; without display:block its ellipsis
   is dead and a long title pushes the grid past the phone's edge (BUG-026,
   the same trap as BUG-006). */
.thumb__cap {
  display: block;
  font-size: var(--fs-small); color: var(--text-muted); margin-top: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- month grid ---- */
.month { width: 100%; border-collapse: collapse; table-layout: fixed; }
.month th { font-size: var(--fs-small); font-weight: 600; color: var(--text-muted); padding: 6px 0; text-align: center; background: none; border: 0; }
.month td { padding: 2px; vertical-align: top; height: 42px; border: 0; }
.month__day {
  display: block; text-align: center; font-size: var(--fs-meta);
  line-height: 22px; height: 22px; border-radius: var(--radius-pill); color: var(--text);
}
.month__day.is-today { background: var(--primary); color: #fff; font-weight: 700; }
.month__day.is-out { color: var(--text-faint); }
.month__chip {
  display: block; margin-top: 2px; padding: 1px 5px;
  font-size: 10px; font-weight: 600; border-radius: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- finance summary tiles ---- */
.fin-tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 12px; }
.fin-tile { padding: 12px; border-radius: var(--radius-tile); }
.fin-tile__label { font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted); }
.fin-tile__value { font-size: 20px; font-weight: 700; margin-top: 3px; }
.fin-tile__sub { font-size: var(--fs-small); color: var(--text-muted); margin-top: 1px; }

/* ======================================================== 4. MOBILE ====== */
/* `.mobile-only` has to beat the element's own display rule (.quick-grid is
   display:grid, .icon-btn is display:grid, .card is display:block...), and
   those rules are declared below this line. !important here, with an explicit
   restore per element inside the mobile breakpoint, is what keeps the two
   layouts from leaking into each other. Same for .desktop-only. */
.mobile-only { display: none !important; }

.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.quick-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  padding: 14px 6px; min-height: 86px;
  border-radius: var(--radius-card); border: 1px solid var(--card-border);
  text-align: center; color: var(--text);
}
.quick-tile__icon { width: 34px; height: 34px; border-radius: 10px; background: #fff; display: grid; place-items: center; }
.quick-tile__label { font-size: 11.5px; font-weight: 600; line-height: 1.25; }

.bottom-nav {
  display: none;
  position: fixed; inset: auto 0 0 0; z-index: 70; height: var(--bottomnav-h);
  background: var(--card-bg); border-top: 1px solid var(--card-border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav__inner { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: var(--bottomnav-h); }
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; cursor: pointer;
  font-size: 10.5px; font-weight: 600; color: var(--text-muted);
}
.bottom-nav .is-active { color: var(--shell-active); }
.bottom-nav__fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  margin-top: -20px; box-shadow: var(--shadow-fab);
}
.bottom-nav__fab .ico { width: 24px; height: 24px; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(15, 23, 42, .45);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 90;
  background: var(--card-bg);
  border-radius: 18px 18px 0 0; padding: 14px 14px 26px;
  transform: translateY(100%); transition: transform .22s ease;
  max-height: 80vh; overflow-y: auto;
}
.sheet.is-open { transform: translateY(0); }
.sheet__grip { width: 38px; height: 4px; border-radius: 2px; background: var(--card-border); margin: 0 auto 12px; }
.sheet__title { font-size: var(--fs-card-title); font-weight: 600; margin: 0 0 12px; }
.sheet__item { display: flex; align-items: center; gap: 11px; padding: 11px 8px; border-radius: var(--radius-tile); color: var(--text); }
.sheet__item:hover { background: var(--row-bg); }
/* Sign out is a POST (a link could be triggered by another site); it looks like the rest. */
.sheet__item--button { width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }

/* ================================================== 4b. RECORD PAGES ==== */
/* Everything below is Phase 3: forms, detail pages, filters, tabs.
   Same tokens, same shapes as the dashboard — no second visual language. */

/* ---- page layout ---- */
.page-head { display: flex; align-items: flex-start; gap: var(--gap); margin-bottom: var(--gap); }
.page-head__text { min-width: 0; }
.page-head__actions { margin-left: auto; display: flex; gap: 8px; flex: none; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
/* An implicit grid column is `auto`, whose minimum is min-content — the
   same trap as a bare `1fr`. Name the track so the cards can shrink. */
.detail-col { display: grid; grid-template-columns: minmax(0, 1fr);
              gap: var(--gap); align-content: start; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--gap); }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }

.field__req { color: var(--red-fg); }
.field__help { display: block; font-size: var(--fs-small); color: var(--text-muted); margin-top: 4px; }
.field--error .input, .field--error .select { border-color: var(--red-fg); }
.field--error .input:focus { box-shadow: 0 0 0 3px var(--red-bg); }
.field--check { display: flex; align-items: flex-start; gap: 9px; padding: 9px 0; }
.field--check input { width: 17px; height: 17px; margin: 1px 0 0; flex: none; accent-color: var(--primary); }

.uploader { display: block; }
.uploader input[type="file"] { display: block; width: 100%; font-size: var(--fs-meta); padding: 8px 0; }
.uploader__hint {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-small); color: var(--text-muted);
}

.form-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: var(--gap); padding-top: var(--gap);
  border-top: 1px solid var(--card-border);
}
.form-actions__spacer { flex: 1; }

fieldset.subform { border: 1px solid var(--card-border); border-radius: var(--radius-card); padding: 14px; margin: 0 0 var(--gap); }
fieldset.subform > legend { font-size: var(--fs-meta); font-weight: 600; color: var(--text-muted); padding: 0 6px; }

/* ---- child-row editor (DPR manpower / materials) ---- */
.child-table { width: 100%; border-collapse: collapse; }
.child-table th {
  font-size: var(--fs-small); font-weight: 600; color: var(--text-muted);
  text-align: left; padding: 0 6px 6px; background: none; border: 0; white-space: nowrap;
}
.child-table td { padding: 3px 6px 3px 0; border: 0; vertical-align: middle; }
.child-table .input, .child-table .select { height: 34px; font-size: var(--fs-meta); }
.child-row__drop { background: none; border: 0; cursor: pointer; color: var(--text-faint); padding: 4px; }
.child-row__drop:hover { color: var(--red-fg); }

/* ---- record header ---- */
.record-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: var(--gap);
}
.record-head__text { min-width: 0; flex: 1; }
.record-head__eyebrow {
  font-size: var(--fs-small); font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .4px;
}
.record-head__title { font-size: var(--fs-page-title); font-weight: 700; margin: 2px 0 0; }
.record-head__actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ---- field grid on detail pages ---- */
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px var(--gap); margin: 0; }
.fields__item { min-width: 0; }
.fields dt { font-size: var(--fs-small); font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.fields dd { margin: 0; font-size: var(--fs-body); overflow-wrap: anywhere; }
.fields__empty { color: var(--text-faint); }
.fields__block { grid-column: 1 / -1; }
.fields__block dd { margin-top: 3px; line-height: 1.55; white-space: normal; }

.muted-note { font-size: var(--fs-meta); color: var(--text-muted); margin: 4px 0 0; }

/* ---- tags ---- */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px;
  border-radius: var(--radius-pill); background: var(--slate-bg); color: var(--slate-fg);
  font-size: var(--fs-small); font-weight: 600;
}
.tag:hover { background: var(--primary-soft); color: var(--primary); }

/* ---- timeline (activity / history) ---- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--card-border); }
.timeline__item { position: relative; padding: 0 0 14px 14px; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: -23px; top: 4px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--card-bg);
}
.timeline__title { font-size: var(--fs-body); font-weight: 600; }
.timeline__meta { font-size: var(--fs-small); color: var(--text-muted); margin-top: 1px; }
.timeline__detail { font-size: var(--fs-meta); color: var(--text-muted); margin-top: 4px; }

/* ---- status / attach inline forms ---- */
.status-form, .attach-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-form .select { width: auto; min-width: 140px; }
.status-form .input { flex: 1; min-width: 160px; }
.attach-form .input { flex: 1; min-width: 180px; height: auto; padding: 7px 9px; }

/* ---- filter bar ---- */
.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-card); padding: 12px; margin-bottom: var(--gap);
}
.filters .input, .filters .select { width: auto; height: 34px; font-size: var(--fs-meta); }
.filters__q { flex: 1; min-width: 190px; }
.filters__select { min-width: 140px; }
.filters__date { min-width: 130px; }

.result-count { font-size: var(--fs-meta); color: var(--text-muted); margin: 0 0 10px; }

/* ---- tabs (project detail) ---- */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; margin-bottom: var(--gap);
  border-bottom: 1px solid var(--card-border); padding-bottom: 0;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 9px 13px; border-bottom: 2px solid transparent;
  font-size: var(--fs-body); font-weight: 600; color: var(--text-muted);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab__count {
  font-size: 10.5px; font-weight: 700; line-height: 16px;
  min-width: 16px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--slate-bg); color: var(--slate-fg); text-align: center;
}
.tab.is-active .tab__count { background: var(--primary-soft); color: var(--primary); }

/* ---- calendar views ---- */
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-title { font-size: var(--fs-card-title); font-weight: 700; }
.cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th {
  font-size: var(--fs-small); font-weight: 600; color: var(--text-muted);
  padding: 7px 4px; text-align: center; background: none;
  border-bottom: 1px solid var(--card-border);
}
.cal-grid td {
  border: 1px solid var(--card-border); vertical-align: top;
  padding: 5px; height: 104px; width: 14.28%;
}
.cal-grid td.is-out { background: var(--row-bg); }
.cal-day { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cal-day__num {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: var(--radius-pill); font-size: var(--fs-meta); font-weight: 600;
}
.cal-day__num.is-today { background: var(--primary); color: #fff; }
.cal-day__add { color: var(--text-faint); padding: 0 2px; line-height: 1; }
.cal-day__add:hover { color: var(--primary); }
.cal-chip {
  display: block; margin-bottom: 3px; padding: 2px 6px; border-radius: 6px;
  font-size: 10.5px; font-weight: 600; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-chip--derived { opacity: .85; border: 1px dashed currentColor; }
.cal-more { font-size: 10px; color: var(--text-muted); }

.cal-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.cal-list__day { border: 1px solid var(--card-border); border-radius: var(--radius-card); padding: 12px; }
.cal-list__date {
  font-size: var(--fs-meta); font-weight: 700; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.cal-list__date .see-all { margin-left: auto; float: none; }

/* ---- small KPI strip used on detail pages ---- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi {
  padding: 11px 12px; border-radius: var(--radius-tile); background: var(--row-bg);
  color: var(--text); display: block;
}
a.kpi:hover { background: var(--row-hover); color: var(--text); }
.kpi__label { font-size: var(--fs-small); font-weight: 600; color: var(--text-muted); }
.kpi__value { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ---- quick links row ---- */
.quick-links { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- file library grid ---- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--gap); }
.file-card { display: block; color: var(--text); }
.file-card img, .file-card__ph {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  border-radius: var(--radius-tile); background: var(--row-bg);
}
.file-card__ph { display: grid; place-items: center; color: var(--m-documents); }
.file-card__title {
  display: block; margin-top: 7px; font-size: var(--fs-meta); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-card__meta {
  display: block; font-size: var(--fs-small); color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- voice capture (baseline §5) ---- */
.voice-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin: calc(var(--pad-card) * -1) calc(var(--pad-card) * -1) var(--gap);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: var(--m-voice-tint); color: var(--m-voice);
  font-size: var(--fs-meta); font-weight: 600;
}

.record { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.record__left { display: grid; justify-items: center; gap: 8px; }
.record__button {
  width: 72px; height: 72px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  box-shadow: var(--shadow-fab);
}
.record__button:hover { background: var(--primary-hover); }
.record__button.is-recording { background: var(--red-fg); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(220, 38, 38, .18); } }
@media (prefers-reduced-motion: reduce) { .record__button.is-recording { animation: none; } }

.record__timer { font-size: var(--fs-meta); font-weight: 700; font-variant-numeric: tabular-nums; }
.record__wave { display: flex; align-items: flex-end; gap: 3px; height: 26px; }
.record__wave span {
  width: 4px; height: 6px; border-radius: 2px; background: var(--primary-soft);
}
.record__wave.is-live span { background: var(--primary); animation: wave .9s ease-in-out infinite; }
.record__wave.is-live span:nth-child(2n) { animation-delay: .15s; }
.record__wave.is-live span:nth-child(3n) { animation-delay: .3s; }
@keyframes wave { 50% { height: 24px; } }
@media (prefers-reduced-motion: reduce) { .record__wave.is-live span { animation: none; height: 16px; } }

.record__right { min-width: 0; }
.record__status { font-size: var(--fs-meta); color: var(--text-muted); margin: 8px 0 0; }
.record__status--ok { color: var(--green-fg); }
.record__status--warn { color: var(--amber-fg); }
.record__controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.record__lang { display: flex; align-items: center; }

.provider-note {
  margin-top: var(--gap); padding-top: 12px; border-top: 1px solid var(--card-border);
  display: grid; gap: 4px; font-size: var(--fs-meta); color: var(--text-muted);
}
.provider-note code {
  background: var(--row-bg); padding: 1px 5px; border-radius: 4px; font-size: var(--fs-small);
}

/* ---- what the reader understood ---- */
.reading { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.reading__title { font-size: var(--fs-card-title); font-weight: 600; }
.reading__meta { font-size: var(--fs-meta); color: var(--text-muted); margin-top: 2px; }
.reading__bar {
  flex: 1; min-width: 120px; height: 6px; border-radius: 3px;
  background: var(--row-bg); overflow: hidden;
}
.reading__bar span { display: block; height: 100%; border-radius: 3px; }

.original-transcript {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-tile);
  background: var(--row-bg); font-size: var(--fs-meta);
}
.original-transcript summary { cursor: pointer; font-weight: 600; color: var(--text-muted); }
.original-transcript p { margin: 8px 0 0; white-space: pre-wrap; }

/* ---- prompt styles (baseline §6) ---- */
.style-card.is-archived { opacity: .62; }
.style-body { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--gap); }
.style-label { font-weight: 700; margin: 0 0 8px; }
.style-points { margin: 0; padding-left: 18px; }
.style-points li { margin-bottom: 5px; font-size: var(--fs-body); }
.style-body > div:first-child {
  background: #FFFBEB; border-left: 3px solid var(--amber-fg);
  border-radius: var(--radius-tile); padding: 14px;
}

/* ---- photo lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 95; display: none;
  background: rgba(15, 23, 42, .88); place-items: center; padding: 24px;
}
.lightbox.is-open { display: grid; }
.lightbox img { max-width: 100%; max-height: 86vh; border-radius: 8px; }
.lightbox__close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: 0; color: #fff; cursor: pointer; padding: 8px;
}
.lightbox__cap { color: #E2E8F0; font-size: var(--fs-meta); margin-top: 10px; text-align: center; }

/* ---- search (PRD §34-35, baseline §7) ---- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.search-form { margin-bottom: var(--gap); }
.search-box {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-pill); padding: 5px 5px 5px 16px; color: var(--text-muted);
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-box input {
  flex: 1; min-width: 0; height: 36px; border: 0; outline: none; background: none;
  font-size: 15px; color: var(--text);
}
.search-box__mic { background: none; border: 0; padding: 6px; cursor: pointer; color: var(--text-muted); }
.search-box .btn { border-radius: var(--radius-pill); flex: none; }
.search-help { font-size: var(--fs-small); color: var(--text-muted); margin: 6px 16px 10px; }
.search-adv {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
}
.search-adv summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 12px 14px;
  font-weight: 600; font-size: var(--fs-body); list-style: none;
}
.search-adv summary::-webkit-details-marker { display: none; }
.search-adv__on {
  font-size: var(--fs-small); font-weight: 600; color: var(--blue-fg);
  background: var(--blue-bg); border-radius: var(--radius-pill); padding: 1px 8px;
}
/* minmax(0, 1fr) and never a bare 1fr — see BUG-008. */
.search-adv__grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0 12px; padding: 0 14px;
}
.search-adv__actions { display: flex; gap: 8px; padding: 0 14px 14px; }
.search-chips { margin-bottom: 12px; }
.search-chips__n {
  display: inline-block; min-width: 18px; margin-left: 4px; padding: 0 5px;
  border-radius: var(--radius-pill); background: var(--row-bg);
  font-size: var(--fs-small); font-weight: 600; color: var(--text-muted); text-align: center;
}
.search-group { margin-bottom: var(--gap); }
.search-group__head { padding: 12px 14px; margin: 0; gap: 10px; align-items: center; }
.search-table td { vertical-align: top; }
.search-hit__date, .search-hit__status, .search-hit__action { white-space: nowrap; }
.search-hit__person, .search-hit__topic { min-width: 90px; }
.search-hit__desc { min-width: 240px; }
.search-hit__title { display: block; font-weight: 600; color: var(--text); }
.search-hit__title:hover { color: var(--primary); }
.search-hit__snip, .search-hit__meta {
  display: block; font-size: var(--fs-meta); color: var(--text-muted); margin-top: 3px;
  overflow-wrap: anywhere;
}
.search-hit__meta:empty { display: none; }
.search-hit mark { background: var(--amber-bg); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---- activity history + change lists (PRD §41) ---- */
.changes { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; }
.changes__item {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px;
  font-size: var(--fs-meta); color: var(--text-muted); min-width: 0;
}
.changes__label { font-weight: 600; color: var(--text); }
.changes__label::after { content: ":"; }
.changes__old { text-decoration: line-through; text-decoration-color: var(--text-faint); }
.changes__old, .changes__new { overflow-wrap: anywhere; min-width: 0; }
.changes__new { color: var(--text); }
.changes__arrow { color: var(--text-faint); }
.changes__more { margin-top: 4px; font-size: var(--fs-meta); }
.changes__more summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.timeline__body { min-width: 0; }
.timeline__all { margin: 4px 0 0; }
.timeline__title, .timeline__detail { overflow-wrap: anywhere; }
.activity-table td { vertical-align: top; }
.activity-row__when, .activity-row__who, .activity-row__action { white-space: nowrap; }
.activity-row__record { min-width: 150px; }
.activity-row__what { min-width: 280px; }
.activity-row__module, .activity-row__project, .activity-row__detail {
  display: block; font-size: var(--fs-small); color: var(--text-muted);
}
.activity-row__link, .activity-row__gone { display: block; font-weight: 600; overflow-wrap: anywhere; }
.activity-row__gone { color: var(--text-muted); }
.activity-row__gone small { font-weight: 400; }
.activity-row__summary { display: block; overflow-wrap: anywhere; }
.activity-row__detail { margin-top: 2px; overflow-wrap: anywhere; }
.activity-row__history { display: inline-block; margin-top: 4px; }
.archived-note { display: flex; align-items: center; gap: 12px; }
.archived-note form { margin-left: auto; }
/* A thumbnail whose file has gone shows a placeholder, not a broken image
   (app.js adds the class on the image's error event). */
.thumb img.is-broken { visibility: hidden; }
.thumb:has(img.is-broken) { background: var(--row-bg); }

/* ======================================================= 5. RESPONSIVE === */
@media (max-width: 1199px) {
  .sidebar { width: var(--sidebar-w-narrow); padding: 10px 8px; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item span { display: none; }
  .app-main { margin-left: var(--sidebar-w-narrow); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-3-cal, .grid-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 767px) {
  .desktop-only { display: none !important; }

  /* .stack-table: a wide table becomes stacked rows. One markup, two layouts —
     a 5-7 column table does not fit a phone, and a sideways-scrolling one hides
     the column that matters. The cell marked __main goes first and full width;
     the rest follow as one wrapping line of small facts. Used by Search and by
     Activity History. */
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody { display: block; }
  .stack-table tbody tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
    padding: 11px 12px; border-bottom: 1px solid var(--card-border);
  }
  .stack-table tbody tr:last-child { border-bottom: 0; }
  .stack-table tbody td {
    display: block; padding: 0; border: 0; min-width: 0;
    font-size: var(--fs-small); color: var(--text-muted); overflow-wrap: anywhere;
  }
  .stack-table tbody td.stack-table__main {
    flex: 1 1 100%; order: -1; margin-bottom: 2px;
    font-size: var(--fs-body); color: var(--text);
  }
  .stack-table .stack-table__hide, .stack-table .is-empty { display: none !important; }

  .search-adv__grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .search-group { padding: 0; }            /* stays flush: the head and rows pad themselves */
  .search-box { padding-left: 12px; }
  .search-box .btn { padding: 0 12px; }
  .activity-row__what, .activity-row__record { min-width: 0; }
  .archived-note { flex-wrap: wrap; }

  .mobile-only { display: block !important; }
  .icon-btn.mobile-only   { display: grid !important; }
  .quick-grid.mobile-only { display: grid !important; }
  .bottom-nav.mobile-only { display: block !important; }

  .app-header { height: auto; padding: 9px 12px; gap: 10px; }
  .brand__name { font-size: 17px; }
  .brand__sub { display: block; font-size: var(--fs-small); color: var(--shell-fg-muted); }
  /* Scoped to the header: the dashboard reuses .header-search for its own
     mobile search pill, which must stay visible. */
  .app-header .header-search { display: none; }

  .sidebar { display: none; }
  .app-main {
    margin-left: 0;
    padding: 66px 12px calc(var(--bottomnav-h) + 22px);
  }
  .bottom-nav { display: block; }

  .card__head { flex-wrap: wrap; }
  .card__action { margin-left: auto; }
  .record { grid-template-columns: minmax(0, 1fr); }
  .record__left { justify-items: start; grid-template-columns: auto auto 1fr; align-items: center; }
  .style-body { grid-template-columns: minmax(0, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid--3 { grid-template-columns: minmax(0, 1fr); }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .page-head { flex-wrap: wrap; }
  .page-head__actions { margin-left: 0; width: 100%; }
  .page-head__actions .btn { flex: 1; }
  .record-head__actions { width: 100%; margin-left: 0; }
  .filters { padding: 10px; }
  .filters__q, .filters__select, .filters__date { flex: 1 1 100%; min-width: 0; }
  .cal-grid td { height: 76px; padding: 3px; }
  .cal-chip { font-size: 9.5px; }
  .file-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .grid-3-cal, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .card { padding: 14px; border-radius: 12px; }
  .thumb-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page-title { font-size: 17px; }
}

/* Touch targets stay >= 44px on coarse pointers (PRD §45). */
@media (pointer: coarse) {
  .btn, .input, .select { min-height: 44px; }
  .list-row { padding: 12px 11px; }
}

@media print {
  .app-header, .sidebar, .bottom-nav { display: none; }
  .app-main { margin: 0; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}
