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

:root {
  --navy: #1a2a4a;
  --navy-light: #243560;
  --red: #cc0000;
  --green: #1e7e34;
  --amber: #c17a00;
  --grey: #555;
  --light-grey: #f5f6f8;
  --border: #e0e3e8;
  --white: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.1);
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--light-grey); min-height: 100vh; }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--navy); }
.login-container { background: var(--white); border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 8px 32px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-brand-mark { font-size: 3rem; font-weight: 900; color: var(--navy); letter-spacing: -2px; }
.login-title { font-size: 1.25rem; font-weight: 700; color: var(--navy); margin-top: .5rem; }
.login-subtitle { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }
.login-form .form-group { margin-bottom: 1rem; }
.login-form label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .375rem; color: var(--navy); }
.login-form input { width: 100%; padding: .75rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 1rem; outline: none; transition: border-color .15s; }
.login-form input:focus { border-color: var(--navy); }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: -100%; width: var(--sidebar-w);
  height: 100dvh; background: var(--navy); color: var(--white);
  display: flex; flex-direction: column; z-index: 100;
  transition: left .25s ease; overflow-y: auto;
}
.sidebar.open { left: 0; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; }
.sidebar-overlay.open { display: block; }

.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo { font-size: 1.5rem; font-weight: 900; letter-spacing: -1px; }
.sidebar-close { background: none; border: none; color: var(--white); font-size: 1.25rem; cursor: pointer; padding: .25rem; }

.sidebar-user { display: flex; align-items: center; gap: .75rem; padding: 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.user-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--navy-light); border: 2px solid rgba(255,255,255,.3); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; flex-shrink: 0; }
.user-name { font-weight: 600; font-size: .9rem; }
.user-role { font-size: .7rem; opacity: .7; text-transform: capitalize; }

.nav-list { list-style: none; padding: .5rem 0; flex: 1; }
.nav-section { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: .75rem 1rem .25rem; opacity: .5; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .65rem 1rem; color: rgba(255,255,255,.85); text-decoration: none; font-size: .9rem; border-radius: 0; transition: background .15s; cursor: pointer; border: none; background: none; width: 100%; text-align: left; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.12); color: var(--white); }
.nav-icon { width: 18px; text-align: center; font-size: 1rem; }

.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255,255,255,.1); margin-top: auto; }
.offline-badge { background: var(--red); color: white; font-size: .7rem; font-weight: 700; padding: .25rem .75rem; border-radius: 20px; margin-bottom: .5rem; text-align: center; }
.logout-link { color: rgba(255,255,255,.7) !important; font-size: .85rem; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar-h); background: var(--white); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: 0 1rem; box-shadow: var(--shadow); }
.hamburger { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--navy); padding: .25rem; flex-shrink: 0; }
.page-title { font-size: 1.1rem; font-weight: 700; color: var(--navy); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-indicator { font-size: .75rem; font-weight: 600; }
.sync-indicator.offline { color: var(--red); }
.sync-indicator.online { color: var(--green); }

/* ── Main layout ──────────────────────────────────────────────────────────── */
.main-content { min-height: 100dvh; }
.content-area { padding: 1rem; max-width: 960px; }

/* Desktop sidebar always visible */
@media (min-width: 768px) {
  .sidebar { left: 0; }
  .sidebar-close, .sidebar-overlay { display: none !important; }
  .with-sidebar { margin-left: var(--sidebar-w); }
  .content-area { padding: 1.5rem 2rem; }
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: .75rem 1rem; font-weight: 700; font-size: .9rem; background: var(--light-grey); border-bottom: 1px solid var(--border); color: var(--navy); }
.card-header--warning { background: #fff8e1; border-bottom-color: #ffe082; color: var(--amber); }
.card-body { padding: 1rem; }
.card-footer { padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--light-grey); }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }

/* ── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 480px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.stat-card--warning { border-color: #ffe082; background: #fff8e1; }
.stat-card--danger { border-color: #ffcdd2; background: #fff5f5; }
.stat-card--good { border-color: #c8e6c9; background: #f1f8e9; }
.stat-value { font-size: 2rem; font-weight: 900; color: var(--navy); line-height: 1; }
.stat-card--warning .stat-value { color: var(--amber); }
.stat-card--danger .stat-value { color: var(--red); }
.stat-card--good .stat-value { color: var(--green); font-size: 1.75rem; }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; font-weight: 600; }

/* ── Action row ───────────────────────────────────────────────────────────── */
.action-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1.1rem; border-radius: var(--radius); font-size: .875rem; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; text-decoration: none; transition: all .15s; white-space: nowrap; line-height: 1; }
.btn-primary { background: var(--navy); color: var(--white); border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-light); }
.btn-secondary { background: #e8ecf5; color: var(--navy); border-color: #d0d7e8; }
.btn-secondary:hover { background: #d0d7e8; }
.btn-outline { background: var(--white); color: var(--navy); border-color: var(--border); }
.btn-outline:hover { border-color: var(--navy); }
.btn-full { width: 100%; }
.btn-lg { padding: .875rem 1.5rem; font-size: 1rem; }
.btn-sm { padding: .35rem .65rem; font-size: .78rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th { padding: .6rem .75rem; text-align: left; font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid var(--border); white-space: nowrap; }
.table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: var(--light-grey); }
.empty-row { text-align: center; color: var(--text-muted); padding: 2rem !important; }
.row-inactive td { opacity: .45; }
.action-cell { white-space: nowrap; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 20px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.badge--lg { font-size: .85rem; padding: .3rem .85rem; }
.badge--pass { background: #d4edda; color: #155724; }
.badge--fail { background: #f8d7da; color: #721c24; }
.badge--role { background: #e8ecf5; color: var(--navy); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: .875rem; }
.form-group label { display: block; font-size: .83rem; font-weight: 600; margin-bottom: .3rem; color: var(--navy); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: .65rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: .95rem; font-family: var(--font); outline: none; transition: border-color .15s; background: var(--white);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--navy); }
.full-width { width: 100%; }
.readonly-field { background: var(--light-grey) !important; color: var(--text-muted); }
.hint { font-size: .75rem; font-weight: 400; color: var(--text-muted); }
.form-stacked .form-group { margin-bottom: .875rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; padding: 1rem 0; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; padding: 1rem; }
@media (min-width: 500px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-group--wide { grid-column: 1 / -1; }
.form-stacked { padding: 1rem; }

/* ── Inspection form checks ───────────────────────────────────────────────── */
.checks-form { padding: .5rem 0; }
.check-row { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.check-row:last-child { border-bottom: none; }
.check-row-label { font-size: .9rem; font-weight: 600; color: var(--text); margin-bottom: .5rem; }
.check-row-controls { display: flex; gap: .5rem; }
.radio-btn { display: flex; align-items: center; gap: .35rem; cursor: pointer; }
.radio-btn input { display: none; }
.radio-btn span {
  padding: .4rem .9rem; border-radius: 20px; font-size: .8rem; font-weight: 700;
  border: 2px solid var(--border); transition: all .12s; user-select: none;
}
.radio-btn--pass input:checked + span { background: var(--green); color: var(--white); border-color: var(--green); }
.radio-btn--fail input:checked + span { background: var(--red); color: var(--white); border-color: var(--red); }
.radio-btn span:hover { border-color: var(--navy); }
.check-note-box { margin-top: .5rem; animation: fadeIn .15s ease; }
.check-note-input { width: 100%; padding: .5rem; border: 1.5px solid var(--red); border-radius: var(--radius); font-size: .85rem; background: #fff5f5; resize: vertical; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Inspection detail ────────────────────────────────────────────────────── */
.detail-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.detail-header-left { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.cert-number { font-size: 1.1rem; font-weight: 700; color: var(--navy); }
.detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.type-chip { background: #e8ecf5; color: var(--navy); padding: .2rem .6rem; border-radius: 20px; font-size: .75rem; font-weight: 600; text-transform: capitalize; }
.detail-grid { display: grid; gap: 1rem; }
@media (min-width: 600px) { .detail-grid { grid-template-columns: 1fr 1fr; } }
.detail-table { padding: .5rem 0; }
.detail-row { display: flex; gap: 1rem; padding: .5rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; }
.detail-row:last-child { border-bottom: none; }
.detail-row span:first-child { font-weight: 600; color: var(--navy); min-width: 130px; flex-shrink: 0; }
.checks-list { padding: .5rem 0; }
.check-item { display: flex; flex-direction: column; padding: .6rem 1rem; border-bottom: 1px solid var(--border); gap: .25rem; }
.check-item:last-child { border-bottom: none; }
.check-item--fail { background: #fff5f5; }
.check-item--no { background: #fff5f5; }
.check-name { font-size: .875rem; font-weight: 600; }
.check-note { font-size: .8rem; color: var(--red); font-style: italic; }

/* ── Customer portal ──────────────────────────────────────────────────────── */
.customer-welcome { margin-bottom: 1rem; }
.customer-welcome h2 { font-size: 1.3rem; font-weight: 700; color: var(--navy); }
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; padding: 1rem; }
.status-card { background: var(--light-grey); border: 2px solid var(--border); border-radius: var(--radius); padding: .875rem; }
.status-card--pass { border-color: #c8e6c9; background: #f1f8e9; }
.status-card--fail { border-color: #ffcdd2; background: #fff5f5; }
.status-card-name { font-weight: 700; font-size: .9rem; margin-bottom: .35rem; }
.status-card-result { margin-bottom: .25rem; }
.status-card-date { font-size: .75rem; color: var(--text-muted); }

/* ── Two-column layout ────────────────────────────────────────────────────── */
.two-col-layout { display: grid; gap: 1rem; }
@media (min-width: 600px) { .two-col-layout { grid-template-columns: 340px 1fr; } }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: .35rem; }
.tab-btn { padding: .45rem .9rem; border-radius: calc(var(--radius) - 2px); border: none; background: none; font-size: .83rem; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.tab-btn.active { background: var(--navy); color: var(--white); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar { margin-bottom: .75rem; }
.filter-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter-input { padding: .55rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .875rem; min-width: 200px; flex: 1; }
.filter-select { padding: .55rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .875rem; background: var(--white); }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; font-weight: 500; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* ── Offline notice ───────────────────────────────────────────────────────── */
.offline-notice { background: #fff8e1; border: 1px solid #ffe082; border-radius: var(--radius); padding: .65rem 1rem; margin-bottom: .75rem; font-size: .85rem; font-weight: 600; color: var(--amber); display: flex; align-items: center; gap: .5rem; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--navy); color: var(--white); padding: .65rem 1.25rem; border-radius: 20px; font-size: .875rem; font-weight: 600; z-index: 999; opacity: 0; transition: all .3s; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: var(--red); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-box { background: var(--white); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 380px; }
.modal-box h3 { font-size: 1.1rem; color: var(--navy); margin-bottom: .75rem; }
.modal-actions { display: flex; gap: .5rem; margin-top: 1rem; }

/* ── Breadcrumb ───────────────────────────────────────────────────────────── */
.breadcrumb { font-size: .83rem; color: var(--text-muted); margin-bottom: .75rem; }
.breadcrumb a { color: var(--navy); text-decoration: none; }

/* ── Type label ───────────────────────────────────────────────────────────── */
.type-label { text-transform: capitalize; font-size: .83rem; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-warning { color: var(--amber); font-weight: 600; }
.text-danger { color: var(--red); font-weight: 600; }
.mono { font-family: 'Courier New', monospace; font-size: .85rem; }
.small { font-size: .8rem; }
.page-hint { color: var(--text-muted); font-size: .875rem; margin-bottom: 1rem; }
.current-logo-label { font-size: .8rem; color: var(--text-muted); margin-bottom: .35rem; }
.inspection-form { max-width: 720px; }
.inspection-form .card { margin-bottom: .75rem; }
