:root {
  --sm-bg: #f5f1e7;
  --sm-surface: #fffefa;
  --sm-border: #d9d2c4;
  --sm-text: #1f211e;
  --sm-muted: #74736d;
  --sm-red: #c3261c;
  --sm-ink: #171916;
  --sm-good: #2f5a3a;
  --sm-warn: #8a5a12;
  --sm-control: 44px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--sm-bg);
  color: var(--sm-text);
}
body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.suite-header {
  min-height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--sm-border);
  background: rgba(245, 241, 231, .97);
  backdrop-filter: blur(12px);
}
.suite-brand { display: grid; gap: 4px; line-height: 1; min-width: 0; }
.family-control {
  color: var(--sm-red);
  font: 800 10px/1 Inter, sans-serif;
  letter-spacing: .04em;
  text-decoration: none;
  text-transform: uppercase;
}
.family-control:hover { text-decoration: underline; }
.app-home { color: inherit; text-decoration: none; min-width: 0; }
.app-home strong {
  color: var(--sm-text);
  font: 700 18px/1.05 Inter, sans-serif;
}
.suite-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  min-width: 0;
  flex-wrap: wrap;
}
.suite-nav a {
  color: var(--sm-muted);
  font: 500 13px/1 Inter, sans-serif;
  text-decoration: none;
  min-height: var(--sm-control);
  display: inline-flex;
  align-items: center;
}
.suite-nav a:hover, .suite-nav a.current { color: var(--sm-red); }
.suite-nav .date {
  color: var(--sm-muted);
  font-size: 12px;
  text-align: right;
  max-width: 16rem;
  overflow-wrap: anywhere;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px clamp(16px, 3vw, 32px) 56px;
}
.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.tab, .btn, .record, .save-button, .category-choice, .capture-button {
  border: 0;
  border-radius: 9px;
  min-height: var(--sm-control);
  padding: 0 14px;
  font: 700 13px/1 Inter, sans-serif;
  cursor: pointer;
  background: #ece8dc;
  color: var(--sm-text);
}
.tab.active, .btn.primary, .save-button {
  background: var(--sm-ink);
  color: #fff;
}
.btn.danger { background: #f8e4e0; color: #8a241c; }
.btn.good { background: #e4efe6; color: var(--sm-good); }
.record {
  min-width: 96px;
  background: var(--sm-ink);
  color: #fff;
}
.record.running { background: var(--sm-red); }

.cloud-strip, .panel {
  background: var(--sm-surface);
  border: 1px solid var(--sm-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.cloud-strip {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { min-width: 0; }
.grow { flex: 1 1 180px; }
.field, textarea.field, select.field {
  width: 100%;
  min-height: var(--sm-control);
  border: 1px solid var(--sm-border);
  border-radius: 9px;
  padding: 0 12px;
  background: #f8f5ee;
}
textarea.field {
  min-height: 76px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}
.field:focus, textarea.field:focus, select.field:focus {
  outline: 2px solid rgba(195, 38, 28, .25);
  outline-offset: 1px;
  border-color: var(--sm-red);
}
.grid { display: grid; gap: 10px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.eyebrow {
  margin: 0 0 4px;
  color: var(--sm-muted);
  font: 800 10px/1 Inter, sans-serif;
  letter-spacing: .04em;
  text-transform: uppercase;
}
h1, h2, h3 {
  margin: 0;
  font: 700 16px/1.15 Inter, sans-serif;
  letter-spacing: -.02em;
}
.muted, .note, .date, .meta, .status, .library-subtitle { color: var(--sm-muted); }
.note, .status, .meta { font-size: 12px; line-height: 1.4; margin: 0; }
.status { margin-top: 2px; }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a3a3a3;
  margin-right: 6px;
}
.dot.ok { background: var(--sm-good); }
.dot.warn { background: var(--sm-warn); }

.timer-board {
  display: grid;
  gap: 12px;
}
.timer-ops, .history-panel { min-width: 0; }
.timer-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px 16px;
  align-items: center;
}
.timer-copy { min-width: 0; }
.activity {
  margin: 0;
  font: 600 15px/1.25 Inter, sans-serif;
  overflow-wrap: anywhere;
}
.timer {
  margin: 0;
  font: 700 28px/1 Inter, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}
.activity-fields { grid-column: 1 / -1; }
.category-strip .toolbar { margin-top: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.category-choice { flex: 1 1 96px; }
.category-choice[data-category="stolen"] { background: #f8e4e0; color: #8a241c; }
.category-choice[data-category="claimed"] { background: #e4efe6; color: var(--sm-good); }
.category-choice[data-category="neutral"] { background: #ece8dc; }

.history-head, .week-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.metric, .history-head strong, .week-head strong {
  font: 700 15px/1 Inter, sans-serif;
  font-variant-numeric: tabular-nums;
}
.list { display: grid; gap: 0; }
.item {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--sm-border);
  border-radius: 0;
  padding: 8px 0;
}
.item:last-child { border-bottom: 0; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--sm-muted); padding: 12px 0; font-size: 13px; }

.week-strip .row { margin-top: 8px; }
.week-plan-label { display: block; margin-top: 8px; }

.capture-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.capture-button {
  min-height: 48px;
  height: 48px;
  padding: 0 10px;
  color: #fff;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: none;
}
.capture-button span { font: 700 13px/1 Inter, sans-serif; }
.capture-button small {
  font: 500 11px/1.2 Inter, sans-serif;
  opacity: .85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.capture-button.glucose { background: var(--sm-red); }
.capture-button.food { background: var(--sm-good); }
.capture-button.event-capture { background: #3f3f46; }
.capture-status {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 9px;
  background: #ece8dc;
  font-size: 12px;
  line-height: 1.4;
}
.capture-status.ok { background: #e4efe6; color: var(--sm-good); }
.capture-status.warn { background: #f8ecd2; color: var(--sm-warn); }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.summary-box {
  background: #f3eee4;
  border-radius: 9px;
  padding: 10px;
  display: grid;
  gap: 4px;
  min-width: 0;
}
.summary-box strong { font-size: 16px; overflow-wrap: anywhere; }
.summary-box span { font-size: 11px; color: var(--sm-muted); }
.warning-card { border-color: #d5a59e; background: #fff8f6; }
.compact-actions { justify-content: flex-end; }
.fragment-body {
  white-space: pre-wrap;
  line-height: 1.4;
  max-height: 6.5em;
  overflow: hidden;
  font-size: 13px;
}
.suggestions { display: flex; gap: 6px; flex-wrap: wrap; }
.suggestions button {
  border: 1px solid var(--sm-border);
  background: var(--sm-surface);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 10px;
  cursor: pointer;
}
.food-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px 88px auto;
  gap: 8px;
  align-items: center;
}
.event {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}
.event-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #ece8dc;
  display: grid;
  place-items: center;
  font: 700 12px/1 Inter, sans-serif;
}
.pill {
  display: inline-block;
  border-radius: 999px;
  background: #ece8dc;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  margin: 4px 4px 0 0;
}
.suite-footer {
  padding: 8px 16px 28px;
  color: var(--sm-muted);
  text-align: center;
  font-size: 12px;
}

dialog {
  width: min(560px, calc(100% - 24px));
  max-width: calc(100vw - 24px);
  border: 0;
  border-radius: 12px;
  padding: 16px;
  background: var(--sm-surface);
  color: var(--sm-text);
}
dialog::backdrop { background: rgba(31, 33, 30, .45); }

/* Viewport gates: 390×844, 768×1024, 820×1180, 1024×768, 1180×820, 1440×900 */
@media (max-width: 820px) {
  .suite-header { min-height: 58px; padding-left: 14px; padding-right: 14px; }
  .app { padding: 12px 14px 48px; }
  .timer-strip { grid-template-columns: minmax(0, 1fr) auto; }
  .timer-copy { grid-column: 1; grid-row: 1; }
  .timer { grid-column: 1; grid-row: 2; }
  .timer-strip .record { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .capture-button small { display: none; }
  .food-row { grid-template-columns: minmax(0, 1fr) 80px; }
  .food-row .food-carbs { grid-column: 1; }
  .event { grid-template-columns: 36px minmax(0, 1fr); }
  .event-actions { grid-column: 2; }
  .grid.two, .grid.three { grid-template-columns: minmax(0, 1fr); }
  .summary-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 390px) {
  .suite-nav .date { max-width: 9.5rem; }
  .tabs { gap: 6px; }
  .tab { padding: 0 6px; font-size: 12px; }
  .timer-strip { grid-template-columns: minmax(0, 1fr); }
  .timer-copy, .timer, .timer-strip .record { grid-column: 1; grid-row: auto; }
  .timer-strip .record { width: 100%; }
  .timer { font-size: 24px; }
  .capture-actions { grid-template-columns: minmax(0, 1fr); }
  .compact-actions { flex-direction: column; align-items: stretch; }
  .compact-actions .btn { width: 100%; }
}

@media (min-width: 1024px) {
  .timer-board {
    grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
    align-items: start;
  }
  .timer-strip { grid-template-columns: minmax(0, 1fr); }
  .timer-copy, .timer, .timer-strip .record { grid-column: 1; grid-row: auto; }
  .timer-strip .record { width: 100%; }
}

@media (min-width: 1180px) {
  .app { width: min(1180px, 100%); }
}

@media (min-width: 1440px) {
  .app { width: min(1120px, 100%); }
}
