:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --text: #202327;
  --muted: #68717a;
  --line: #d8dde2;
  --accent: #176f7a;
  --accent-dark: #105862;
  --danger: #a23838;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button[type="submit"],
#saveProjectBtn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button[type="submit"]:hover,
#saveProjectBtn:hover {
  background: var(--accent-dark);
}

.danger {
  color: var(--danger);
}

.file-button input {
  display: none;
}

input,
select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  color: var(--text);
}

input[type="color"] {
  padding: 2px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: grid;
  min-width: 230px;
  margin-right: 8px;
}

.brand strong {
  font-size: 18px;
}

.brand span,
.status {
  color: var(--muted);
  font-size: 13px;
}

.project-name {
  min-width: 220px;
}

.status {
  margin-left: auto;
  text-align: right;
}

.app-shell {
  display: grid;
  grid-template-columns: 420px minmax(720px, 1fr);
  height: calc(100vh - 64px);
}

.sidebar {
  overflow: auto;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #fafbfc;
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.panel h2,
.dialog h2 {
  margin: 0;
  font-size: 15px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.preset-list {
  display: grid;
  gap: 8px;
}

.stamp-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

#stampModeBtn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.active-preset {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f8f9;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-list,
.page-list {
  display: grid;
  gap: 8px;
}

.project-actions,
.page-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.project-actions .danger {
  grid-column: 1 / -1;
}

.project-row,
.page-row {
  width: 100%;
  min-height: 38px;
  justify-content: start;
  text-align: left;
}

.project-row.active,
.page-row.active {
  border-color: var(--accent);
  background: #eef8f9;
}

.project-row {
  display: grid;
  gap: 2px;
}

.preset-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: grab;
}

.preset-card.active {
  border-color: var(--accent);
  background: #eef8f9;
  box-shadow: 0 0 0 1px rgba(23, 111, 122, 0.18);
}

.preset-card:active {
  cursor: grabbing;
}

.preset-preview {
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-weight: 750;
  line-height: 1;
}

.preset-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.preset-meta strong {
  font-size: 14px;
}

.preset-meta span {
  color: var(--muted);
  font-size: 12px;
}

.panel-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.advanced-controls {
  display: grid;
  gap: 10px;
}

.advanced-controls summary,
.experiment-details summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.experiment-details {
  display: grid;
  gap: 10px;
}

.experiment-details[open] {
  gap: 12px;
}

.experiment-details > *:not(summary) {
  margin-top: 10px;
}

.staff-zone-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.calibration-controls {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 8px;
}

.calibration-controls h3 {
  margin: 0;
  font-size: 13px;
}

.debug-info {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f8f9;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  padding: 8px;
  white-space: pre-line;
}

.candidate-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.icon-button {
  min-width: 30px;
  min-height: 30px;
  padding: 0;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
  font-weight: 500;
}

.checkbox-row input {
  min-height: 0;
}

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

.workspace {
  overflow: auto;
  padding: 18px;
  background: #e9ecef;
  position: relative;
  display: grid;
  place-items: start center;
}

.stage-host {
  display: inline-block;
  background: #fff;
  box-shadow: 0 1px 10px rgba(0, 0, 0, 0.16);
  aspect-ratio: 210 / 297;
}

.empty-state {
  position: absolute;
  inset: 18px;
  pointer-events: none;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(20, 24, 28, 0.28);
}

.dialog-body {
  width: min(380px, calc(100vw - 28px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.print-area {
  display: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .topbar {
    flex-wrap: wrap;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
