:root {
  --ivory: #fffff0;
  --paper: #fffaf0;
  --white: #ffffff;
  --anthracite: #383838;
  --ink: #202020;
  --muted: #6d6a65;
  --cobalt: #0047ab;
  --pine: #2e8b57;
  --garnet: #800020;
  --line: rgba(56, 56, 56, 0.16);
  --soft-line: rgba(56, 56, 56, 0.09);
  --shadow: 0 16px 42px rgba(35, 35, 35, 0.1);
  --focus: 0 0 0 4px rgba(0, 71, 171, 0.18);
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(179, 139, 109, 0.17), transparent 27rem),
    radial-gradient(circle at 100% 100%, rgba(0, 71, 171, 0.08), transparent 32rem),
    var(--ivory);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: var(--white); padding: 0.7rem 1rem; border-radius: 0.6rem; }
.skip-link:focus { top: 1rem; }

.app-header {
  padding: max(1.2rem, env(safe-area-inset-top)) max(1.2rem, env(safe-area-inset-right)) 1.6rem max(1.2rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 240, 0.92);
  backdrop-filter: blur(14px);
}
.back-link { display: inline-block; margin-bottom: 1rem; color: var(--cobalt); font-weight: 750; text-decoration: none; }
.brand-block { display: flex; align-items: center; gap: 1rem; max-width: 1180px; margin: auto; }
.brand-block img { flex: 0 0 auto; }
.brand-block h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1; letter-spacing: -0.035em; }
.brand-block p:not(.eyebrow) { margin: 0.5rem 0 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.15rem); }
.eyebrow, .step-label { margin: 0 0 0.25rem; color: var(--garnet); font-size: 0.76rem; font-weight: 850; letter-spacing: 0.11em; text-transform: uppercase; }
.header-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.75rem; max-width: 1180px; margin: 1rem auto 0; }
.status-dot { color: var(--muted); font-size: 0.88rem; }
.status-dot::before { content: ""; display: inline-block; width: 0.55rem; height: 0.55rem; margin-right: 0.45rem; border-radius: 50%; background: #c78f00; }
.status-dot.online::before { background: var(--pine); }
.status-dot.offline::before { background: var(--garnet); }

.layout { display: grid; grid-template-columns: 280px minmax(0, 860px); gap: 1.5rem; max-width: 1180px; margin: 1.5rem auto 3rem; padding: 0 1.2rem; align-items: start; }
.history-panel, .card { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.9); box-shadow: var(--shadow); }
.history-panel { position: sticky; top: 1.2rem; border-radius: 1.2rem; padding: 1rem; }
.panel-heading, .progress-heading, .result-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.panel-heading h2 { margin: 0; font-size: 1.05rem; }
.history-list { display: grid; gap: 0.55rem; margin: 1rem 0; max-height: 55vh; overflow: auto; }
.history-item { width: 100%; padding: 0.75rem; text-align: left; border: 1px solid var(--soft-line); border-radius: 0.8rem; background: var(--paper); cursor: pointer; }
.history-item:hover, .history-item.active { border-color: var(--cobalt); }
.history-item strong, .history-item small { display: block; }
.history-item small { margin-top: 0.25rem; color: var(--muted); }
.history-actions, .result-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.workspace { min-width: 0; }
.card { border-radius: 1.5rem; padding: clamp(1.25rem, 4vw, 2.2rem); }
.card + .card, .notice + .card { margin-top: 1rem; }
.compact-card { padding: 1.25rem; }
.card h2 { margin: 0 0 0.65rem; font-size: clamp(1.45rem, 4vw, 2.1rem); line-height: 1.18; }
.intro { max-width: 68ch; color: var(--muted); }
.field { margin-top: 1.35rem; }
.field > label, .inline-field label { display: block; margin-bottom: 0.45rem; font-weight: 780; }
.optional { color: var(--muted); font-weight: 500; }
input, textarea {
  width: 100%;
  border: 1px solid rgba(56, 56, 56, 0.24);
  border-radius: 0.85rem;
  padding: 0.8rem 0.9rem;
  background: var(--white);
  color: var(--ink);
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible, .drop-zone:focus-within { outline: none; box-shadow: var(--focus); border-color: var(--cobalt); }
.drop-zone { display: grid; place-items: center; min-height: 9rem; padding: 1.4rem; border: 2px dashed rgba(0, 71, 171, 0.35); border-radius: 1rem; background: rgba(0, 71, 171, 0.035); text-align: center; cursor: pointer; }
.drop-zone strong, .drop-zone span { display: block; }
.drop-zone strong { color: var(--cobalt); font-size: 1.05rem; }
.drop-zone span { margin-top: 0.35rem; color: var(--muted); }
.drop-zone.dragging { border-color: var(--cobalt); background: rgba(0, 71, 171, 0.09); }
.document-list { display: grid; gap: 0.55rem; margin-top: 0.7rem; }
.document-item { display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; align-items: center; padding: 0.65rem 0.8rem; border: 1px solid var(--soft-line); border-radius: 0.75rem; background: var(--paper); }
.document-item span, .document-item small { display: block; overflow-wrap: anywhere; }
.document-item small { color: var(--muted); }
.privacy-details { margin: 1.25rem 0; padding: 0.8rem 1rem; border: 1px solid var(--soft-line); border-radius: 0.85rem; background: var(--paper); }
.privacy-details summary { cursor: pointer; font-weight: 760; }
.privacy-details p { color: var(--muted); font-size: 0.92rem; }

.button, .icon-button { border: 0; border-radius: 0.8rem; font-weight: 800; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.65rem; padding: 0.65rem 1rem; }
.button.primary { background: var(--anthracite); color: var(--white); }
.button.primary:hover { background: #1e1e1e; }
.button.secondary { border: 1px solid var(--line); background: var(--white); }
.button.large { width: 100%; min-height: 3.2rem; font-size: 1.03rem; }
.button:disabled { opacity: 0.48; cursor: not-allowed; }
.icon-button { width: 2.2rem; height: 2.2rem; background: var(--paper); font-size: 1.3rem; }
.file-button { cursor: pointer; }
.remove-document { border: 0; background: transparent; color: var(--garnet); cursor: pointer; font-weight: 800; }
.inline-field { display: grid; grid-template-columns: 150px 1fr; gap: 0.7rem; align-items: center; }
.inline-field label { margin: 0; }

.notice { padding: 0.85rem 1rem; border-radius: 0.8rem; border: 1px solid; }
.notice.warning { color: #6e5100; border-color: #dfc772; background: #fff8d9; }
.notice.error { margin: 1rem 0; color: #74132d; border-color: #e3a4b4; background: #fff0f3; }
.phase-badge { padding: 0.35rem 0.65rem; border-radius: 999px; background: rgba(0, 71, 171, 0.09); color: var(--cobalt); font-size: 0.82rem; font-weight: 800; }
.progress-track { height: 0.55rem; margin: 1.4rem 0 0.8rem; overflow: hidden; border-radius: 999px; background: #ece9e2; }
.progress-track span { display: block; width: 8%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--garnet), var(--cobalt)); transition: width 0.35s ease; }
.progress-message { font-weight: 720; }
.progress-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; padding: 0; list-style: none; counter-reset: steps; }
.progress-steps li { color: var(--muted); font-size: 0.84rem; }
.progress-steps li::before { counter-increment: steps; content: counter(steps); display: grid; place-items: center; width: 1.5rem; height: 1.5rem; margin-bottom: 0.35rem; border: 1px solid var(--line); border-radius: 50%; background: var(--white); }
.progress-steps li.done { color: var(--pine); font-weight: 750; }
.progress-steps li.done::before { content: "✓"; border-color: var(--pine); }

.result-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.meta-pill { padding: 0.35rem 0.6rem; border-radius: 999px; background: var(--paper); border: 1px solid var(--soft-line); color: var(--muted); font-size: 0.82rem; }
.result-content { display: grid; gap: 1rem; }
.result-section { padding-top: 1rem; border-top: 1px solid var(--soft-line); }
.result-section h3 { margin: 0 0 0.65rem; font-size: 1.15rem; }
.result-section pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.compact-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
.compact-cell { padding: 0.85rem; border-radius: 0.8rem; background: var(--paper); border: 1px solid var(--soft-line); }
.compact-cell strong { display: block; color: var(--garnet); }
.question-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.question-table th, .question-table td { padding: 0.65rem; border-bottom: 1px solid var(--soft-line); text-align: left; vertical-align: top; }
.question-table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.human-panel { margin-top: 1.5rem; padding-top: 1.2rem; border-top: 2px solid var(--line); }
.human-panel h3 { margin-top: 0; }
.human-panel .button { margin-top: 0.75rem; }
.muted { color: var(--muted); }
footer { max-width: 900px; margin: 2rem auto; padding: 0 1.2rem max(1rem, env(safe-area-inset-bottom)); text-align: center; font-size: 0.9rem; }

@media (max-width: 850px) {
  .layout { grid-template-columns: 1fr; }
  .history-panel { position: static; }
  .history-list { max-height: 12rem; }
}

@media (max-width: 600px) {
  .app-header { padding-inline: 1rem; }
  .brand-block { align-items: flex-start; }
  .brand-block img { width: 58px; height: 58px; }
  .layout { margin-top: 1rem; padding: 0 0.75rem; }
  .history-panel, .card { border-radius: 1rem; }
  .history-panel { padding: 0.8rem; }
  .card { padding: 1.1rem; }
  .inline-field, .compact-grid { grid-template-columns: 1fr; }
  .progress-steps { grid-template-columns: repeat(2, 1fr); }
  .result-heading { display: block; }
  .result-actions { margin-top: 0.75rem; }
  .question-table, .question-table tbody, .question-table tr, .question-table td { display: block; }
  .question-table thead { display: none; }
  .question-table tr { padding: 0.6rem 0; border-bottom: 1px solid var(--soft-line); }
  .question-table td { padding: 0.2rem 0; border: 0; }
  .question-table td::before { content: attr(data-label) ": "; color: var(--muted); font-weight: 750; }
}

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