* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #07080d;
  --bg-soft: #10141c;
  --bg-card: #161b26;
  --border: #242b3a;
  --text: #e7eaf3;
  --text-dim: #9aa2b8;
  --accent: #ff6b35;
  --accent-soft: rgba(255, 107, 53, 0.12);
  --on-accent: #ffffff;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

html, body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(ellipse at top, rgba(255, 107, 53, 0.06), transparent 60%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Header ===== */
.app-header {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.logo svg {
  color: var(--accent);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  flex-shrink: 0;
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.main-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(255, 107, 53, 0.4);
}

/* ===== Main ===== */
.app-main {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.app-footer {
  text-align: center;
  padding: 16px;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

/* ===== Cards & Layout ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 12px;
  color: var(--text);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.view-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.view-subtitle {
  color: var(--text-dim);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

/* ===== Buttons ===== */
.btn {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }

.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); filter: none; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ===== Search & Filters ===== */
.search-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.search-input {
  flex: 1;
  min-width: 220px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

.chip-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 13px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:hover { color: var(--text); }
.chip-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-easy { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.badge-medium { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-hard { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.badge-cat {
  background: rgba(96, 165, 250, 0.15);
  color: var(--blue);
}

/* ===== Lists ===== */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--bg-soft);
  cursor: pointer;
  transition: border-color 0.15s;
}

.list-item:hover { border-color: var(--accent); }

.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; margin-bottom: 3px; }
.list-item-sub { color: var(--text-dim); font-size: 0.85rem; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 640px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: modalIn 0.18s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover { color: var(--text); background: var(--bg-soft); }

/* ===== Forms ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }

.form-group textarea { min-height: 80px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== Steps & Guides ===== */
.step-list {
  list-style: none;
  counter-reset: step;
}

.step-list li {
  counter-increment: step;
  padding: 10px 0 10px 44px;
  position: relative;
  color: var(--text);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
}

.step-list li:last-child { border-bottom: none; }

.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 10px;
  width: 28px;
  height: 28px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.tool-list, .part-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-tag, .part-tag {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.callout {
  background: var(--bg-soft);
  border-left: 3px solid var(--yellow);
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
  margin: 14px 0;
  font-size: 0.9rem;
}

/* ===== Stats ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.stat-card .stat-label {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-card .stat-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  opacity: 0.8;
  margin-top: 2px;
}

/* ===== Tables ===== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  color: var(--text-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

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

tr:hover td { background: var(--bg-soft); }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state p { margin-bottom: 16px; }

/* ===== Diagnostics ===== */
.symptom-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.diag-result {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.diag-score {
  font-weight: 700;
  color: var(--accent);
}

/* ===== Maintenance ===== */
.maintenance-chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.mc-overdue { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.mc-soon { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.mc-ok { background: rgba(52, 211, 153, 0.15); color: var(--green); }

/* ===== Bike brand picker ===== */
.active-bike {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.active-bike .badge {
  font-size: 0.9rem;
  padding: 5px 12px;
}

.brand-picker {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.brand-picker label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.brand-chip {
  font-size: 0.9rem;
  padding: 9px 16px;
  font-weight: 700;
}

.model-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.model-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ===== Spec sheet ===== */
.spec-sheet {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.spec-title {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.spec-cell {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.spec-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.spec-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.spec-note {
  margin-top: 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(255, 107, 53, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text);
}

.spec-disclaimer {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.85;
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 12px 16px;
    padding: 12px 16px;
  }
  .app-header .logo { grid-column: 1; grid-row: 1; min-width: 0; }
  .app-header .logo h1 { font-size: 1.1rem; }
  .app-header .nav-assistant { grid-column: 2; grid-row: 1; justify-self: end; align-self: start; margin-top: 2px; }
  .app-header .main-nav { grid-column: 1 / -1; grid-row: 2; width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-btn { min-width: 0; padding-inline: 8px; }
  .app-main { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .grid-4.dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card, .stat-card, .list-item, .diag-result, .spec-cell { min-width: 0; }
  .search-row { align-items: stretch; }
  .search-input { min-width: 0; width: 100%; flex-basis: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .spec-grid { grid-template-columns: minmax(0, 1fr); }
  .list-item-sub, .spec-value, .monospace { overflow-wrap: anywhere; }

  .parts-table,
  .parts-table tbody,
  .parts-table tr,
  .parts-table td {
    display: block;
    width: 100%;
  }

  .parts-table thead { display: none; }

  .parts-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }

  .parts-table tr:last-child { border-bottom: 0; }

  .parts-table td {
    max-width: none;
    padding: 0;
    border: 0;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .parts-table td:first-child {
    grid-column: 1 / -1;
    font-size: 1rem;
  }

  .bike-parts-table td:nth-child(2),
  .bike-parts-table td:nth-child(3),
  .all-parts-table td:nth-child(2),
  .all-parts-table td:nth-child(3),
  .all-parts-table td:nth-child(4) {
    grid-column: 1 / -1;
  }

  .bike-parts-table td:nth-child(4),
  .all-parts-table td:nth-child(5) {
    grid-column: 1;
    align-self: center;
    font-size: 1rem;
  }

  .bike-parts-table td:nth-child(5),
  .all-parts-table td:nth-child(6) {
    grid-column: 2;
    justify-self: end;
  }

  .all-parts-table td:nth-child(7) {
    grid-column: 1 / -1;
  }

  .all-parts-table td:nth-child(7) .btn { width: 100%; }

  .tbl,
  .tbl tbody,
  .tbl tr,
  .tbl td {
    display: block;
    width: 100%;
  }

  .tbl thead { display: none; }
  .tbl tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .tbl tr:last-child { border-bottom: 0; }
  .tbl td { max-width: none; padding: 3px 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .tbl td:first-child { font-weight: 700; }

  .modal-overlay { padding: 16px 10px; }
  .modal { padding: 18px; min-width: 0; }
  .modal-body > div[style*="display:flex"] { flex-wrap: wrap; }
}

/* ===== Misc ===== */
.monospace { font-family: Consolas, monospace; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* ===== AI Assistant ===== */
.nav-assistant {
  border: 1px solid rgba(255, 107, 53, 0.35);
  color: var(--accent);
}

.chat-window {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 780px;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px 2px;
}

.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid rgba(255, 107, 53, 0.4);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.chat-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
  line-height: 1.5;
  max-width: 82%;
}

.chat-msg.user .chat-bubble {
  background: var(--accent-soft);
  border-color: rgba(255, 107, 53, 0.3);
  color: var(--text);
}

.chat-suggest-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-sugg {
  font-size: 0.8rem;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input {
  flex: 1;
  min-width: 0;
}