:root {
  --primary: #0b57d0;
  --primary-strong: #083f9c;
  --background: #f6f7f9;
  --surface: #ffffff;
  --surface-low: #eef1f5;
  --surface-high: #e7ebf0;
  --text: #171b20;
  --muted: #5d6675;
  --outline: #d4d9e2;
  --ok: #0f6b3b;
  --ok-bg: #d9f4e4;
  --error: #a42323;
  --error-bg: #ffe0dd;
  --warn-bg: #fff4cc;
  --sidebar-w: 248px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
button, input, textarea { font: inherit; }
select { font: inherit; }
.material-symbols-outlined { font-size: 20px; line-height: 1; vertical-align: middle; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--outline);
  display: flex;
  flex-direction: column;
  padding: 18px 0;
  z-index: 20;
}
.brand { padding: 6px 24px 24px; }
.brand h1 { margin: 0; color: var(--primary); font-size: 21px; font-weight: 800; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.sidebar nav { flex: 1; padding: 0 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
.nav-item.active { background: #dbe7ff; color: var(--primary-strong); }
.profile-nav {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--outline);
}
.profile-nav p {
  margin: 0 10px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.profile-link {
  display: grid;
  grid-template-columns: 20px 1fr 18px;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.profile-link:hover { background: var(--surface-low); color: var(--text); }
.profile-link.active { background: var(--ok-bg); color: var(--ok); }
.profile-link .lock {
  font-size: 17px;
  justify-self: end;
}
.profile-empty {
  display: block;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}
.side-foot { display: grid; gap: 8px; padding: 0 16px; }
.side-foot form { width: 100%; }
.side-foot .logout-btn { width: 100%; }
.profile-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: var(--sidebar-w);
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  z-index: 10;
}
.brand-sm { display: none; font-weight: 800; color: var(--primary); }
.search { position: relative; flex: 1; max-width: 520px; }
.search .material-symbols-outlined {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--muted);
}
.search input {
  width: 100%;
  border: 0;
  border-radius: 999px;
  background: var(--surface-low);
  padding: 10px 16px 10px 42px;
  outline: none;
}
.search input:focus { box-shadow: 0 0 0 2px var(--primary); }

.app-main { margin-left: var(--sidebar-w); padding-top: var(--topbar-h); min-height: 100vh; }
.canvas { max-width: 1160px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 30px; line-height: 1.15; }
.sub, .muted { color: var(--muted); }
.sub { margin: 4px 0 0; font-size: 14px; }

.btn, .btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--outline);
  background: var(--surface-low);
  color: var(--text);
  border-radius: 8px;
  min-height: 36px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover, .btn-primary:hover { background: var(--surface-high); }
.btn.accent, .btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.accent:hover, .btn-primary:hover { background: var(--primary-strong); }
.btn-primary { width: 100%; }
.btn.danger {
  background: var(--error-bg);
  border-color: #efb0aa;
  color: var(--error);
}
.btn.danger:hover {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.btn.logout-btn {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.btn.logout-btn:hover {
  background: #7f1717;
  border-color: #7f1717;
  color: #fff;
}
.btn.logout-btn .material-symbols-outlined {
  color: inherit;
}

.flash {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid #b8dfc8;
  background: var(--ok-bg);
  border-radius: 8px;
  color: var(--ok);
}
.error-flash {
  border-color: #efb0aa;
  background: var(--error-bg);
  color: var(--error);
}

.add-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) 120px 130px 85px minmax(170px, 1fr) auto;
  gap: 10px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.add-check {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.add-check input { width: auto; }
.field label, .field > label { color: var(--muted); font-size: 12px; font-weight: 700; }
.field input, .field textarea, .field select, .edit-form input, .edit-form textarea {
  width: 100%;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  outline: none;
}
.field textarea {
  min-height: 86px;
  resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus, .edit-form input:focus, .edit-form textarea:focus { border-color: var(--primary); }

.facet { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 12px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.product-list { display: grid; gap: 10px; }
.product-row {
  display: grid;
  grid-template-columns: 76px 1fr minmax(96px, 120px) auto;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 12px;
}
.product-row.hit { border-color: #95d7ad; background: linear-gradient(0deg, rgba(217,244,228,.45), rgba(255,255,255,.9)); }
.thumb {
  width: 76px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-low);
  color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-title h3 { margin: 0; font-size: 16px; line-height: 1.25; }
.row-title h3 a { color: var(--text); }
.product-main p { margin: 4px 0; }
.price-line { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); }
.price-line strong { color: var(--text); font-size: 16px; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-low);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.error { background: var(--error-bg); color: var(--error); }
.muted-pill { opacity: .75; }
.error-text { color: var(--error); font-size: 13px; }
.price-change {
  min-height: 48px;
  border-radius: 8px;
  background: var(--surface-low);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 7px 8px;
  line-height: 1.1;
}
.price-change strong {
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}
.price-change span {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
}
.price-change.down {
  background: var(--ok-bg);
  color: var(--ok);
}
.price-change.down strong { color: var(--ok); }
.price-change.up {
  background: var(--error-bg);
  color: var(--error);
}
.price-change.up strong { color: var(--error); }
.price-change.same strong { color: var(--muted); }
.price-change.empty-change span { margin-top: 0; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions .btn { width: 38px; padding: 0; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.runs {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 10px 14px;
}
.runs summary { cursor: pointer; font-weight: 800; }
.runs ul { list-style: none; padding: 0; margin: 10px 0 0; }
.runs li { border-top: 1px solid var(--outline); padding: 8px 0; font-size: 13px; }
.run-status {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-low);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.run-ok { background: var(--ok-bg); color: var(--ok); }
.run-sent { background: var(--ok-bg); color: var(--ok); }
.run-error { background: var(--error-bg); color: var(--error); }
.run-running { background: var(--warn-bg); color: #7b5a00; }
.run-pending { background: var(--warn-bg); color: #7b5a00; }

.empty {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  color: var(--muted);
  padding: 36px;
  text-align: center;
}

.back { display: inline-flex; align-items: center; gap: 5px; margin-bottom: 14px; font-weight: 800; }
.detail {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 26px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 22px;
}
.detail-cover img, .detail-cover .no-cover {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: contain;
  background: var(--surface-low);
}
.detail-cover .no-cover { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.detail-info h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; }
.detail-info .price { margin: 10px 0; font-size: 24px; font-weight: 800; }
.target-ok { color: var(--ok); font-weight: 800; }
.edit-form { display: grid; gap: 10px; max-width: 520px; margin: 18px 0 12px; }
.edit-form label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 800; }
.edit-form textarea { min-height: 80px; resize: vertical; }
.edit-form .check { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.edit-form .check input { width: auto; }
.history {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 18px;
}
.history h2 { margin: 0 0 12px; font-size: 20px; }
.settings-panel {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 18px;
}
.settings-panel-head {
  margin-bottom: 16px;
}
.settings-panel-head h3 {
  margin: 0;
  font-size: 18px;
}
.settings-panel-head p {
  margin: 3px 0 0;
  font-size: 13px;
}
.settings-form {
  display: grid;
  grid-template-columns: minmax(240px, 1.2fr) 120px 120px;
  gap: 14px;
  align-items: end;
  max-width: 860px;
}
.settings-form.password-form {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  max-width: 620px;
}
.settings-form .grow { grid-column: span 1; }
.settings-form .field input, .settings-form .field select {
  width: 100%;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  outline: none;
}
.settings-form .field input:focus, .settings-form .field select:focus { border-color: var(--primary); }
.setting-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.hint {
  color: var(--muted);
  font-size: 12px;
}
.settings-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-start;
}
.test-mail-actions {
  margin-top: 10px;
}
.profile-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}
.profile-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border-bottom: 1px solid var(--outline);
}
.auth-body {
  min-height: 100vh;
  min-height: 100svh;
  background: var(--background);
  overflow-anchor: none;
}
.auth-shell {
  width: min(460px, calc(100vw - 32px));
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin: 0 auto;
  padding: clamp(32px, 12vh, 92px) 0 32px;
}
.auth-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 24px;
}
.auth-panel h1 {
  margin: 0;
  color: var(--primary);
  font-size: 28px;
}
.auth-panel p {
  margin: 6px 0 16px;
}
.auth-form {
  display: grid;
  gap: 12px;
}
.auth-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.auth-form input, .auth-form select {
  width: 100%;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  outline: none;
}
.auth-form input:focus, .auth-form select:focus {
  border-color: var(--primary);
}
.profile-create {
  margin-top: 16px;
  border-top: 1px solid var(--outline);
  padding-top: 14px;
}
.profile-create summary {
  cursor: pointer;
  font-weight: 800;
  margin-bottom: 12px;
}
.chart-wrap {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
  margin: 0 0 16px;
}
.price-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 220px;
}
.chart-grid {
  stroke: var(--outline);
  stroke-width: 1;
}
.chart-label, .chart-date {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.chart-area {
  fill: rgba(11, 87, 208, .08);
}
.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-point {
  fill: var(--surface);
  stroke: var(--primary);
  stroke-width: 3;
}
.chart-empty {
  border: 1px dashed var(--outline);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
  margin-bottom: 16px;
  text-align: center;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-top: 1px solid var(--outline); padding: 9px 8px; }
th { color: var(--muted); font-size: 12px; }

@media (max-width: 1020px) {
  .sidebar { display: none; }
  .topbar { left: 0; }
  .brand-sm { display: inline; }
  .app-main { margin-left: 0; }
  .add-panel { grid-template-columns: 1fr 1fr; }
  .add-panel .grow, .add-check { grid-column: span 2; }
  .settings-form { grid-template-columns: 1fr 1fr; }
  .settings-form .grow, .settings-actions { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .canvas { padding: 16px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .add-panel { grid-template-columns: 1fr; }
  .add-panel .grow, .add-check { grid-column: auto; }
  .settings-form { grid-template-columns: 1fr; }
  .product-row { grid-template-columns: 56px 1fr; }
  .thumb { width: 56px; }
  .price-change { grid-column: 1 / -1; min-height: 42px; align-items: flex-start; padding: 8px 10px; }
  .row-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .two-col, .detail { grid-template-columns: 1fr; }
}
