:root {
  --bg-page: #f5f6f3;
  --bg-surface: #ffffff;
  --bg-subtle: #eef0ec;
  --ink-primary: #14171a;
  --ink-secondary: #4a545e;
  --ink-muted: #76808a;
  --border-light: #e1e5df;
  --border-strong: #c8cfc6;

  --ozon: #005bff;
  --ozon-soft: #eaf1ff;
  --tiktok: #fe2c55;
  --tiktok-soft: #fff0f3;

  --accent: #0f6b4b;
  --accent-hover: #0a543a;
  --accent-soft: #e6f4ee;

  --ok: #15803d;
  --ok-soft: #e8f7ed;
  --warn: #b45309;
  --warn-soft: #fef5e7;
  --err: #c81e1e;
  --err-soft: #fdecec;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-size: 12px; }

/* ---------- Login Screen ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}

.login-card h1 {
  margin: 14px 0 6px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--ink-secondary);
  font-size: 13px;
}

/* ---------- Top Bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-light);
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--ink-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.brand-title { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--ink-muted); }

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 9px;
  overflow-x: auto;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  padding: 7px 13px;
  border-radius: 6px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  font-size: 12px;
  color: var(--ink-secondary);
  cursor: pointer;
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: #cbd5e1; }
.dot.ok { background: #16a34a; }
.dot.off { background: #94a3b8; }
.dot.warn { background: #d97706; }

/* ---------- Layout ---------- */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px 20px 64px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-intro { margin-bottom: 20px; }
.page-intro h1 { margin: 0 0 4px; font-size: 21px; font-weight: 700; letter-spacing: -0.025em; }
.page-intro p { margin: 0; color: var(--ink-secondary); font-size: 13.5px; }

.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 18px;
}

.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.surface-title { margin: 0; font-size: 15px; font-weight: 650; }
.surface-desc { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-muted); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---------- Platform Selector & Tags ---------- */
.platform-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 7px;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
}

.seg-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.tag-ozon { background: var(--ozon-soft); color: var(--ozon); }
.tag-tiktok { background: var(--tiktok-soft); color: var(--tiktok); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--ink-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn:hover:not(:disabled) { background: var(--bg-subtle); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a51818; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-secondary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: #fafbf9;
  padding: 28px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Progress Bar ---------- */
.progress-wrap {
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 8px;
}

.progress-track {
  height: 8px;
  background: #d8ded6;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---------- Tables & Badges ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #f9faf8;
  color: var(--ink-secondary);
  font-weight: 600;
  text-align: left;
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
tbody td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-neutral { background: var(--bg-subtle); color: var(--ink-secondary); }

.err-list { margin: 4px 0 0; padding-left: 16px; color: var(--err); font-size: 12px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-secondary); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--ink-primary);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 75, 0.12);
}
.field-hint { margin-top: 4px; font-size: 11.5px; color: var(--ink-muted); }

/* ---------- Switch ---------- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #fafbf9;
  margin-bottom: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-bottom: 14px;
}
.notice-info { background: var(--bg-subtle); color: var(--ink-secondary); }
.notice-warn { background: var(--warn-soft); color: #854d0e; }

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}
.metric-label { display: block; font-size: 11.5px; color: var(--ink-muted); }
.metric-val { font-size: 18px; font-weight: 700; }

.empty { text-align: center; padding: 24px; color: var(--ink-muted); font-size: 13px; }

/* ---------- Modal & Toast ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: 16px 18px; overflow-y: auto; }
pre.json-view {
  margin: 0;
  padding: 14px;
  background: #14171a;
  color: #e6edf3;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-x: auto;
}

.toast-box {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink-primary);
  color: #fff;
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  max-width: 380px;
}
.toast.ok { background: #14532d; }
.toast.err { background: #991b1b; }
