:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --surface: #fffaf1;
  --surface-strong: #fffdf8;
  --ink: #21201c;
  --muted: #6d695f;
  --line: #d8d0c2;
  --accent: #1f7a6d;
  --accent-strong: #155e55;
  --accent-soft: #dcefeb;
  --blue: #315f9a;
  --rose: #a9475e;
  --gold: #9b6b19;
  --shadow: 0 18px 50px rgba(39, 33, 24, 0.12);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(31, 122, 109, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(49, 95, 154, 0.045) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--sans);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar, .card, .auth-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 14px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 7px;
  background: linear-gradient(135deg, #1f7a6d, #315f9a);
  color: #fffaf1;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 800;
}

h1, h2, p { margin: 0; }
.brand h1 { font-size: clamp(22px, 3vw, 34px); line-height: 1.05; }
.brand p, .eyebrow { color: var(--muted); font-family: var(--mono); font-size: 11px; font-weight: 700; text-transform: uppercase; }

.top-actions, .button-row, .auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.icon-button, .primary-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 800;
}

.icon-button {
  width: 42px;
}

.primary-button {
  padding: 0 16px;
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fffaf1;
}

.secondary-button {
  padding: 0 14px;
}

.danger { color: var(--rose); }
.secondary-link { color: var(--accent-strong); font-weight: 800; text-decoration: none; }

.auth-panel {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 130px);
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(280px, 0.55fr);
  gap: 30px;
  width: min(880px, 100%);
  padding: 28px;
}

.auth-card h2 { margin-top: 6px; font-size: clamp(28px, 5vw, 52px); line-height: 1.05; }
.auth-card p { margin-top: 14px; color: var(--muted); line-height: 1.7; }
.auth-form, .field, .share-settings label { display: grid; gap: 7px; }

.auth-form label span, .field span, .share-settings span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  background: var(--surface-strong);
  color: var(--ink);
}

input { height: 44px; padding: 0 12px; }
textarea { min-height: 96px; padding: 11px 12px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.13); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(380px, 0.96fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(360px, 0.7fr);
  gap: 16px;
  margin-top: 16px;
}

.workspace > *, .dashboard > *, .panel-heading > div, .share-item > div {
  min-width: 0;
}

.card { padding: 18px; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading h2 { margin-top: 2px; font-size: 24px; line-height: 1.1; }
.user-line { margin-top: 6px; color: var(--muted); font-size: 13px; }

.date-input { width: 150px; font-family: var(--mono); }

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.42fr);
  gap: 12px;
  margin-bottom: 16px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f5efe3;
}

.segmented legend { position: absolute; width: 1px; height: 1px; overflow: hidden; }
.segmented label { display: grid; place-items: center; min-height: 34px; border-radius: 5px; color: var(--muted); font-size: 14px; }
.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.segmented label:has(input:checked) { background: var(--surface-strong); color: var(--accent-strong); }

.range-control {
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
}

.range-control span { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.range-control strong { color: var(--ink); font-family: var(--mono); }
.range-control input { accent-color: var(--accent); }

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field.full { grid-column: 1 / -1; }

.patch-output {
  min-height: 637px;
  padding: 22px;
  border: 1px solid #c7baa8;
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(255, 253, 248, 0.72), rgba(255, 253, 248, 0.72)),
    repeating-linear-gradient(0deg, transparent, transparent 30px, rgba(49, 95, 154, 0.08) 31px);
  line-height: 1.65;
}

.patch-output h3 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  font-size: 28px;
  line-height: 1.12;
}

.build-tag, .status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(31, 122, 109, 0.32);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.saved { border-color: rgba(31, 122, 109, 0.35); background: var(--accent-soft); }

.patch-section { margin-top: 17px; }
.patch-section h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 7px; font-size: 15px; }
.patch-section h4::before { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); content: ""; }
.patch-section.issue h4::before, .patch-section.rollback h4::before { background: var(--rose); }
.patch-section.analysis h4::before { background: var(--blue); }
.patch-section.experiment h4::before { background: var(--gold); }
.patch-section ul { margin: 0; padding-left: 22px; }
.patch-section p { margin: 0; }

.history-list, .share-list { display: grid; gap: 10px; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}
.history-main {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
  color: inherit;
  text-align: left;
}
.history-main span { color: var(--accent-strong); font-family: var(--mono); font-size: 12px; font-weight: 800; }
.history-main strong { font-size: 15px; line-height: 1.35; }
.history-main small, .share-item small { color: var(--muted); font-size: 12px; }

.share-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.share-result {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.qr-box {
  display: grid;
  place-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
}
.qr-box svg { width: min(240px, 100%); height: auto; }

.share-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.share-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
}
.share-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-item.inactive { opacity: 0.62; }

.empty-state {
  padding: 24px;
  border: 1px dashed #bfb4a2;
  border-radius: 7px;
  color: var(--muted);
}

.share-note { margin-top: 14px; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 7px;
  background: #173f3a;
  color: #fffaf1;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .workspace, .dashboard, .auth-card { grid-template-columns: 1fr; }
  .patch-output { min-height: 460px; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 680px); padding-top: 10px; }
  .topbar, .panel-heading { align-items: stretch; flex-direction: column; }
  .top-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .icon-button { width: 100%; }
  .control-grid, .input-grid, .share-settings, .share-url-row, .share-item { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .date-input { width: 100%; }
  .patch-output { padding: 16px; }
  .patch-output h3 { font-size: 23px; }
}
