/* =========================================================
   Автооптимист · Прайс-скан — стили
   Светлая тема по умолчанию, тёмная — через [data-theme="dark"]
   ========================================================= */

:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f2f5f8;
  --surface-3: #e8edf2;
  --border: #d6dde4;
  --text: #18212b;
  --text-muted: #64717f;
  --primary: #1b63d6;
  --primary-hover: #1653b8;
  --primary-soft: rgba(27, 99, 214, 0.1);
  --accent: #2b3a4a;
  --danger: #cf4040;
  --danger-hover: #b23636;
  --success: #268a52;
  --warning: #b8811c;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 6px 20px rgba(20, 30, 45, 0.07);
  --radius: 12px;
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171b21;
  --surface-2: #1e242c;
  --surface-3: #262e38;
  --border: #303a45;
  --text: #e7ecf1;
  --text-muted: #97a3af;
  --primary: #4c8df0;
  --primary-hover: #629cf3;
  --primary-soft: rgba(76, 141, 240, 0.14);
  --accent: #cbd6e2;
  --danger: #e06060;
  --danger-hover: #e87676;
  --success: #46b878;
  --warning: #d6a13e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Layout ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.region-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 0;
  z-index: 20;
}

.tab-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

/* ---------- Cards & forms ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 640px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  main {
    padding: 16px;
  }
  .app-header {
    padding: 14px 16px;
  }
  .tabs {
    padding: 0 6px;
  }
  .card {
    padding: 18px;
  }
}

input,
textarea,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 12px;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364717f' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

textarea {
  min-height: 68px;
  resize: vertical;
}

#workType {
  min-height: 60px;
  font-size: 16px;
  font-weight: 500;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 650;
  padding: 12px 20px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  line-height: 1.2;
}

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

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

.btn.block {
  width: 100%;
}

.btn.big {
  padding: 15px 22px;
  font-size: 16px;
  border-radius: 12px;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn.secondary:hover {
  background: var(--surface-3);
}

.btn.danger {
  background: var(--danger);
}

.btn.danger:hover {
  background: var(--danger-hover);
}

.btn.small {
  padding: 7px 13px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Status / alerts ---------- */

.alert {
  border-radius: 9px;
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 14px;
}

.alert.error {
  background: rgba(207, 64, 64, 0.12);
  color: var(--danger);
  border: 1px solid rgba(207, 64, 64, 0.3);
}

.alert.success {
  background: rgba(38, 138, 82, 0.12);
  color: var(--success);
  border: 1px solid rgba(38, 138, 82, 0.3);
}

.hidden {
  display: none !important;
}

.search-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 16px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Result ---------- */

.source-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.source-line.from-price {
  background: rgba(38, 138, 82, 0.12);
  color: var(--success);
  border: 1px solid rgba(38, 138, 82, 0.3);
}

.source-line.from-claude {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--border);
}

.source-line .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.price-hero {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.price-hero .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.price-hero .price-input-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
}

.price-hero input {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  border: none;
  background: none;
  padding: 0;
  width: 100%;
  color: var(--text);
}

.price-hero input:focus {
  outline: none;
}

.price-hero .cur {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .price-hero input {
    font-size: 34px;
  }
  .price-hero .cur {
    font-size: 24px;
  }
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.result-metric {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
}

.result-metric .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
}

.result-metric .value {
  font-size: 19px;
  font-weight: 700;
  margin-top: 4px;
}

.summary-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 13px 15px;
  font-size: 14px;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
}

.badge.high {
  color: var(--success);
  border-color: rgba(38, 138, 82, 0.4);
}

.badge.mid {
  color: var(--warning);
  border-color: rgba(184, 129, 28, 0.4);
}

.badge.low {
  color: var(--danger);
  border-color: rgba(207, 64, 64, 0.4);
}

/* ---------- Car picker ---------- */

.car-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) {
  .car-picker {
    grid-template-columns: 1fr;
  }
}

.manual-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.manual-row input {
  flex: 1;
}

.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  padding: 6px 0 0;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 760px;
}

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

th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

tbody tr:last-child td {
  border-bottom: none;
}

td input.price-input {
  width: 110px;
  padding: 7px 9px;
}

.muted {
  color: var(--text-muted);
}

.empty {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- History list ---------- */

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.history-item .top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: baseline;
}

.history-item .work {
  font-weight: 650;
}

.history-item .price {
  font-weight: 750;
  white-space: nowrap;
  font-size: 16px;
}

.history-item .meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 5px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.tag.price {
  color: var(--success);
  border-color: rgba(38, 138, 82, 0.4);
  background: rgba(38, 138, 82, 0.1);
}

.tag.claude {
  color: var(--primary);
  border-color: var(--border);
  background: var(--primary-soft);
}

/* ---------- Auth overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.overlay .card {
  max-width: 360px;
  width: 100%;
  margin: 0;
}

.overlay .brand-mark {
  margin-bottom: 12px;
}
