:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #687385;
  --line: #dfe4ea;
  --accent: #1769e0;
  --accent-dark: #0f55bd;
  --danger: #c93535;
  --ok: #0d7f4f;
  --warn: #ad6b00;
  --shadow: 0 10px 30px rgba(18, 32, 48, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}

body.is-locked {
  display: block;
}

body.is-locked .sidebar,
body.is-locked .app {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: var(--bg);
  z-index: 20;
}

body.is-locked .login-screen {
  display: grid;
}

body.is-viewer .nav-item:not([data-view="dashboard"]),
body.is-viewer #runCheckBtn,
body.is-viewer #exportJsonBtn,
body.is-viewer #clearBtn {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 24px;
}

.login-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #b7c2d0;
}

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

.primary:hover {
  background: var(--accent-dark);
}

.ghost {
  background: transparent;
}

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

.sidebar {
  min-height: 100vh;
  padding: 18px;
  background: #111820;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  font-weight: 800;
}

.brand small {
  display: block;
  color: #aeb9c7;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  text-align: left;
  color: #dbe3ed;
  border-color: transparent;
  background: transparent;
}

.nav-item:hover,
.nav-item.is-active {
  background: #202c38;
  border-color: #2d3b49;
  color: #fff;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-actions button {
  color: #fff;
  border-color: #2d3b49;
}

.app {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.topbar p,
.panel p {
  color: var(--muted);
}

.topbar-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.toolbar {
  margin-bottom: 12px;
}

.inline-field {
  display: grid;
  gap: 4px;
  min-width: 180px;
  color: var(--muted);
}

.toolbar input,
.toolbar select {
  min-width: 240px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

.editor {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.editor .check {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 39px;
}

.check input {
  width: auto;
}

.settings-form {
  max-width: 980px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
}

.pager select {
  width: auto;
  min-width: 92px;
}

.pager button {
  padding: 7px 10px;
}

.pager .pager-info {
  margin-right: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f0f3f6;
  color: #3a4655;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  z-index: 1;
}

td.num,
th.num {
  text-align: right;
}

.price-main {
  font-size: 16px;
}

.sort-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sort-button:hover {
  color: var(--accent);
}

.price-diff {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
}

.diff-positive {
  color: var(--ok);
}

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

tr:last-child td {
  border-bottom: 0;
}

.cell-sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2f7;
  color: #465365;
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  background: #e6f5ee;
  color: var(--ok);
}

.badge.warn {
  background: #fff3dc;
  color: var(--warn);
}

.badge.danger {
  background: #fdeaea;
  color: var(--danger);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  padding: 6px 8px;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 14px;
}

.panel {
  padding: 16px;
}

.panel button,
.panel input {
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #111820;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

a {
  color: var(--accent);
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .import-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .metrics,
  .editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app {
    padding: 14px;
  }

  .metrics,
  .editor,
  .nav {
    grid-template-columns: 1fr;
  }

  .topbar-actions button,
  .toolbar input,
  .toolbar select {
    width: 100%;
  }
}
