:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #6d7785;
  --line: #dbe0e6;
  --soft: #f4f5f7;
  --panel: #fbfbfc;
  --accent: #ff5a36;
  --accent-dark: #d93e1d;
  --shadow: 0 18px 55px rgba(23, 32, 42, 0.13);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #e9ecef; color: var(--ink); }

button, input, select { font: inherit; }
button, summary, select, input[type="color"], input[type="checkbox"], input[type="radio"] { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: minmax(320px, 390px) 1fr; height: 100dvh; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; overflow: hidden; background: var(--panel); border-right: 1px solid var(--line); z-index: 2; }
.brand { flex: 0 0 72px; height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 26px; border-bottom: 1px solid var(--line); }
h1 { margin: 0; white-space: nowrap; font-family: Georgia, serif; font-size: clamp(22px, 2vw, 29px); font-weight: 400; line-height: 1; letter-spacing: -.04em; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--ink); font-size: 20px; transition: .18s ease; }
.icon-button:hover { border-color: var(--accent); color: var(--accent); transform: rotate(-20deg); }

.settings-scroll { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
details { border-bottom: 1px solid var(--line); background: rgba(255,255,255,.4); }
summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 26px; list-style: none; font-weight: 750; font-size: 13px; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "+"; order: 3; color: var(--muted); font-size: 17px; font-weight: 400; }
details[open] summary::before { content: "−"; }
.summary-value { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-body { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 10px; padding: 2px 26px 22px; }
.field-wide { grid-column: 1 / -1; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field, .color-field { display: grid; gap: 6px; min-width: 0; }
.field > span, .color-field > span, .subheading { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.subheading { margin-top: 5px; }
.color-section { margin-top: 15px; }
input[type="number"], input[type="text"], select { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); padding: 0 10px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,90,54,.12); }
input:disabled, select:disabled { cursor: not-allowed; color: #929aa5; background: #f0f2f4; opacity: .75; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 7px; border-radius: 5px; color: var(--muted); font-size: 11px; text-align: center; }
.segmented input:checked + span { background: white; color: var(--ink); box-shadow: 0 1px 4px rgba(23,32,42,.12); font-weight: 700; }
.toggle { display: flex; align-items: center; gap: 9px; min-height: 28px; color: var(--ink); font-size: 12px; font-weight: 650; }
.toggle input { width: 17px; height: 17px; accent-color: var(--accent); }
.compact-toggle { min-height: 22px; color: var(--muted); font-size: 10px; font-weight: 700; }
.compact-toggle input { width: 15px; height: 15px; }
.output-chip { align-self: end; display: grid; place-items: center; height: 38px; border-radius: 7px; background: var(--ink); color: white; font-size: 10px; font-variant-numeric: tabular-nums; }
.color-field { position: relative; grid-template-columns: 1fr 34px; align-items: center; grid-column: 1 / -1; min-height: 34px; }
.color-field input { width: 31px; height: 25px; padding: 1px; border: 1px solid var(--line); border-radius: 5px; background: white; }
.color-field.inherited-color input[type="color"] { opacity: 1; }
.color-field.inherited-color::after { content: ""; position: absolute; top: 50%; right: 4px; width: 25px; height: 2px; border-radius: 999px; background: var(--inherit-strike, #000); transform: translateY(-50%) rotate(-42deg); pointer-events: none; }
.setting-with-default { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; }
.setting-with-default > .color-field { grid-column: auto; }
.default-toggle { display: flex; align-items: center; gap: 5px; min-height: 34px; color: var(--muted); font-size: 10px; font-weight: 700; }
.default-toggle input { width: 15px; height: 15px; accent-color: var(--accent); }
.border-settings { display: grid; gap: 9px; padding-top: 3px; border-top: 1px solid #edf0f2; }
.border-controls { display: grid; gap: 10px; }
.secondary-button { min-height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); font-weight: 700; font-size: 11px; }
.secondary-button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }
.secondary-button:disabled { cursor: not-allowed; opacity: .45; }
.secondary-button.danger:hover:not(:disabled) { border-color: #d92d20; color: #b42318; }
.preset-panel { padding: 2px 26px 20px; }
.preset-list { display: grid; gap: 7px; margin-bottom: 9px; }
.preset-row { display: grid; grid-template-columns: minmax(0, 1fr) 32px 32px 32px; align-items: center; min-height: 38px; border: 1px solid var(--line); border-radius: 7px; background: white; overflow: hidden; }
.preset-row.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,90,54,.1); }
.preset-name, .preset-action { height: 36px; border: 0; background: transparent; color: var(--ink); }
.preset-name { min-width: 0; padding: 0 10px; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 700; }
.preset-action { border-left: 1px solid #edf0f2; color: var(--muted); font-size: 15px; }
.preset-action:hover { color: var(--accent-dark); background: #fff7f5; }
.preset-action.remove:hover { color: #b42318; }
.preset-name-input { width: 100%; height: 36px !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; font-size: 11px; font-weight: 700; }
.preset-new { width: 100%; }
.labels-body { display: block; }
.style-body { padding-top: 0; }
.style-subsections { display: grid; gap: 8px; }
.style-subsection { border: 1px solid var(--line); border-radius: 8px; background: white; overflow: hidden; }
.style-subsection > summary { padding: 12px 14px; font-size: 11px; }
.style-subsection > summary::before { font-size: 14px; }
.role-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; padding: 4px 14px 16px; border-top: 1px solid #edf0f2; }
.role-fields .color-field { grid-column: 1 / -1; }
.role-fields .setting-with-default > .color-field { grid-column: auto; }
.style-field-separator { height: 1px; margin: 1px 0; background: #edf0f2; }
.text-format-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.format-toggle { position: relative; min-width: 0; }
.format-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.format-toggle span { display: block; overflow: hidden; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--muted); font-size: 10px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.format-toggle input:checked + span { border-color: var(--accent); background: #fff7f5; color: var(--accent-dark); box-shadow: 0 0 0 2px rgba(255,90,54,.08); }
.format-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.value-group { display: grid; gap: 8px; }
.value-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.value-group-heading > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.setting-options { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.individual-toggle { display: grid; place-items: center; width: 25px; height: 25px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--muted); font-size: 16px; font-weight: 800; line-height: 1; }
.individual-toggle:hover { border-color: var(--accent); color: var(--accent-dark); }
.individual-values { margin-top: 2px; }
.name-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 9px 0 18px; }
.name-grid.weekdays { grid-template-columns: repeat(2, 1fr); margin-bottom: 2px; }
.name-item { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: center; gap: 5px; }
.name-number { color: var(--muted); font-size: 9px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.name-grid input { min-width: 0; height: 34px; font-size: 11px; }

.export-panel { flex: 0 0 auto; padding: 0; border-top: 1px solid var(--line); background: #fff; }
.export-details { border: 0; background: #fff; }
.export-details > summary { padding: 14px 26px; }
.export-details > summary small { margin-left: auto; color: var(--muted); font-size: 10px; font-weight: 500; }
.export-body { padding: 0 26px 20px; }
.export-body select { margin-bottom: 9px; }
.export-dpi { margin-bottom: 9px; }
.download-button { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 46px; padding: 0 42px; border: 0; border-radius: 8px; background: var(--accent); color: white; font-weight: 800; text-align: center; transition: .18s ease; }
.download-button span:last-child { position: absolute; right: 16px; }
.download-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.download-button:disabled { opacity: .55; cursor: wait; transform: none; }
.status { min-height: 0; margin-top: 0; color: var(--muted); font-size: 10px; line-height: 1.35; }
.status:not(:empty) { min-height: 14px; margin-top: 8px; }
.status.error { color: #b42318; }

.preview-area { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: #e9ecef; }
.preview-toolbar { flex: 0 0 72px; height: 72px; display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 0 34px; border-bottom: 1px solid rgba(23,32,42,.1); }
.preview-toolbar h2 { margin: 0; font-family: Georgia, serif; font-weight: 400; font-size: 22px; letter-spacing: -.025em; }
.preview-tools { display: flex; align-items: center; gap: 12px; }
.zoom-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.zoom-control select { width: 78px; height: 30px; padding-inline: 8px; border-radius: 999px; font-size: 10px; text-transform: none; }
.preview-meta { display: flex; gap: 8px; color: var(--muted); font-size: 10px; }
.preview-meta span { padding: 6px 9px; border: 1px solid rgba(23,32,42,.12); border-radius: 999px; background: rgba(255,255,255,.5); }
.preview-stage { flex: 1; min-height: 0; overflow: auto; display: grid; align-content: start; justify-items: center; gap: 34px; padding: 38px; }
.preview-stage.single:not(.zoomed) { align-content: center; }
.preview-stage.zoomed { align-content: start; justify-items: start; }
.page-wrap { margin: 0; display: grid; grid-template-columns: 24px minmax(0, auto); grid-template-rows: auto auto 18px; align-items: center; justify-items: center; gap: 7px 10px; }
.page-canvas { position: relative; width: 100%; aspect-ratio: var(--page-ratio); line-height: 0; background-color: white; background-image: linear-gradient(45deg,#eef0f2 25%,transparent 25%),linear-gradient(-45deg,#eef0f2 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#eef0f2 75%),linear-gradient(-45deg,transparent 75%,#eef0f2 75%); background-size: 16px 16px; background-position: 0 0,0 8px,8px -8px,-8px 0; box-shadow: var(--shadow); }
.page-canvas svg { display: block; width: 100%; height: 100%; background: transparent; }
.page-height { grid-column: 1; grid-row: 2; writing-mode: vertical-rl; transform: rotate(180deg); }
.page-canvas { grid-column: 2; grid-row: 2; }
.page-width { grid-column: 2; grid-row: 3; }
.page-measure { color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .05em; font-variant-numeric: tabular-nums; }
.page-label { grid-column: 2; grid-row: 1; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.preview-message { align-self: center; max-width: 430px; padding: 24px; color: var(--muted); text-align: center; line-height: 1.5; }

[hidden] { display: none !important; }

@media (max-width: 850px) {
  .app-shell { grid-template-columns: 320px minmax(430px, 1fr); }
  .preview-toolbar { padding-inline: 24px; }
  .preview-stage { padding: 28px; }
}

@media (max-width: 680px) {
  body { overflow: auto; }
  .app-shell { display: grid; grid-template-columns: 1fr; grid-template-rows: 100dvh 100dvh; height: 200dvh; overflow: visible; }
  .sidebar { height: 100dvh; }
  .preview-area { height: 100dvh; }
}

@media print {
  .sidebar, .preview-toolbar, .page-label { display: none !important; }
  .app-shell, .preview-area, .preview-stage { display: block; height: auto; overflow: visible; padding: 0; background: white; }
  .page-wrap, .page-canvas { width: 100%; max-width: none; box-shadow: none; break-after: page; }
}
