/* SMA Command Center - Light theme (v2): white/gray surfaces, Sharp Red accent (#ab272c). */

:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #f1f1f3;
  --surface-hover: #e7e7ea;
  --border: #e1e1e5;
  --text: #1c1c1f;
  --text-dim: #56565d;
  --text-faint: #8b8b92;
  --red: #ab272c;
  --red-hover: #931f24;
  --red-dim: rgba(171, 39, 44, 0.1);
  --green: #2e9c5c;
  --amber: #a97a1f;
  --yellow: #9c7a00;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(20, 20, 24, 0.08);
  --sidebar-w: 240px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
p { margin: 0 0 8px; color: var(--text-dim); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
}
.sidebar .brand .mark {
  width: 32px; height: 32px;
  background: var(--red);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 15px;
}
.sidebar .brand .name { font-weight: 700; font-size: 14.5px; line-height: 1.2; }
.sidebar .brand .sub { font-size: 11px; color: var(--text-faint); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 17px; height: 17px; opacity: 0.85; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--red-dim); color: var(--red); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border);
}
.sidebar-footer .who { flex: 1; min-width: 0; }
.sidebar-footer .who .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who .r { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }
.logout-btn { background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 6px; border-radius: 8px; }
.logout-btn:hover { background: var(--surface-hover); color: var(--text); }

.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px;
  max-width: 1400px;
}

.page-header { margin-bottom: 28px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-header h1 { font-size: 22px; }
.page-header p { margin: 0; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-card { padding: 18px 20px; }
.stat-card .label { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .delta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-danger { color: var(--red); border-color: rgba(171,39,44,0.3); background: rgba(171,39,44,0.06); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--surface-2); cursor: pointer; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-draft { background: var(--surface-2); color: var(--text-dim); }
.badge-sent { background: rgba(217,164,65,0.15); color: var(--amber); }
.badge-approved { background: rgba(63,181,111,0.15); color: var(--green); }
.badge-declined { background: rgba(171,39,44,0.1); color: var(--red); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-faint); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--red); }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 380px; padding: 36px 32px; }
.login-card .mark { width: 44px; height: 44px; background: var(--red); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 19px; margin-bottom: 18px; }
.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card p { margin-bottom: 24px; font-size: 13px; }
.error-text { color: var(--red); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* Utility */
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.spacer { flex: 1; }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; } .mb-16 { margin-bottom: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-faint); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.4; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { width: 480px; max-width: 92vw; max-height: 86vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.hidden { display: none !important; }

.total-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; }
.total-row.grand { font-size: 17px; font-weight: 700; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }
.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 10px; }
@media (max-width: 900px) { .item-row { grid-template-columns: 1fr; } }

/* Inspections */
.template-pick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 700px) { .template-pick-grid { grid-template-columns: 1fr; } }
.template-card { cursor: pointer; padding: 24px 20px; border: 1px solid var(--border); transition: border-color 0.15s, background 0.15s; }
.template-card:hover { border-color: var(--red); background: var(--surface-hover); }
.template-card h3 { margin-bottom: 6px; }

.inspection-progress { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 12px 0; margin-bottom: 8px; }
.progress-bar-track { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--red); transition: width 0.2s; }

.inspection-item { padding: 16px; border-bottom: 1px solid var(--border); }
.inspection-item:last-child { border-bottom: none; }
.inspection-item .item-label { font-weight: 600; font-size: 14.5px; margin-bottom: 2px; }
.inspection-item .item-hint { font-size: 12px; color: var(--text-faint); margin-bottom: 10px; }

/* Color key / legend, shown at the top of every inspection form */
.status-legend { display: flex; flex-wrap: wrap; gap: 18px; padding: 12px 16px; margin-bottom: 16px; }
.status-legend .legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.legend-swatch { width: 18px; height: 18px; border-radius: 5px; flex-shrink: 0; }
.legend-swatch.ok { background: var(--green); }
.legend-swatch.attention { background: var(--yellow); }
.legend-swatch.immediate { background: var(--red); }

.status-btn-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.status-btn {
  min-height: 52px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.05s;
}
.status-btn:active { transform: scale(0.97); }
.status-btn .checkbox-swatch {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.status-btn .checkbox-swatch svg { width: 14px; height: 14px; opacity: 0; }
.status-btn.ok .checkbox-swatch { border-color: var(--green); }
.status-btn.attention .checkbox-swatch { border-color: var(--yellow); }
.status-btn.immediate .checkbox-swatch { border-color: var(--red); }
.status-btn.ok.active { background: rgba(63,181,111,0.14); border-color: var(--green); color: var(--green); }
.status-btn.ok.active .checkbox-swatch { background: var(--green); }
.status-btn.attention.active { background: rgba(224,180,0,0.14); border-color: var(--yellow); color: var(--yellow); }
.status-btn.attention.active .checkbox-swatch { background: var(--yellow); }
.status-btn.immediate.active { background: rgba(171,39,44,0.12); border-color: var(--red); color: var(--red); }
.status-btn.immediate.active .checkbox-swatch { background: var(--red); }
.status-btn.active .checkbox-swatch svg { opacity: 1; color: #0c0c0d; }

/* Tire tread measurement group */
.tire-group-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
@media (max-width: 480px) { .tire-group-grid { grid-template-columns: 1fr 1fr; } }
.tire-input-field label { font-size: 11.5px; }
.tire-input-field input { text-align: center; font-weight: 600; }

.note-toggle { font-size: 12px; color: var(--text-faint); cursor: pointer; text-decoration: underline; }
.item-note-field { margin-top: 8px; }

.sticky-action-bar {
  position: sticky; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 14px 16px; margin: 16px -20px -20px; border-radius: 0 0 var(--radius) var(--radius);
  display: flex; gap: 10px;
}
.sticky-action-bar .btn { flex: 1; min-height: 46px; }

@media (max-width: 700px) {
  .main { padding: 16px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Star rating widget */
.star-rating-row { display: flex; gap: 6px; margin-bottom: 4px; }
.star-btn {
  width: 44px; height: 44px;
  border: none; background: none; cursor: pointer;
  color: var(--surface-2);
  padding: 4px;
  transition: transform 0.05s;
}
.star-btn svg { width: 100%; height: 100%; }
.star-btn:active { transform: scale(0.9); }
.star-btn.active { color: #d4af37; }
