:root {
  color-scheme: dark;
  --app-bg: #111315;
  --app-surface: #191c1f;
  --app-surface-2: #22262a;
  --app-text: #f2f4f5;
  --app-muted: #a6afb7;
  --app-line: #343a40;
  --app-accent: #45b97c;
  --app-accent-text: #07150d;
  --app-danger: #f26d78;
  --app-warning: #f4c35b;
  --app-info: #63a9e8;
  --app-focus: #8cc8ff;
  --app-shadow: rgba(0, 0, 0, .28);
}

html[data-app-theme="light"] {
  color-scheme: light;
  --app-bg: #f4f6f7;
  --app-surface: #ffffff;
  --app-surface-2: #edf1f2;
  --app-text: #182024;
  --app-muted: #5f6a72;
  --app-line: #cfd7db;
  --app-accent: #177a4b;
  --app-accent-text: #ffffff;
  --app-danger: #b42335;
  --app-warning: #8a5d00;
  --app-info: #1768a3;
  --app-focus: #1768a3;
  --app-shadow: rgba(35, 46, 52, .15);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--app-bg); color: var(--app-text); font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { min-height: 36px; border: 1px solid var(--app-line); border-radius: 5px; padding: 7px 12px; background: var(--app-surface-2); color: var(--app-text); cursor: pointer; }
button:hover { border-color: var(--app-muted); }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--app-focus); outline-offset: 2px; }
button.primary { background: var(--app-accent); border-color: var(--app-accent); color: var(--app-accent-text); font-weight: 700; }
button.danger { background: var(--app-danger); border-color: var(--app-danger); color: #fff; font-weight: 700; }
button.quiet, .icon-button { background: transparent; }
.icon-button { width: 36px; padding: 0; }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px; background: var(--app-surface); border-bottom: 1px solid var(--app-line); }
.brand, .top-actions { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 5px; background: var(--app-accent); color: var(--app-accent-text); font-size: 12px; font-weight: 800; }
.badge { display: inline-flex; align-items: center; min-height: 22px; border: 1px solid currentColor; border-radius: 4px; padding: 2px 7px; font-size: 11px; font-weight: 800; }
.badge.warning { color: var(--app-warning); }
.badge.success { color: var(--app-accent); }
.badge.error { color: var(--app-danger); }
.muted, .meta-line { color: var(--app-muted); }
.tabs { display: flex; gap: 2px; padding: 0 24px; background: var(--app-surface); border-bottom: 1px solid var(--app-line); overflow-x: auto; }
.tab { min-width: 76px; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; }
.tab.active { color: var(--app-accent); border-bottom-color: var(--app-accent); font-weight: 700; }
.workspace { width: min(1320px, 100%); margin: 0 auto; padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.composer-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 1px; background: var(--app-line); border: 1px solid var(--app-line); }
.form-section { display: flex; flex-direction: column; gap: 15px; padding: 22px; background: var(--app-surface); }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 23px; }
h2 { font-size: 17px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--app-muted); font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--app-line); border-radius: 5px; padding: 9px 10px; background: var(--app-bg); color: var(--app-text); }
textarea { resize: vertical; min-height: 112px; }
select[multiple] { min-height: 190px; }
select option:disabled { color: var(--app-muted); }
.check-row { flex-direction: row; align-items: center; gap: 8px; color: var(--app-text); }
.check-row input { width: 18px; height: 18px; }
.inline-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-control button { min-width: 68px; }
.preflight-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 36px; }
.preflight-row .meta-line { min-width: 0; overflow-wrap: anywhere; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 5px 0 0 5px; }
.segmented button:last-child { border-radius: 0 5px 5px 0; }
.segmented button.active { background: var(--app-accent); color: var(--app-accent-text); border-color: var(--app-accent); }
.image-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; min-height: 0; }
.image-tile { aspect-ratio: 3 / 4; position: relative; overflow: hidden; border: 1px solid var(--app-line); border-radius: 5px; background: var(--app-surface-2); }
.image-tile img { width: 100%; height: 100%; object-fit: cover; }
.image-tile span { position: absolute; left: 5px; bottom: 5px; min-width: 22px; border-radius: 4px; padding: 2px 5px; background: rgba(0, 0, 0, .72); color: #fff; font-size: 11px; text-align: center; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.item-list { display: grid; gap: 8px; }
.item-row { display: grid; grid-template-columns: minmax(220px, 1.3fr) minmax(160px, .8fr) minmax(180px, 1fr) auto; align-items: center; gap: 16px; min-height: 72px; padding: 12px 14px; border: 1px solid var(--app-line); border-radius: 5px; background: var(--app-surface); }
.item-title { font-weight: 700; overflow-wrap: anywhere; }
.item-meta { margin-top: 3px; color: var(--app-muted); font-size: 12px; overflow-wrap: anywhere; }
.row-actions { display: flex; align-items: center; gap: 7px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--app-line); background: var(--app-surface); }
table { width: 100%; border-collapse: collapse; }
th, td { min-height: 44px; padding: 11px 12px; border-bottom: 1px solid var(--app-line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--app-muted); font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.form-error { margin: 0; color: var(--app-danger); font-size: 12px; font-weight: 700; white-space: pre-wrap; }
dialog { width: min(520px, calc(100vw - 32px)); border: 1px solid var(--app-line); border-radius: 6px; padding: 0; background: var(--app-surface); color: var(--app-text); box-shadow: 0 18px 50px var(--app-shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .62); }
.dialog-form { display: flex; flex-direction: column; gap: 15px; padding: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.summary-box { padding: 11px; border-left: 3px solid var(--app-warning); background: var(--app-surface-2); color: var(--app-muted); overflow-wrap: anywhere; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); border: 1px solid var(--app-line); border-radius: 5px; padding: 11px 14px; background: var(--app-text); color: var(--app-bg); box-shadow: 0 10px 30px var(--app-shadow); font-weight: 700; }
.login-body { display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(390px, 100%); }
.login-panel { display: flex; flex-direction: column; gap: 18px; padding: 28px; border: 1px solid var(--app-line); border-radius: 6px; background: var(--app-surface); box-shadow: 0 18px 48px var(--app-shadow); }
.form-stack { display: flex; flex-direction: column; gap: 15px; }
[hidden] { display: none !important; }

@media (max-width: 820px) {
  .topbar { padding: 10px 14px; }
  .top-actions .muted { display: none; }
  .tabs { padding: 0 10px; }
  .workspace { padding: 14px; }
  .composer-grid { grid-template-columns: 1fr; }
  .inline-control { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr; gap: 8px; }
  .row-actions { flex-wrap: wrap; }
}
