:root {
  color-scheme: light;
  --canvas: #f3f5f4;
  --surface: #ffffff;
  --ink: #18211f;
  --muted: #68736f;
  --line: #d7dfdc;
  --line-strong: #b8c7c2;
  --primary: #087f74;
  --primary-hover: #06685f;
  --primary-soft: #e6f4f1;
  --warm: #b35d22;
  --warm-soft: #fff3e8;
  --dark: #26312e;
  --danger: #a33c3c;
  --danger-soft: #fff0ef;
  --shadow: 0 12px 32px rgba(26, 47, 42, 0.08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
input, textarea { color: var(--ink); }

.app-header { border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.96); }
.header-inner { width: min(1180px, 100%); min-height: 74px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 22px 12px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { flex: 0 0 42px; border-radius: 8px; }
.brand h1 { font-size: 20px; line-height: 1.25; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 750; }
.device-status, .retention-badge, .history-hit { display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.device-status span { width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #2f9a68; }

.workspace { width: min(1180px, 100%); margin: 0 auto; padding: 28px 22px max(42px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 22px; align-items: start; }
.workflow-panel, .history-panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.workflow-panel { min-width: 0; padding: 28px; }
.history-panel { position: sticky; top: 22px; padding: 24px; }
.panel-heading, .history-heading, .result-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-heading { padding-bottom: 24px; }
.panel-heading h2, .history-heading h2 { margin-top: 3px; font-size: 24px; line-height: 1.3; }

.workflow-step { padding: 23px 0; border-top: 1px solid var(--line); }
.step-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-heading label { font-size: 15px; font-weight: 750; }
.step-number { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 13px; font-weight: 800; }
.step-number-warm { background: var(--warm-soft); color: var(--warm); }
.input-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
input, textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
input { min-height: 52px; padding: 0 14px; }
textarea { min-height: 190px; padding: 14px; resize: vertical; line-height: 1.65; }
input::placeholder, textarea::placeholder { color: #8a9692; }
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid rgba(8, 127, 116, 0.2); outline-offset: 2px; border-color: var(--primary); }

.button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 16px; border: 1px solid transparent; border-radius: 6px; font-weight: 750; }
.button:hover { filter: brightness(0.98); }
.button:disabled { cursor: wait; opacity: 0.62; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-hover); }
.button-dark { background: var(--dark); color: #fff; }
.button-secondary { border-color: var(--line); background: #fff; color: var(--dark); }
.button-full { width: 100%; margin-top: 10px; }
.compact-button { min-width: 104px; }
.icon { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--danger); }

.feedback { margin-top: 18px; padding: 12px 14px; border: 1px solid #bddfd7; border-radius: 6px; background: var(--primary-soft); color: #075f57; }
.feedback.error { border-color: #efc1bd; background: var(--danger-soft); color: var(--danger); }
.feedback.success { border-color: #b9ddca; background: #eaf6ef; color: #216c49; }

.message-result { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.result-heading { margin-bottom: 14px; }
.result-heading h3 { margin-top: 3px; font-size: 20px; }
.history-hit { border-color: #eed5bc; background: var(--warm-soft); color: var(--warm); }
.result-actions { margin-top: 11px; display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 9px; }

.settings { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.settings summary { min-height: 42px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 700; cursor: pointer; }
.settings-form { display: grid; gap: 10px; padding-top: 14px; }
.settings-form label { margin-top: 4px; font-size: 13px; font-weight: 750; }
.settings-actions { display: flex; gap: 9px; margin-top: 3px; }

.search-field { height: 48px; margin: 20px 0 6px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--muted); }
.search-field:focus-within { outline: 3px solid rgba(8, 127, 116, 0.2); border-color: var(--primary); }
.search-field input { min-height: 0; padding: 0; border: 0; outline: 0; }
.history-list { margin: 0; padding: 0; list-style: none; }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 15px 0; border-top: 1px solid var(--line); }
.history-open { min-width: 0; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.history-order { display: block; overflow-wrap: anywhere; font-weight: 800; }
.history-code { display: block; margin-top: 3px; overflow-wrap: anywhere; color: var(--primary-hover); font: 700 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }
.history-time { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.history-copy { width: 40px; height: 40px; align-self: center; }
.empty-state { padding: 42px 0 24px; color: var(--muted); text-align: center; font-size: 14px; }
.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; }
[hidden] { display: none !important; }

@media (max-width: 840px) {
  .workspace { grid-template-columns: 1fr; }
  .history-panel { position: static; }
}

@media (max-width: 580px) {
  .header-inner { min-height: 68px; padding-left: 16px; padding-right: 16px; }
  .device-status { width: 9px; min-height: 9px; padding: 0; border: 0; overflow: hidden; color: transparent; }
  .device-status span { width: 9px; height: 9px; margin: 0; }
  .workspace { padding: 16px 12px max(28px, env(safe-area-inset-bottom)); gap: 14px; }
  .workflow-panel, .history-panel { padding: 20px 16px; }
  .panel-heading h2, .history-heading h2 { font-size: 21px; }
  .retention-badge { display: none; }
  .input-actions { grid-template-columns: minmax(0, 1fr) 92px; }
  .compact-button { min-width: 0; padding: 0 12px; }
  .result-actions { grid-template-columns: 1fr; }
  .settings-actions { display: grid; grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
