/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-header:    rgba(22, 78, 88, 0.92);
  --clr-nav:       rgba(18, 68, 78, 0.95);
  --clr-bg:        #fdfbf7;
  --clr-surface:   #fffdf6;
  --clr-border:    #c8b898;
  --clr-text:      #1a1208;
  --clr-muted:     #554433;
  --clr-accent:    #ffcc44;
  --clr-error:     #c0392b;
  --clr-teal-dark: rgba(15, 65, 75, 0.97);
  --clr-cream:     #f0e8d0;
  --nav-height:    60px;
  --header-height: 52px;
}

body {
  font-family: 'Segoe UI', Verdana, Arial, Helvetica, sans-serif;
  font-size: 14px;
  background: var(--clr-bg);
  color: var(--clr-text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  height: var(--header-height);
  background: var(--clr-header);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--clr-cream);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
}
header h1 { font-size: 1.1rem; font-weight: 600; flex: 1; letter-spacing: 0.02em; }

.header-logo-link { display: flex; align-items: center; flex-shrink: 0; }
.header-logo {
  height: 32px;
  border-radius: 5px;
  padding: 3px 7px;
  background: rgba(255, 253, 246, 0.92);
}
@media (max-width: 480px) {
  .header-logo { padding: 3px; border-radius: 6px; }
}

.header-actions { display: flex; gap: 0.5rem; }
.header-btn {
  background: rgba(255, 252, 242, 0.15);
  color: var(--clr-cream);
  border: 1px solid rgba(240, 232, 208, 0.4);
  border-radius: 5px;
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.header-btn:active { background: rgba(255, 252, 242, 0.28); }

/* ── Main content ─────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--clr-bg);
}

.loading { color: var(--clr-muted); text-align: center; padding: 2rem; }

/* ── Bottom nav ───────────────────────────────────────────────────────────── */
#bottom-nav {
  height: var(--nav-height);
  display: flex;
  background: var(--clr-nav);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(200, 184, 152, 0.3);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(240, 232, 208, 0.65);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-top: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.nav-btn.active {
  color: var(--clr-accent);
  border-top-color: var(--clr-accent);
}

/* ── Sub-nav (Bikes / Wheelsets within Stable) ───────────────────────────── */
.sub-nav {
  display: flex;
  border-bottom: 1px solid var(--clr-border);
  margin: -1rem -1rem 1rem;   /* bleed to edges of #main-content padding */
  background: var(--clr-surface);
}
.sub-nav-btn {
  flex: 1;
  padding: 0.625rem 0.5rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--clr-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.sub-nav-btn.active {
  color: var(--clr-text);
  border-bottom-color: var(--clr-accent);
}

/* ── Bike list ────────────────────────────────────────────────────────────── */
.bike-list { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }

.bike-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 0.875rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.bike-card:active { background: #f5f0e8; }
.bike-name { font-weight: 600; color: var(--clr-text); }
.bike-meta { font-size: 0.8rem; color: var(--clr-muted); }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 3rem 1rem;
  color: var(--clr-muted);
  text-align: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--clr-teal-dark);
  color: var(--clr-cream);
  border: 1px solid rgba(200, 184, 152, 0.4);
  border-radius: 5px;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }

.btn-fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 1rem);
  right: 1rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.6rem;
  padding: 0;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(15, 65, 75, 0.35);
}

/* ── Gear table ───────────────────────────────────────────────────────────── */
.gear-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.gear-table {
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 100%;
}
table.gear-table th,
table.gear-table td {
  border: 1px solid var(--clr-border);
  padding: 0.375rem 0.5rem;
  text-align: right;
  white-space: nowrap;
}
table.gear-table th {
  background: var(--clr-teal-dark);
  color: var(--clr-cream);
  text-align: center;
}
table.gear-table td:first-child {
  text-align: left;
  font-weight: 600;
  background: #f5f0e8;
  color: var(--clr-text);
}
table.gear-table tr:nth-child(even) td { background: #fdfaf3; }
table.gear-table tr:nth-child(even) td:first-child { background: #f5f0e8; }

/* ── Library list ─────────────────────────────────────────────────────────── */
.library-section { margin-bottom: 1.5rem; }
.library-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
  margin-bottom: 0.5rem;
}

.library-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.library-section-header h2 { margin-bottom: 0; }

.lib-collapse-btn {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.lib-chevron {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--clr-muted);
  transition: transform 0.18s;
}
.lib-collapse-btn.is-collapsed .lib-chevron {
  transform: rotate(-90deg);
}

.library-list { list-style: none; display: flex; flex-direction: column; gap: 0.375rem; }
.library-item {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 5px;
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}
.library-item .item-value { color: var(--clr-muted); }
.library-item .item-end   { display: flex; align-items: center; gap: 0.5rem; }

.library-add-form {
  margin-top: 0.5rem;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 0.75rem;
}
.library-add-form .form-row { margin-bottom: 0.625rem; }
.library-add-form .form-row:last-of-type { margin-bottom: 0; }
.library-add-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.625rem;
}

/* ── Placeholder views ────────────────────────────────────────────────────── */
.view-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--clr-muted);
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.form-section h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
  margin-bottom: 0.75rem;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.875rem;
}
.form-row:last-child { margin-bottom: 0; }

.form-row label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--clr-text);
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--clr-border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.95rem;
  background: rgba(255, 252, 242, 0.88);
  color: var(--clr-text);
}
.form-row input:focus,
.form-row select:focus {
  outline: 2px solid rgba(22, 78, 88, 0.55);
  outline-offset: 1px;
}
.form-hint {
  font-size: 0.75rem;
  color: var(--clr-muted);
}

.radio-group {
  display: flex;
  gap: 1.25rem;
}
.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.9rem;
  font-weight: normal;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 0.5rem 0 1rem;
}
.btn-secondary {
  background: var(--clr-surface);
  color: var(--clr-text);
  border: 1px solid var(--clr-border);
  border-radius: 5px;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-secondary:active { background: #f5f0e8; }

/* ── Error message ────────────────────────────────────────────────────────── */
.error-msg {
  color: var(--clr-error);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e8b4b0;
  border-radius: 5px;
  background: #fdf2f0;
  margin-bottom: 0.75rem;
}

/* ── Section headings in calculator ──────────────────────────────────────── */
#calc-results h3 {
  color: var(--clr-teal-dark);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--clr-border);
  padding-bottom: 0.25rem;
}

/* ── Fitted cell highlight in gear tables ────────────────────────────────── */
table.gear-table td.cell-fitted {
  background: rgba(255, 204, 68, 0.28) !important;
  font-weight: 700;
}

/* ── Parts pool section ──────────────────────────────────────────────────── */
.pool-subsection { margin-bottom: 0.875rem; }
.pool-subsection:last-child { margin-bottom: 0; }
.pool-subsection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.375rem;
}
.pool-subsection-header strong { font-size: 0.875rem; color: var(--clr-text); }

.pool-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }
.pool-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-radius: 4px;
  font-size: 0.875rem;
}
.pool-item.pool-fitted { background: rgba(255, 204, 68, 0.12); border-color: rgba(200, 160, 0, 0.4); }
.pool-empty { font-size: 0.8rem; color: var(--clr-muted); padding: 0.25rem 0; list-style: none; }
.pool-tag {
  font-size: 0.7rem;
  color: var(--clr-muted);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  vertical-align: middle;
}

/* ── Bike detail view ────────────────────────────────────────────────────── */
.detail-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--clr-border);
  font-size: 0.875rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--clr-muted); flex-shrink: 0; }
.detail-empty { color: var(--clr-muted); font-size: 0.875rem; padding: 0.25rem 0; }

/* ── Help text ───────────────────────────────────────────────────────────── */
.help-text {
  margin: 2rem 0 1rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--clr-border);
  color: var(--clr-muted);
  font-size: 0.8rem;
  line-height: 1.6;
}
.help-text p + p { margin-top: 0.5rem; }

/* ── Assigned wheelset rows ──────────────────────────────────────────────── */
.wheelset-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--clr-border);
}
.wheelset-row:last-of-type { border-bottom: none; }
.wheelset-row.is-active {
  background: rgba(255, 204, 68, 0.08);
  border-radius: 4px;
  padding: 0.5rem 0.375rem;
  margin: 0 -0.375rem;
}
.wheelset-row-info { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; }
.wheelset-row-name { font-weight: 600; font-size: 0.875rem; }
.wheelset-row-meta { font-size: 0.775rem; color: var(--clr-muted); }
.wheelset-row-actions { display: flex; gap: 0.375rem; flex-shrink: 0; }

.badge-active {
  display: inline-block;
  background: var(--clr-accent);
  color: #1a1208;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  vertical-align: middle;
}

/* ── Small buttons ───────────────────────────────────────────────────────── */
.btn-sm {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--clr-border);
  background: var(--clr-surface);
  color: var(--clr-text);
}
.btn-sm:active { background: #f5f0e8; }
.btn-sm.danger { color: var(--clr-error); border-color: #e8b4b0; }
.btn-sm.danger:active { background: #fdf2f0; }

/* ── Danger button (delete) ──────────────────────────────────────────────── */
.btn-danger {
  background: var(--clr-surface);
  color: var(--clr-error);
  border: 1px solid #e8b4b0;
  border-radius: 5px;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:active { background: #fdf2f0; }

/* ── Wheelset assign picker ──────────────────────────────────────────────── */
.assign-picker { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.375rem; }
.picker-item {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.75rem;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
}
.picker-item:active { background: #f5f0e8; }

/* ── Maintenance view ────────────────────────────────────────────────────── */
.maint-settings {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--clr-border);
  margin-bottom: 0.75rem;
}
.maint-odometer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.maint-odometer input[type="number"] { width: 7rem; }

.component-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--clr-border);
}
.component-row:last-of-type { border-bottom: none; }
.status-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-green  { background: #2ecc71; }
.status-orange { background: #f39c12; }
.status-red    { background: #e74c3c; }
.component-info { flex: 1; min-width: 0; }
.component-name { font-weight: 600; font-size: 0.95rem; }
.component-progress {
  font-size: 0.78rem;
  color: var(--clr-muted);
  margin-top: 0.1rem;
}
.component-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.history-section { margin-top: 1.5rem; }
.history-toggle {
  background: none;
  border: none;
  font-size: 0.875rem;
  color: var(--clr-muted);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.history-entry {
  font-size: 0.8rem;
  color: var(--clr-muted);
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  gap: 0.75rem;
}
.history-entry:last-child { border-bottom: none; }
.history-date { flex-shrink: 0; font-weight: 600; }
.history-odo  { opacity: 0.7; }

.maint-section-heading {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--clr-muted);
  margin: 1rem 0 0.4rem;
}

/* Replace confirmation mini-form */
.replace-form {
  background: var(--clr-cream);
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}
