:root {
  --background: #0f0f13;
  --surface: #1a1a24;
  --surface-raised: #22222e;
  --border: #2d2d3b;
  --brand: #62377c;
  --action: #be1c7f;
  --text: #f8f9fa;
  --muted: #a1a1aa;
  --success: #54d69b;
  --warning: #f4b860;
  --danger: #ff7188;
  --radius: 8px;
  --ui-font: Inter, "Helvetica Neue", Arial, sans-serif;
  --data-font: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
  font-family: var(--ui-font);
}

button, input, select { font: inherit; }

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 3px;
}

.app-header {
  min-height: 88px;
  padding: 18px clamp(18px, 3vw, 46px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 15, 19, 0.96);
}

.brand-lockup { display: flex; align-items: center; gap: 16px; }
.brand-logo { width: 92px; height: 50px; object-fit: contain; object-position: left center; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.1rem, 2vw, 1.45rem); letter-spacing: -0.02em; }
.brand-lockup p, .toolbar p { color: var(--muted); margin-top: 4px; font-size: 0.86rem; }

.credits { text-align: right; }
.credits span { display: block; color: var(--muted); font-size: 0.75rem; }
.credits strong { font-family: var(--data-font); font-size: 1.35rem; }

main { padding: 24px clamp(18px, 3vw, 46px) 40px; }

.view-tabs { display: flex; gap: 26px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.view-tab { position: relative; padding: 0 0 12px; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-weight: 700; }
.view-tab::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: transparent; }
.view-tab.active { color: var(--text); }
.view-tab.active::after { background: var(--action); box-shadow: 0 0 10px rgba(190, 28, 127, 0.55); }
.view-tab span { display: inline-flex; min-width: 26px; margin-left: 7px; padding: 2px 7px; justify-content: center; border-radius: 999px; background: var(--surface); color: var(--muted); font: 0.68rem var(--data-font); }

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 0.7fr)) minmax(240px, 1.4fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.status-strip > div { padding: 15px 18px; border-right: 1px solid var(--border); }
.status-strip > div:last-child { border-right: 0; }
.status-strip span { display: block; color: var(--muted); font-size: 0.74rem; margin-bottom: 5px; }
.status-strip strong { font-family: var(--data-font); font-size: 1rem; }

.progress-shell { margin: 18px 0 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--brand); border-radius: var(--radius); }
.progress-shell.running { box-shadow: 0 0 18px rgba(190, 28, 127, 0.2); }
.progress-copy { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 8px; }
.progress-value { font-family: var(--data-font); }
.progress-track { height: 3px; background: var(--border); overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--action); transition: width 250ms ease; box-shadow: 0 0 10px var(--action); }

.workspace { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.toolbar, .filters { padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.toolbar { border-bottom: 1px solid var(--border); }
.toolbar h2 { font-size: 1.05rem; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.button {
  min-height: 38px;
  padding: 0 15px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}
.button-link { display: inline-flex; align-items: center; text-decoration: none; }
.button.primary { background: var(--action); }
.button.primary:hover { box-shadow: 0 0 14px rgba(190, 28, 127, 0.42); }
.button.secondary { background: transparent; border-color: var(--brand); }
.button.secondary:hover { background: rgba(98, 55, 124, 0.25); }
.button.outline { background: transparent; border-color: var(--border); }
.button.outline:hover { border-color: var(--muted); }
.button:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; }
.button.small { min-height: 32px; padding: 0 11px; font-size: 0.76rem; }

.filters { padding-top: 14px; padding-bottom: 14px; background: #16161e; }
.search-field { flex: 1; max-width: 620px; }
.search-field input, .sort-field select {
  width: 100%; min-height: 40px; color: var(--text); background: var(--background);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px;
}
.search-field input:focus, .sort-field select:focus { border-color: var(--action); }
.sort-field { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.78rem; }
.sort-field select { min-width: 170px; }

.table-shell { overflow-x: auto; }
table { width: 100%; min-width: 1180px; border-collapse: collapse; }
.planned-table { min-width: 1420px; }
th { padding: 11px 12px; text-align: left; color: var(--muted); font-size: 0.71rem; font-weight: 600; border-bottom: 1px solid var(--border); background: #14141b; }
td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 0.83rem; }
tbody tr:hover { background: rgba(98, 55, 124, 0.1); }
tbody tr:last-child td { border-bottom: 0; }
.select-column { width: 42px; text-align: center; }
.action-column { width: 150px; text-align: right; }
.planned-actions-column { width: 330px; text-align: right; }
td.action-column { text-align: right; }
.vehicle-name { display: block; font-weight: 700; }
.vehicle-version { display: block; margin-top: 4px; color: var(--muted); max-width: 420px; }
.color-control { display: inline-flex; margin-top: 7px; margin-right: 9px; vertical-align: middle; }
.vehicle-color {
  min-width: 138px;
  height: 30px;
  padding: 0 28px 0 9px;
  color: var(--text);
  background: #14141b;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
}
.vehicle-color:hover, .vehicle-color:focus { border-color: var(--brand); }
.vehicle-color.saving { border-color: var(--action); box-shadow: 0 0 12px rgba(190, 28, 127, 0.28); }
.sku { display: inline-block; margin-top: 5px; color: var(--muted); font: 0.7rem var(--data-font); }
.data-value { font-family: var(--data-font); font-variant-numeric: tabular-nums; }
.rank { display: inline-flex; min-width: 30px; height: 30px; align-items: center; justify-content: center; border: 1px solid var(--brand); border-radius: 6px; font: 0.8rem var(--data-font); }
.rank.top-three { color: var(--success); border-color: rgba(84, 214, 155, 0.6); }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.72rem; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status.found::before { background: var(--success); }
.status.missing { color: var(--warning); }
.status.missing::before { background: var(--warning); }
.links { display: flex; gap: 10px; }
.links a { color: #e463b3; text-decoration: none; border-bottom: 1px solid transparent; white-space: nowrap; }
.links a:hover { border-bottom-color: currentColor; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 9px; white-space: nowrap; }
.text-button { padding: 5px 2px; border: 0; color: #d7b6e9; background: transparent; cursor: pointer; font-size: 0.73rem; }
.text-button:hover { color: var(--text); }
.text-button.danger { color: var(--danger); }

.empty-state { padding: 60px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 8px; }

dialog { width: min(480px, calc(100vw - 32px)); color: var(--text); background: var(--surface); border: 1px solid var(--brand); border-radius: var(--radius); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
dialog form { padding: 24px; }
dialog h2 { font-size: 1.1rem; margin-bottom: 10px; }
dialog p { color: var(--muted); line-height: 1.55; }
.form-dialog { width: min(650px, calc(100vw - 32px)); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 20px 0 24px; }
.form-grid label, .single-field { display: grid; gap: 7px; color: var(--muted); font-size: 0.78rem; }
.form-grid .full-field { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .single-field input {
  width: 100%; min-height: 41px; padding: 0 11px; color: var(--text); background: var(--background);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.form-grid input:focus, .form-grid select:focus, .single-field input:focus { border-color: var(--action); }
.single-field { margin: 20px 0 24px; }
.dialog-stats { margin: 20px 0; display: grid; grid-template-columns: 1fr auto; gap: 9px 16px; }
.dialog-stats dt { color: var(--muted); }
.dialog-stats dd { margin: 0; font-family: var(--data-font); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; padding: 13px 16px; border: 1px solid var(--brand); border-radius: var(--radius); background: var(--surface-raised); box-shadow: 0 12px 36px rgba(0, 0, 0, 0.38); font-size: 0.84rem; }
.toast.error { border-color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 850px) {
  .app-header, .toolbar, .filters { align-items: stretch; flex-direction: column; }
  .credits { text-align: left; }
  .status-strip { grid-template-columns: repeat(2, 1fr); }
  .status-strip > div { border-bottom: 1px solid var(--border); }
  .actions { justify-content: flex-start; }
  .search-field { max-width: none; }
  .sort-field { align-items: stretch; flex-direction: column; }
  .view-tabs { overflow-x: auto; }
  .view-tab { white-space: nowrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full-field { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
