:root {
  color-scheme: light;
  --fg: #172026; --muted: #5b6570; --line: #dbe1e7; --bg: #f3f5f8; --surface: #fff;
  --accent: #1f4e79; --accent-dark: #163a5a; --accent-soft: #e6eef6;
  --danger: #a32121; --ok: #1b6b2f; --warn: #8a5a00;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); background: var(--bg); overflow-wrap: break-word; }
h1 { margin: 0 0 var(--s4); font-size: 26px; line-height: 1.25; }
h2 { margin: var(--s4) 0 var(--s2); font-size: 18px; line-height: 1.3; }
h3 { margin: var(--s3) 0 var(--s2); font-size: 15px; line-height: 1.3; }
p { margin: 0 0 var(--s2); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid #7aa7d1; outline-offset: 2px; }

/* Top bar and persistent navigation */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s5); padding: var(--s3) var(--s5); background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.brand { font-weight: 700; font-size: 17px; color: var(--fg); text-decoration: none; white-space: nowrap; }
.brand-sub { font-weight: 500; color: var(--muted); }
.topnav { display: flex; flex-wrap: wrap; gap: var(--s1); flex: 1 1 auto; }
.topnav[hidden] { display: none; }
.topnav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.topnav a:hover { background: var(--bg); color: var(--fg); }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); }
.content { max-width: 1040px; margin: var(--s5) auto var(--s6); padding: 0 var(--s5); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 38px; font: inherit; font-weight: 600; padding: 6px 16px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn[hidden] { display: none; }
a.btn { display: inline-flex; }
.btn-secondary { background: var(--surface); color: var(--accent); border-color: #b8c6d4; }
.btn-secondary:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-dark); border-color: #b8c6d4; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #7d1818; border-color: #7d1818; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.error { color: var(--danger); }
.error:empty { display: none; }
.muted { color: var(--muted); }
.muted:empty { display: none; }

/* Dashboard */
.nav { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s4); margin: var(--s4) 0; padding: 0; list-style: none; }
.nav li { display: block; }
.nav a, .nav span { display: block; padding: var(--s5) var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); color: var(--accent); font-size: 17px; font-weight: 600; text-decoration: none; }
.nav a:hover { border-color: var(--accent); background: var(--accent-soft); }
.nav .disabled { color: var(--muted); background: transparent; cursor: not-allowed; }

/* Toolbars */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin: 0 0 var(--s4); }
.inline { display: inline-flex; align-items: center; gap: var(--s2); }
.toolbar select, .toolbar input[type=search], .toolbar input[type=date], .panel input[type=text] { font: inherit; min-height: 38px; padding: 6px 10px; border: 1px solid #b8c6d4; border-radius: 6px; background: var(--surface); max-width: 100%; min-width: 0; }
.toolbar input[type=search] { flex: 1 1 200px; }

/* Tables: scroll horizontally inside the card instead of clipping the page */
.table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table th, .table td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { background: #f8fafc; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfd; }
.table td:first-child, .table td:nth-child(2), .table td:nth-child(5) { white-space: nowrap; }
.table td { min-width: 0; }
.table td a { font-weight: 600; text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.thumb { display: block; width: 56px; height: 42px; object-fit: cover; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); }
.diff-line { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 12.5px; overflow-wrap: anywhere; min-width: 220px; }

/* Forms */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4) var(--s5); align-items: start; padding: var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form > fieldset, .form > .actions, .form > .field:has(textarea), .form > .error { grid-column: 1 / -1; }
.field { display: grid; gap: var(--s1); min-width: 0; align-content: start; }
.field label { font-weight: 600; font-size: 14px; }
.field input, .field textarea, .spec-row input { font: inherit; padding: 8px 10px; border: 1px solid #b8c6d4; border-radius: 6px; width: 100%; min-width: 0; background: var(--surface); }
.field textarea { resize: vertical; }
.field input[readonly] { background: var(--bg); color: var(--muted); }
.field p { margin: 0; font-size: 13px; }
fieldset { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfd; padding: var(--s3) var(--s4) var(--s4); }
legend { padding: 0 var(--s2); font-weight: 700; font-size: 15px; }
.prices { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s3) var(--s4); }
.prices legend { grid-column: 1 / -1; float: left; width: auto; }
.spec-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto; gap: var(--s2); margin-bottom: var(--s2); align-items: center; }
.trans-spec-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: var(--s2) 0; }
.form > .actions:last-child { position: sticky; bottom: 0; z-index: 5; margin: 0 calc(var(--s5) * -1) calc(var(--s5) * -1); padding: var(--s3) var(--s5); background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.banner { background: #fff4e5; border: 1px solid #f0c27b; padding: var(--s2) var(--s3); border-radius: 6px; margin-bottom: var(--s4); }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s3); margin: var(--s2) 0 var(--s3); }
.gallery-item { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: var(--s2); }
.gallery-item .actions { margin: 0; gap: var(--s1); }
.gallery-item .btn { flex: 1 1 auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }
.gallery-item p { margin: 0; font-size: 13px; }
.thumb-lg { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; background: var(--bg); }
.card-row { display: grid; gap: var(--s2); justify-items: start; margin: var(--s3) 0; }
.card-row .thumb-lg { width: 200px; max-width: 100%; }

/* Image editor */
.editor { display: grid; gap: var(--s3); justify-items: start; border: 2px solid var(--accent); border-radius: var(--radius); background: var(--surface); padding: var(--s4); margin: var(--s3) 0; }
.editor h3 { margin: 0; }
.editor-canvas { display: block; width: 100%; max-width: 480px; height: auto; cursor: grab; touch-action: none; border: 1px solid var(--line); border-radius: 4px; }
.editor label { display: block; font-weight: 600; margin-top: var(--s1); }
.editor input[type=range] { display: block; width: 100%; max-width: 480px; accent-color: var(--accent); }
.editor p { margin: 0; }

/* Panels and order details */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s1) var(--s4) var(--s4); margin: var(--s4) 0; min-width: 0; }
.panel .table { box-shadow: none; margin-bottom: var(--s3); }
.details { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: var(--s2) var(--s4); margin: var(--s2) 0; }
.details dt { font-weight: 600; color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
h1 .status { vertical-align: middle; margin-left: var(--s2); font-size: 14px; }

/* Status badges */
.status { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; line-height: 1.5; white-space: nowrap; background: #eceff3; color: #3d4752; border: 1px solid #cfd6de; }
.status-pending_payment { background: #fff4d6; color: #7a5200; border-color: #f0d68a; }
.status-paid { background: #dcf3e1; color: #14562a; border-color: #a6d9b3; }
.status-in_production { background: #e1ebfb; color: #1c3f7a; border-color: #aec5ee; }
.status-shipped { background: #e4e0f8; color: #3c2f8a; border-color: #bfb6ec; }
.status-delivered { background: #c9ecd2; color: #0f4a22; border-color: #8ccb9d; }
.status-payment_failed, .status-cancelled { background: #fbe1e1; color: #8a1c1c; border-color: #eeb0b0; }
.status-refunded { background: #eceff3; color: #3d4752; border-color: #cfd6de; }

/* Toast */
.toast { position: fixed; right: var(--s4); bottom: 84px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 6px; color: #fff; background: var(--ok); box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.toast[hidden] { display: none; }
.toast-warn { background: var(--warn); }
.toast-error { background: var(--danger); }

/* Translation tabs */
.tabs { display: flex; flex-wrap: wrap; gap: var(--s1); margin: var(--s2) 0 var(--s3); }
.tab { font: inherit; padding: 6px 12px; border: 1px solid #b8c6d4; border-radius: 6px; background: var(--surface); color: var(--accent); cursor: pointer; }
.tab-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab-panel[hidden] { display: none; }
.tab-panel { display: grid; gap: var(--s3); }
.trans-spec-row { align-items: center; }

/* Pages tab */
.page-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s4); margin: var(--s4) 0; }
.page-card { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.page-card h2 { margin: 0 0 var(--s1); }
.page-card .actions { margin-top: auto; padding-top: var(--s3); }
.page-head { margin-bottom: var(--s3); }
.page-head h1 { margin: var(--s2) 0 var(--s2); }
.page-sections { display: grid; gap: var(--s4); margin-bottom: var(--s4); }
.page-section { padding: var(--s3) var(--s4) var(--s4); margin: 0; display: grid; gap: var(--s4); align-content: start; }
.page-section > h2 { margin: var(--s2) 0 0; }
.page-section > p { margin: calc(var(--s2) * -1) 0 0; }
.slot { padding-top: var(--s3); border-top: 1px solid var(--line); }
.slot .field-title { margin: 0; font-weight: 600; font-size: 14px; }
.slot-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); }
.slot-meta p { margin: 0; font-size: 13px; }
.counter { flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter-over { color: var(--danger); font-weight: 700; }
.field-error { font-size: 13px; }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: var(--danger); }
.ref { padding: 4px 8px; background: var(--bg); border-left: 3px solid var(--line); border-radius: 4px; white-space: pre-line; }
.btn-small { min-height: 30px; padding: 2px 10px; font-size: 13px; justify-self: start; }
.notice { color: var(--warn); font-weight: 600; }
.image-row { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.image-info { display: grid; gap: var(--s2); min-width: 0; }
.image-info p { margin: 0; font-size: 13px; }
.page-thumb { display: block; width: 100%; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); }
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.thumb-hero { aspect-ratio: 21 / 10; }
.thumb-square { aspect-ratio: 1 / 1; max-width: 200px; }
.thumb-photo { aspect-ratio: 3 / 2; }
.thumb-portrait { aspect-ratio: 7 / 8; max-width: 200px; }

/* Sticky save bar of the page editor */
.savebar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s4); padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -2px 8px rgba(16, 24, 40, .08); }
.dirty-flag { font-weight: 600; color: var(--muted); }
.dirty-flag.dirty { color: var(--warn); }
.savebar-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.savebar-actions .btn { min-height: 36px; }

/* Narrow screens */
@media (max-width: 720px) {
  .toast { bottom: 150px; right: var(--s3); }
  .topbar { padding: var(--s2) var(--s3); gap: var(--s1) var(--s3); }
  .topnav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .content { margin: var(--s4) auto var(--s5); padding: 0 var(--s3); }
  h1 { font-size: 22px; }
  .form { grid-template-columns: minmax(0, 1fr); padding: var(--s3); }
  .form > .actions:last-child { margin: 0 calc(var(--s3) * -1) calc(var(--s3) * -1); padding: var(--s2) var(--s3); }
  .spec-row, .trans-spec-row { grid-template-columns: minmax(0, 1fr); padding-bottom: var(--s2); border-bottom: 1px dashed var(--line); }
  .details { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .details dt { margin-top: var(--s2); font-size: 13px; }
  .toolbar > * { flex: 1 1 100%; }
  .toolbar .btn { flex: 1 1 auto; }
  .table th, .table td { padding: 8px 10px; }
  .image-row { grid-template-columns: minmax(0, 1fr); }
  .thumb-square, .thumb-portrait { max-width: 160px; }
  .page-section { padding: var(--s2) var(--s3) var(--s3); }
  .savebar { margin: 0 calc(var(--s3) * -1); padding: var(--s2) var(--s3); border-radius: 0; border-left: 0; border-right: 0; }
  .savebar-actions { width: 100%; }
  .savebar-actions .btn { flex: 1 1 auto; padding: 4px 10px; font-size: 13px; }
}
