:root {
  color-scheme: light;
  --ink: #17201f;
  --muted: #687370;
  --paper: #f4f1e9;
  --card: #fffdf8;
  --line: #d8ddd7;
  --forest: #142f2b;
  --forest-soft: #dce8e3;
  --orange-soft: #fbe8d5;
  --danger: #a33a35;
  --shadow: 0 16px 45px rgba(20, 47, 43, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 85% 0, #e4ece5 0, transparent 34rem), var(--paper); }
button, input, select, textarea { font: inherit; }
button, label, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-header {
  position: sticky; top: 0; z-index: 20; min-height: 68px;
  padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: rgba(244, 241, 233, .9); border-bottom: 1px solid rgba(20, 47, 43, .1); backdrop-filter: blur(18px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--forest); text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: var(--paper); background: var(--forest); font-weight: 800; }
.brand strong, .brand small { display: block; line-height: 1; }
.brand strong { font-size: 17px; letter-spacing: .08em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.68); font-size: 12px; }
.status-pill::before { width: 7px; height: 7px; border-radius: 50%; background: #b47b3d; content: ""; }
.status-pill.online::before { background: #2b8c64; }
.status-pill.offline::before { background: var(--danger); }
.text-button { padding: 8px 4px; border: 0; color: var(--forest); background: transparent; font-weight: 700; }

.page-shell { width: min(100%, 1120px); margin: 0 auto; padding: 28px 18px max(60px, env(safe-area-inset-bottom)); }
.login-screen { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.login-card { width: min(100%, 640px); padding: clamp(28px, 6vw, 56px); border: 1px solid rgba(20,47,43,.12); border-radius: 30px; background: rgba(255,253,248,.92); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 10px; color: #7d4d25; font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; max-width: 18ch; color: var(--forest); font-size: clamp(34px, 7vw, 62px); line-height: 1.02; letter-spacing: -.045em; }
h2 { margin: 0; color: var(--forest); font-size: clamp(23px, 4vw, 34px); letter-spacing: -.025em; }
h3 { margin: 0; color: var(--forest); font-size: 18px; }
.lead { margin: 20px 0 0; max-width: 52ch; color: var(--muted); font-size: 17px; line-height: 1.6; }
.muted { color: var(--muted); }
.login-form { margin-top: 34px; }
label { display: block; margin-bottom: 7px; color: #40514e; font-size: 13px; font-weight: 750; }
.input-action { display: flex; gap: 10px; }
input, select, textarea { width: 100%; min-height: 46px; padding: 11px 13px; border: 1px solid #cbd3ce; border-radius: 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #3b766b; box-shadow: 0 0 0 3px rgba(59,118,107,.14); }
input:disabled, select:disabled { color: #79817f; background: #eff0ec; }
textarea { min-height: 100px; resize: vertical; }
.primary-button, .secondary-button, .danger-button { min-height: 46px; padding: 11px 17px; border-radius: 12px; border: 1px solid transparent; font-weight: 800; white-space: nowrap; }
.primary-button { color: #fff; background: var(--forest); box-shadow: 0 8px 20px rgba(20,47,43,.15); }
.primary-button:hover { background: #20463f; }
.secondary-button { color: var(--forest); border-color: #aebdb7; background: transparent; }
.danger-button { color: var(--danger); border-color: #e0b4b0; background: #fff7f6; }
button:disabled { cursor: wait; opacity: .55; }
.form-message { min-height: 20px; margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.feature-row { margin-top: 30px; display: flex; flex-wrap: wrap; gap: 8px; }
.feature-row span, .chip { padding: 7px 10px; border-radius: 999px; color: #40514e; background: var(--forest-soft); font-size: 12px; font-weight: 700; }

.workspace-intro { display: grid; grid-template-columns: 1.1fr .9fr; gap: 28px; align-items: end; padding: 38px 0; }
.workspace-intro h1 { font-size: clamp(30px, 5vw, 52px); }
.search-card, .overview-card { padding: 22px; border: 1px solid rgba(20,47,43,.12); border-radius: 20px; background: var(--card); box-shadow: 0 10px 28px rgba(20,47,43,.06); }
.screen-toolbar { margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.store-hero { padding: clamp(22px, 4vw, 34px); border-radius: 24px; color: #f7f7f2; background: var(--forest); }
.store-hero .eyebrow { color: #f1b781; }
.store-hero h1 { max-width: none; color: #fff; font-size: clamp(30px, 5vw, 46px); }
.store-address { margin: 13px 0 0; color: #cad8d3; line-height: 1.55; }
.source-warning { margin-top: 16px; padding: 12px 14px; border-radius: 12px; color: #5c3718; background: var(--orange-soft); font-size: 13px; }
.safety-note { margin: 14px 0; padding: 13px 15px; border: 1px solid #c9d7d1; border-radius: 14px; color: #40514e; background: #edf4f0; font-size: 13px; line-height: 1.5; }

.overview-card { margin-bottom: 16px; }
.overview-heading { margin-bottom: 17px; display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.overview-heading h2 { font-size: 22px; }
.overview-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.summary-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.metric { padding: 14px; border-radius: 15px; background: #eef1ec; }
.metric strong, .metric span { display: block; }
.metric strong { color: var(--forest); font-size: 22px; }
.metric span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.workflow-stack { display: grid; gap: 12px; }
.workflow-section { overflow: hidden; border: 1px solid #d1d9d4; border-radius: 18px; background: var(--card); box-shadow: 0 8px 24px rgba(20,47,43,.045); }
.workflow-section > summary { min-height: 78px; padding: 16px 19px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 14px; list-style: none; cursor: pointer; }
.workflow-section > summary::-webkit-details-marker { display: none; }
.workflow-section > summary::after { content: "+"; color: var(--forest); font-size: 24px; line-height: 1; }
.workflow-section[open] > summary::after { content: "−"; }
.step-number { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--forest); background: var(--forest-soft); font-size: 11px; font-weight: 850; letter-spacing: .08em; }
.workflow-title strong, .workflow-title small { display: block; }
.workflow-title strong { color: var(--forest); font-size: 17px; }
.workflow-title small { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.workflow-badge { padding: 6px 9px; border-radius: 999px; color: #40514e; background: #edf0ec; font-size: 11px; font-weight: 750; }
.workflow-body { padding: 0 19px 20px; border-top: 1px solid #e3e7e3; }
.subsection { padding: 20px 0; }
.subsection + .subsection { border-top: 1px solid #e3e7e3; }
.subsection-heading { margin-bottom: 15px; }
.subsection-heading h3 { font-size: 17px; }
.subsection-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.field-grid, .component-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-grid .wide, .component-fields .wide { grid-column: 1 / -1; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: block; padding: 10px 13px; border: 1px solid #cbd3ce; border-radius: 12px; background: #fff; font-size: 13px; font-weight: 700; }
.choice input:checked + span { color: #fff; border-color: var(--forest); background: var(--forest); }
.source-value { display: block; min-height: 17px; margin: 5px 2px 0; color: var(--muted); font-size: 11px; }

.device-list { display: grid; gap: 10px; padding-top: 18px; }
.device-group { overflow: hidden; border: 1px solid #d4dbd6; border-radius: 18px; background: #fff; }
.device-group > summary { padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; list-style: none; cursor: pointer; }
.device-group > summary::-webkit-details-marker { display: none; }
.device-group > summary::after { content: "+"; color: var(--forest); font-size: 22px; line-height: 1; }
.device-group[open] > summary::after { content: "−"; }
.group-title small { display: block; margin-top: 4px; color: var(--muted); font-weight: 500; }
.group-body { padding: 0 18px 18px; border-top: 1px solid #e4e8e4; }
.group-fields { padding: 0 0 17px; }
.summary-status { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.summary-status > span { padding: 5px 8px; border-radius: 999px; color: #59625f; background: #f0f2ef; font-size: 10px; font-weight: 700; }
.data-state { padding: 5px 8px; border-radius: 999px; color: #6b5a42; background: #f4ecdf; font-size: 10px; font-weight: 800; white-space: nowrap; }
.data-state.unchanged { color: #37624f; background: #e4eee8; }
.data-state.changed { color: #75451d; background: var(--orange-soft); }
.change-guidance { margin: 17px 0 14px; padding: 10px 12px; border-radius: 11px; color: #5c6662; background: #f0f2ef; font-size: 12px; }
.change-guidance.editing { color: #6b421f; background: var(--orange-soft); }

.component-list { display: grid; gap: 11px; }
.component-card { overflow: hidden; border: 1px solid #dfe4df; border-radius: 15px; background: #fafaf7; }
.component-summary { padding: 14px 15px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; list-style: none; cursor: pointer; }
.component-summary::-webkit-details-marker { display: none; }
.component-summary::after { content: "+"; color: var(--forest); font-size: 20px; line-height: 1; }
.component-card[open] > .component-summary::after { content: "−"; }
.component-body { padding: 15px; border-top: 1px solid #e0e5e0; }
.component-meta { color: var(--muted); font-size: 11px; }
.component-source { margin: 0 0 14px; color: var(--muted); font-size: 11px; }
.change-panel { margin-top: 14px; padding: 14px; border: 1px solid #d8ddd8; border-radius: 13px; }
.change-panel.locked { background: #f0f1ee; }
.change-panel.editing { border-color: #e2b88f; background: #fff9f3; }
.change-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.change-panel-heading span { color: var(--muted); font-size: 11px; font-weight: 750; }
.change-panel > p { margin: 5px 0 13px; color: var(--muted); font-size: 12px; }
.observation-notes { margin-top: 14px; }
.top-actions { margin: 0 0 14px; }
.inline-actions { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 9px; }
.upload-button { position: relative; overflow: hidden; }
.upload-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.evidence-list { display: grid; gap: 6px; margin-top: 10px; }
.evidence-item { padding: 9px 11px; display: flex; justify-content: space-between; gap: 10px; border-radius: 10px; background: var(--forest-soft); font-size: 12px; }
.sync-actions { position: sticky; bottom: 12px; z-index: 10; margin-top: 14px; padding: 12px; display: flex; justify-content: flex-end; gap: 9px; border: 1px solid rgba(20,47,43,.13); border-radius: 17px; background: rgba(255,253,248,.94); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 32px), 520px); padding: 13px 16px; border-radius: 13px; color: #fff; background: var(--forest); box-shadow: var(--shadow); text-align: center; }

@media (max-width: 860px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-header { min-height: 62px; }
  .status-pill { max-width: 112px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-shell { padding-top: 18px; }
  .login-card { border-radius: 22px; }
  .input-action { flex-direction: column; }
  .workspace-intro { grid-template-columns: 1fr; padding-top: 24px; }
  .field-grid, .component-fields { grid-template-columns: 1fr; }
  .field-grid .wide, .component-fields .wide { grid-column: auto; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .workflow-section > summary { min-height: 72px; padding: 14px; grid-template-columns: auto minmax(0, 1fr); gap: 10px; }
  .workflow-section > summary::after { display: none; }
  .workflow-badge { grid-column: 2; justify-self: start; }
  .workflow-body { padding: 0 14px 16px; }
  .device-group > summary { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .device-group > summary::after { display: none; }
  .summary-status { justify-content: flex-start; }
  .group-body { padding: 0 14px 14px; }
  .component-summary { grid-template-columns: minmax(0, 1fr) auto; }
  .component-summary::after { display: none; }
  .sync-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .sync-actions .primary-button { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
