/* MKT-09 Hermes Unified App — styles
   Tokens per DESIGN.md + operator directive: orange #F28725, navy #0F172A.
   Light default, dark via [data-theme="dark"], persisted to localStorage 'epix-theme'. */

:root {
  --color-primary: #0F172A;      /* navy — headers, primary text accents */
  --color-accent: #F28725;       /* orange — CTAs, active states */
  --color-accent-hover: #DA771F;
  --color-success: #28a745;
  --color-warning: #e67e00;
  --color-error: #dc3545;
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #e2e6ea;
  --color-text: #1a1a2e;
  --color-text-muted: #6b7280;
  --color-field-bg: #ffffff;
  --shadow-card: 0 8px 28px rgba(15, 23, 42, 0.07);
  --radius: 12px;
  --font-head: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --color-primary: #1f3b61;
  --color-bg: #0a1018;
  --color-surface: #0f1923;
  --color-border: #2a3a4a;
  --color-text: #ffffff;
  --color-text-muted: #a0aab4;
  --color-field-bg: #0a1220;
  --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* The hidden attribute always wins, even over display:flex/grid rules */
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; border-radius: 4px; }

/* ============ Header ============ */
.app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 10;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; object-fit: contain; }
.brand-mark-text { font-weight: 800; font-size: 13px; letter-spacing: 0.18em; color: var(--color-accent); }
.brand-title { font-family: var(--font-head); font-weight: 700; font-size: 18px; color: var(--color-text); }

.header-nav { display: flex; gap: 4px; margin-left: 8px; }
.nav-tab {
  border: 0; background: transparent; color: var(--color-text-muted);
  font: 500 14px var(--font-body); padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.nav-tab:hover { color: var(--color-text); }
.nav-tab.active { background: var(--color-accent); color: #fff; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 13px; color: var(--color-text-muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); width: 34px; height: 34px; border-radius: 999px; cursor: pointer; font-size: 16px; line-height: 1; }
.icon-btn:hover { border-color: var(--color-accent); }
.link-btn { border: 0; background: transparent; color: var(--color-accent); font: 500 13px var(--font-body); cursor: pointer; padding: 4px 6px; }
.link-btn:hover { text-decoration: underline; }

/* ============ Layout ============ */
.app-main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }
.screen[hidden] { display: none; }
.app-footer { text-align: center; font-size: 12px; color: var(--color-text-muted); padding: 16px; }

.section-title { font-family: var(--font-head); font-weight: 600; font-size: 20px; margin: 0 0 8px; color: var(--color-text); }
.help-text { color: var(--color-text-muted); font-size: 14px; margin: 0 0 20px; }
.hint { color: var(--color-text-muted); font-size: 12px; margin: 10px 0 0; }

/* ============ Login ============ */
.login-card {
  max-width: 380px; margin: 8vh auto 0; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 32px 28px; box-shadow: var(--shadow-card); text-align: center;
}
.login-logo { max-width: 110px; margin: 0 auto 8px; display: block; }
.login-logo-text { font-weight: 800; font-size: 22px; letter-spacing: 0.2em; color: var(--color-accent); margin-bottom: 8px; }
.login-title { font-family: var(--font-head); font-size: 24px; margin: 0 0 4px; }
.login-sub { color: var(--color-text-muted); font-size: 14px; margin: 0 0 24px; }
#login-form { text-align: left; }

/* ============ Fields ============ */
.field { display: flex; flex-direction: column; font-size: 13px; color: var(--color-text-muted); margin-bottom: 14px; }
.field > span, .field legend { margin-bottom: 4px; font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 11px 12px; border: 1px solid var(--color-border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: var(--color-field-bg); color: var(--color-text);
  transition: border-color 0.15s; min-height: 44px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 0; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(242, 135, 37, 0.18);
}
.field textarea { resize: vertical; min-height: 64px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.form-grid .field.full, .form-grid fieldset.full { grid-column: 1 / -1; }
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; margin-right: 18px; cursor: pointer; font-size: 14px; color: var(--color-text); min-height: 44px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 22px; border: 0; border-radius: var(--radius);
  font: 600 14px var(--font-body); cursor: pointer; text-decoration: none;
  min-height: 44px; transition: background 0.15s, opacity 0.15s;
}
.btn.primary { background: var(--color-accent); color: #fff; }
.btn.primary:hover { background: var(--color-accent-hover); }
.btn.secondary { background: var(--color-primary); color: #fff; }
.btn.secondary:hover { opacity: 0.9; }
.btn.ghost { background: transparent; color: var(--color-text-muted); border: 1px solid var(--color-border); }
.btn.ghost:hover { color: var(--color-text); border-color: var(--color-text-muted); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ============ Mode toggle ============ */
.mode-card { margin-bottom: 18px; }
.mode-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  border: 0; padding: 0; margin: 0;
}
.mode-option { position: relative; display: block; cursor: pointer; }
.mode-option input { position: absolute; opacity: 0; inset: 0; }
.mode-body {
  display: flex; flex-direction: column; gap: 2px; height: 100%;
  background: var(--color-surface); border: 2px solid var(--color-border);
  border-radius: var(--radius); padding: 14px 16px; transition: border-color 0.15s;
}
.mode-option input:checked + .mode-body { border-color: var(--color-accent); background: rgba(242, 135, 37, 0.06); }
.mode-option input:focus-visible + .mode-body { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.mode-option.disabled { opacity: 0.55; cursor: not-allowed; }
.mode-name { font-weight: 600; font-size: 15px; color: var(--color-text); }
.mode-desc { font-size: 12.5px; color: var(--color-text-muted); line-height: 1.35; }
.mode-note { font-size: 12.5px; color: var(--color-warning); margin: 8px 2px 0; }

/* ============ Input tabs ============ */
.input-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.input-tab {
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted);
  font: 600 14px var(--font-body); padding: 10px 18px; border-radius: 999px; cursor: pointer; min-height: 44px;
}
.input-tab.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.panel[hidden] { display: none; }

/* ============ Wizard ============ */
.wizard-card, .voice-card, .progress-card, .result-card, .history-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-card);
}
.wizard-head { margin-bottom: 18px; }
.wizard-progress { width: 100%; height: 5px; appearance: none; border: 0; background: var(--color-border); border-radius: 3px; }
.wizard-progress::-webkit-progress-bar { background: var(--color-border); border-radius: 3px; }
.wizard-progress::-webkit-progress-value { background: var(--color-accent); border-radius: 3px; transition: all 0.3s; }
.wizard-progress::-moz-progress-bar { background: var(--color-accent); border-radius: 3px; }
.wizard-step-label { font-size: 12px; color: var(--color-text-muted); margin-top: 6px; }
.wizard-step-label span { color: var(--color-accent); font-weight: 600; }
.wizard-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--color-border); }
.wizard-footer .btn.primary { margin-left: auto; }

.budget-warn {
  background: rgba(230, 126, 0, 0.12); color: var(--color-warning);
  padding: 12px 14px; border-radius: var(--radius); font-size: 13px; margin-top: 4px; line-height: 1.4; grid-column: 1 / -1;
}
.budget-warn[hidden] { display: none; }

.form-error, .notice {
  padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 14px; line-height: 1.45;
}
.form-error { background: rgba(220, 53, 69, 0.1); color: var(--color-error); }
.notice.info { background: rgba(31, 59, 97, 0.08); color: var(--color-text); border: 1px solid var(--color-border); }
[data-theme="dark"] .notice.info { background: rgba(255,255,255,0.06); }
.notice.warn { background: rgba(230, 126, 0, 0.12); color: var(--color-warning); }
.notice.error { background: rgba(220, 53, 69, 0.1); color: var(--color-error); }
.notice.error .btn { margin-top: 10px; }
.notice[hidden] { display: none; }

/* ============ Voice ============ */
.voice-recorder { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.record-btn {
  display: inline-flex; align-items: center; gap: 10px;
  border: 2px solid var(--color-accent); background: transparent; color: var(--color-text);
  font: 600 14px var(--font-body); padding: 12px 20px; border-radius: 999px; cursor: pointer; min-height: 48px;
}
.record-btn .record-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--color-error); }
.record-btn.recording { background: rgba(220, 53, 69, 0.1); border-color: var(--color-error); }
.record-btn.recording .record-dot { animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.record-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--color-error); font-size: 16px; }
.voice-divider { display: flex; align-items: center; gap: 12px; color: var(--color-text-muted); font-size: 12px; margin: 14px 0; }
.voice-divider::before, .voice-divider::after { content: ''; flex: 1; height: 1px; background: var(--color-border); }
.voice-preview { display: flex; align-items: center; gap: 12px; margin: 10px 0 16px; flex-wrap: wrap; }
.voice-preview audio { max-width: 100%; }

/* ============ Progress stepper ============ */
.stepper { list-style: none; display: flex; padding: 0; margin: 20px 0 18px; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.step::before {
  content: ''; position: absolute; top: 9px; left: -50%; width: 100%; height: 2px;
  background: var(--color-border); z-index: 0;
}
.step:first-child::before { display: none; }
.step-dot {
  width: 20px; height: 20px; border-radius: 50%; background: var(--color-surface);
  border: 2px solid var(--color-border); z-index: 1; transition: all 0.25s;
}
.step-label { font-size: 12px; color: var(--color-text-muted); }
.step.done .step-dot { background: var(--color-success); border-color: var(--color-success); }
.step.done::before { background: var(--color-success); }
.step.active .step-dot { border-color: var(--color-accent); background: var(--color-accent); box-shadow: 0 0 0 4px rgba(242, 135, 37, 0.25); animation: pulse 1.4s infinite; }
.step.active .step-label { color: var(--color-accent); font-weight: 600; }
.step.done .step-label { color: var(--color-text); }
.step[hidden] { display: none; }

.progress-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.stage-text { font-size: 14px; color: var(--color-text); }
.elapsed { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--color-text-muted); }
.progress-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.estimate-id-chip { font-size: 12px; color: var(--color-text-muted); background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 999px; padding: 4px 12px; }

/* ============ Result ============ */
.result-head { display: flex; align-items: center; gap: 12px; }
.badge { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 4px 12px; }
.badge.success { background: rgba(40, 167, 69, 0.14); color: var(--color-success); }
.result-client { color: var(--color-text-muted); font-size: 14px; margin: 2px 0 18px; }
.boq-summary { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 6px 18px; margin-bottom: 20px; }
.boq-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--color-border); font-size: 14px; color: var(--color-text-muted); }
.boq-row:last-child { border-bottom: 0; }
.boq-row strong { color: var(--color-text); font-variant-numeric: tabular-nums; }
.boq-row.grand { font-size: 16px; }
.boq-row.grand strong { color: var(--color-accent); font-family: var(--font-head); font-size: 20px; }
.cta-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.result-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ============ History ============ */
.history-list { list-style: none; margin: 0; padding: 0; }
.history-item {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; border-bottom: 1px solid var(--color-border);
  padding: 14px 4px; cursor: pointer; font-family: inherit; color: var(--color-text);
}
.history-item:hover { background: rgba(242, 135, 37, 0.05); }
.history-item .h-mode { font-size: 18px; }
.history-item .h-main { flex: 1; min-width: 0; }
.history-item .h-client { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .h-sub { font-size: 12px; color: var(--color-text-muted); }
.history-item .h-status { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; }
.h-status.complete { background: rgba(40, 167, 69, 0.14); color: var(--color-success); }
.h-status.processing { background: rgba(242, 135, 37, 0.14); color: var(--color-accent); }
.h-status.error, .h-status.hold { background: rgba(220, 53, 69, 0.12); color: var(--color-error); }
.empty-state { color: var(--color-text-muted); font-size: 14px; text-align: center; padding: 24px 0; }

/* ============ Responsive: 390px target ============ */
@media (max-width: 640px) {
  .app-header { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .header-nav { order: 3; width: 100%; margin-left: 0; }
  .user-chip { display: none; }
  .app-main { padding: 16px 10px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .mode-toggle { grid-template-columns: 1fr; }
  .wizard-card, .voice-card, .progress-card, .result-card, .history-card { padding: 18px 14px; }
  .step-label { font-size: 10.5px; }
  .cta-row .btn { flex: 1; }
  .result-foot { flex-direction: column; align-items: stretch; }
  .result-foot .btn { width: 100%; }
}
