:root {
  --bg: #0a0c11;
  --panel: #11141c;
  --panel-2: #161a24;
  --panel-3: #1c2130;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9ebf1;
  --muted: #8a90a2;
  --muted-2: #646b7d;
  --accent: #8b7cff;
  --accent-soft: rgba(139, 124, 255, 0.14);
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.13);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.13);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.13);
  --radius: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}
.glow-a { width: 520px; height: 520px; top: -220px; left: -140px; background: rgba(109, 94, 252, 0.28); }
.glow-b { width: 480px; height: 480px; bottom: -260px; right: -120px; background: rgba(45, 212, 191, 0.12); }

h1, h2, h3, p { margin: 0; }
a { color: inherit; }

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 22px clamp(18px, 4vw, 44px) 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 210px; }
.brand-mark { width: 40px; height: 40px; color: var(--accent); flex: none; }
.brand h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.brand p { font-size: 12px; color: var(--muted-2); letter-spacing: 0.02em; }

.stats { display: flex; gap: 8px; flex: 1; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.018);
  min-width: 82px;
}
.stat-value { font-size: 17px; font-weight: 620; font-variant-numeric: tabular-nums; }
.stat-value.accent { color: var(--green); }
.stat-label { font-size: 11px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.07em; }

.actions { display: flex; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 560;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--panel-3); border-color: rgba(255, 255, 255, 0.22); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, #9385ff, #7566f0);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow: 0 8px 22px rgba(117, 102, 240, 0.28);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, #9c8fff, #7e6ff5); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 9px; }

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  padding: 0 clamp(18px, 4vw, 44px) 60px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 12px;
  flex: 1 1 220px;
  min-width: 180px;
}
.search svg { width: 16px; height: 16px; color: var(--muted-2); flex: none; }
.search input {
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  width: 100%;
  outline: none;
}
.search:focus-within { border-color: rgba(139, 124, 255, 0.5); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip.active {
  background: var(--accent-soft);
  border-color: rgba(139, 124, 255, 0.45);
  color: #cfc8ff;
}

.select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12.5px;
  outline: none;
}

.items { display: flex; flex-direction: column; gap: 12px; }

.card {
  position: relative;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) 190px;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.028), rgba(255, 255, 255, 0.008));
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.55;
}
.card[data-state="at_target"]::before { background: var(--green); opacity: 0.9; }
.card[data-state="close"]::before { background: var(--amber); }
.card[data-state="error"]::before { background: var(--red); }
.card:hover { border-color: var(--line-strong); transform: translateY(-1px); box-shadow: var(--shadow); }
.card.archived { opacity: 0.6; }

.thumb {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb span { font-size: 26px; font-weight: 620; color: var(--muted-2); }

.card-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.card-top { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.card-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { color: #cfc8ff; }
.card-meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.card-meta .dot::before { content: "·"; margin-right: 8px; color: var(--muted-2); }
.card-notes {
  font-size: 12.5px;
  color: var(--muted-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; flex-wrap: wrap; }

.price-block { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.price-now { font-size: 24px; font-weight: 650; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.price-target { font-size: 12px; color: var(--muted); }
.delta { font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px; }
.delta.good { color: var(--green); background: var(--green-soft); }
.delta.bad { color: var(--amber); background: var(--amber-soft); }
.delta.neutral { color: var(--muted); background: rgba(255, 255, 255, 0.05); }

.spark { width: 190px; height: 38px; margin-top: 2px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.spark path.area { opacity: 0.55; }
.spark .dot-now { fill: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.green { color: var(--green); background: var(--green-soft); border-color: rgba(74, 222, 128, 0.2); }
.badge.amber { color: var(--amber); background: var(--amber-soft); border-color: rgba(251, 191, 36, 0.2); }
.badge.red { color: var(--red); background: var(--red-soft); border-color: rgba(248, 113, 113, 0.22); }
.badge.muted { color: var(--muted); background: rgba(255, 255, 255, 0.045); border-color: var(--line); }
.badge.purple { color: #c3b9ff; background: var(--accent-soft); border-color: rgba(139, 124, 255, 0.25); }

.card-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--panel-3); border-color: var(--line-strong); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 80px 20px; border: 1px dashed var(--line-strong); border-radius: 20px; }
.empty-art { font-size: 44px; color: var(--accent); opacity: 0.7; margin-bottom: 8px; }
.empty h2 { font-size: 19px; margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 18px; font-size: 13.5px; }

.rail {
  position: sticky;
  top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.012));
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; }
.rail-head h2 { font-size: 14px; font-weight: 620; letter-spacing: 0.01em; }
.link { background: none; border: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 0; }
.link:hover { color: var(--accent); text-decoration: underline; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.alert:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.035); }
.alert.unread { border-left: 2px solid var(--accent); }
.alert.delivery-error { border-left-color: var(--red); }
.alert-top { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.alert-name { font-size: 12.8px; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-msg { font-size: 12px; color: var(--muted); }
.alert-time { font-size: 11px; color: var(--muted-2); }
.alert-empty { font-size: 12.5px; color: var(--muted-2); padding: 16px 4px; text-align: center; }

.rail-note { border-top: 1px solid var(--line); padding-top: 12px; font-size: 11.5px; color: var(--muted-2); }
.rail-note strong { color: var(--muted); display: block; margin-bottom: 3px; font-weight: 600; }

.modal {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.modal::backdrop { background: rgba(4, 5, 8, 0.72); backdrop-filter: blur(4px); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; font-weight: 620; }
.modal-body { padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: rgba(255, 255, 255, 0.015); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: rgba(139, 124, 255, 0.55); }
.field textarea { resize: vertical; min-height: 58px; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted-2); }

.advanced { border: 1px solid var(--line); border-radius: 11px; padding: 10px 13px; display: flex; flex-direction: column; gap: 12px; }
.advanced summary { cursor: pointer; font-size: 12.5px; color: var(--muted); user-select: none; }
.advanced[open] summary { color: var(--text); margin-bottom: 2px; }

.toggles { display: flex; gap: 16px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

.form-error { color: var(--red); font-size: 12.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--panel-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 50;
  max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(248, 113, 113, 0.5); }

.loader { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 40; }
.loader[hidden] { display: none; }
.loader span {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; max-height: none; order: 2; }
  .card { grid-template-columns: 72px minmax(0, 1fr) 160px; }
  .thumb { width: 72px; height: 72px; }
  .spark { width: 160px; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 14px; padding-bottom: 10px; }
  .brand { flex: 1; }
  .stats { order: 3; flex: 0 0 100%; width: 100%; gap: 6px; overflow: visible; }
  .stat { flex: 1 1 0; min-width: 0; padding: 6px 8px; }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 9.5px; letter-spacing: 0.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .actions { gap: 7px; }
  .btn span { display: none; }
  .btn { padding: 9px 11px; }
  .btn.primary span { display: inline; }
  .card { grid-template-columns: 58px minmax(0, 1fr); grid-template-areas: "thumb main" "price price"; }
  .thumb { width: 58px; height: 58px; grid-area: thumb; }
  .card-main { grid-area: main; }
  .price-block { grid-area: price; flex-direction: row; align-items: center; justify-content: space-between; text-align: left; padding-top: 10px; border-top: 1px solid var(--line); }
  .price-now { font-size: 20px; }
  .spark { width: 120px; height: 30px; margin: 0; }
  .card-actions { margin-left: 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .rail { order: 2; }
}

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