@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;600;700&family=Barlow:wght@400;500;600&family=JetBrains+Mono:wght@400;600&display=swap');

/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  /* Stertil-Koni brand colors */
  --red:        #CC1F28;
  --red-dark:   #A3181F;
  --red-light:  #E8252F;
  --navy:       #0F1923;
  --navy-mid:   #172230;
  --navy-light: #1F2E40;
  --steel:      #263B52;
  --border:     #2A3E58;
  --text:       #F0F4F8;
  --text-dim:   #90A8C0;
  --text-muted: #4A6480;
  --card-bg:    #172230;
  --input-bg:   #0F1923;
  --success:    #27AE60;
  --warning:    #F5A623;
  --error:      #E74C3C;
  --info:       #2980B9;
  --font-head:  'Barlow Condensed', sans-serif;
  --font-body:  'Barlow', sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
  --radius:     6px;
  --shadow:     0 2px 16px rgba(0,0,0,0.5);
  --nav-h:      52px;  /* matches the real header height (mobile + safe-area) so toast offset is correct */
  --bottom-nav: 64px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--navy);
  color: var(--text);
  min-height: 100vh;
  /* Default: leave room for bottom nav on all screens */
  padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  /* Prevent horizontal overflow on all devices */
  max-width: 100vw;
}

a { color: var(--red-light); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: var(--font-body);
  font-size: 1rem;
}

/* ============================================================
   LAYOUT
   ============================================================ */
#app { min-height: 100vh; }

.page { display: none; animation: fadeIn 0.2s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ============================================================
   TOP HEADER (authenticated pages)
   ============================================================ */
.top-header {
  background: var(--navy-mid);
  border-bottom: 2px solid var(--red);
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 8px;
}

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

.logo-mark {
  width: 32px;
  height: 32px;
  background: var(--red);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: white;
  flex-shrink: 0;
  border-bottom: 2px solid var(--red-dark);
}

.logo-text {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 1px;
  color: var(--text);
  text-transform: uppercase;
  line-height: 1;
}

.logo-sub {
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

@media (max-width: 479px) {
  .logo-text { display: none; }
  .logo-sub  { display: none; }
  .header-logo-img { height: 24px; }
}

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

.user-badge {
  background: var(--steel);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: none;
}

@media (min-width: 480px) { .user-badge { display: block; } }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  min-height: 36px;
}

.btn-logout:hover { border-color: var(--red); color: var(--red-light); }

/* ── Notifications bell + dropdown ── */
.notif-wrap { position: relative; }
.notif-bell {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 6px 9px;
  min-height: 36px;
  position: relative;
  transition: border-color 0.15s;
}
.notif-bell:hover { border-color: var(--red); }
.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.notif-modal-box { max-width: 460px; }
.notif-modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.notif-mark-all {
  background: transparent;
  border: none;
  color: var(--red-light);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 4px;
}
.notif-mark-all:hover { text-decoration: underline; }
.notif-list {
  max-height: 65vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.notif-loading,
.notif-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.notif-item {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--navy-light); }
.notif-item.unread { background: rgba(204,31,40,0.08); }
.notif-item-icon { font-size: 1.1rem; line-height: 1.3; flex-shrink: 0; }
.notif-item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-item-title {
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 400;
}
.notif-item.unread .notif-item-title { font-weight: 700; }
.notif-item-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.notif-item-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* ── Announcements (admin mass email) ── */
.announce-recipients {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.announce-radio {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
}
.announce-radio input { accent-color: var(--red); }
.announce-user-list {
  margin-top: 8px;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
}
.announce-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.announce-user-item:last-child { border-bottom: none; }
.announce-user-item:hover { background: var(--navy-light); }
.announce-user-item input { accent-color: var(--red); flex-shrink: 0; }
.announce-user-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.announce-user-name { font-size: 0.85rem; color: var(--text); }
.announce-user-meta { font-size: 0.75rem; color: var(--text-dim); }

/* ============================================================
   BOTTOM NAV (mobile)
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navy-mid);
  border-top: 2px solid var(--border);
  display: flex;
  z-index: 500;
  /* Safe area for notched phones (iPhone X+, Android) */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  /* Height = nav items + safe area */
  min-height: var(--bottom-nav);
}

.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 4px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav .nav-item.active { color: var(--red-light); }
.bottom-nav .nav-item:active { background: var(--navy-light); }

.nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

@media (max-width: 380px) {
  .nav-label { font-size: 0.55rem !important; }
  .nav-icon  { font-size: 1.1rem !important; }
  .bottom-nav .nav-item { padding: 6px 2px; }
}

.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
#page-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(204,31,31,0.08) 0%, transparent 60%),
    var(--navy);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-mark {
  width: 52px;
  height: 52px;
  font-size: 20px;
  margin: 0 auto 12px;
}

.login-logo h1 {
  font-family: var(--font-head);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text);
}

.login-logo p {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

.login-error {
  background: rgba(231,76,60,0.15);
  border: 1px solid rgba(231,76,60,0.4);
  color: #ff6b6b;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.15s;
  min-height: 44px;
  -webkit-appearance: none;
}

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

.form-group select {
  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 d='M1 1l5 5 5-5' stroke='%238FA3BA' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--red);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--red-light); }
.btn-primary:active { background: var(--red-dark); }

.btn-secondary {
  background: var(--steel);
  color: var(--text);
}

.btn-secondary:hover { background: var(--navy-light); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-ghost:hover { border-color: var(--red); color: var(--red-light); }

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

/* ============================================================
   SEARCH PAGE
   ============================================================ */
@media (max-width: 479px) {
  .search-hero { padding: 14px 12px 10px; }
  .search-hero h2 { font-size: 1.1rem; }
  .search-hint { font-size: 0.72rem; }
}

.search-hero {
  background: var(--navy-mid);
  border-bottom: 1px solid var(--border);
  padding: 20px 16px;
}

.search-hero h2 {
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 14px;
}

.search-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-input-wrap {
  flex: 1;
  position: relative;
}

.search-input-wrap input {
  width: 100%;
  background: var(--input-bg);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 12px 14px 12px 42px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  min-height: 52px;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

.search-input-wrap input:focus {
  outline: none;
  border-color: var(--red);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-bar select {
  background: var(--input-bg);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 0 32px 0 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  min-height: 52px;
  min-width: 120px;
  cursor: pointer;
  -webkit-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 d='M1 1l5 5 5-5' stroke='%238FA3BA' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.search-bar select:focus {
  outline: none;
  border-color: var(--red);
}

.search-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  padding: 0 2px;
}

.search-results {
  padding: 16px;
}

.results-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

/* ============================================================
   CODE CARD
   ============================================================ */
.code-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.code-card:hover, .code-card:active { border-color: var(--red); }

.code-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 12px;
}

.code-num {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--red-light);
  letter-spacing: 1px;
  white-space: nowrap;
  min-width: 50px;
}

.code-desc {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.3;
}

.code-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.badge-FAULT  { background: rgba(231,76,60,0.2);  color: #ff6b6b; border: 1px solid rgba(231,76,60,0.3); }
.badge-ERROR  { background: rgba(243,156,18,0.2); color: #f5b642; border: 1px solid rgba(243,156,18,0.3); }
.badge-INFO   { background: rgba(52,152,219,0.2); color: #5dade2; border: 1px solid rgba(52,152,219,0.3); }

.badge-model {
  background: var(--steel);
  color: var(--text-dim);
  font-size: 0.6rem;
  letter-spacing: 0.5px;
}

/* Expanded code detail */
.code-detail {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: none;
  background: rgba(0,0,0,0.2);
}

.code-card.expanded .code-detail { display: block; }

.detail-section {
  margin-bottom: 14px;
}

.detail-section:last-child { margin-bottom: 0; }

.detail-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.detail-value.mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #7ec8e3;
}

/* ============================================================
   TSB PAGE
   ============================================================ */
.page-header {
  background: var(--navy-mid);
  border-bottom: 1px solid var(--border);
  padding: 20px 16px;
}

.page-header h2 {
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.page-header p {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
}

.tsb-list {
  padding: 16px;
}

.tsb-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.15s;
}

.tsb-card:hover { border-color: var(--red); }

.tsb-info { flex: 1; min-width: 0; }

.tsb-number {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--red-light);
  font-weight: 600;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.tsb-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 6px;
}

.tsb-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tsb-applies {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--steel);
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.tsb-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-tsb-pdf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--red);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  min-height: 44px;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-tsb-pdf:hover { background: var(--red-light); text-decoration: none; }

.tsb-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.tsb-admin-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 6px 9px;
  min-height: 34px;
  line-height: 1;
}
.tsb-admin-btn:hover { border-color: var(--red); }
.tsb-del:hover { border-color: var(--error); }

/* ============================================================
   ADMIN PAGE
   ============================================================ */
.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--navy-mid);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-tab {
  padding: 14px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  min-height: 44px;
}

.admin-tab.active {
  color: var(--red-light);
  border-bottom-color: var(--red);
}

.admin-panel { display: none; padding: 16px; }
.admin-panel.active { display: block; }

.user-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.user-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 500px;
  font-size: 0.85rem;
}

.user-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.user-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(46,66,96,0.5);
  color: var(--text);
  vertical-align: middle;
}

.user-table tr:hover td { background: rgba(22,35,54,0.5); }

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

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  /* Above the mobile bottom-nav (z-index 500) so bottom-sheet modals — including
     the notifications popout — aren't hidden behind the nav bar. */
  z-index: 600;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 24px;
  }
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--navy-mid);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  animation: slideUp 0.25s ease;
}

@media (min-width: 600px) {
  .modal {
    border-radius: 12px;
    max-width: 480px;
    animation: fadeIn 0.2s ease;
  }
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}

.modal-close:hover { background: var(--steel); }

/* ============================================================
   EMPTY / LOADING STATES
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p { font-size: 0.9rem; line-height: 1.5; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--text-dim);
  gap: 10px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 12px);
  right: 16px;
  z-index: 700; /* above modals (600) so confirmations stay visible */
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: slideLeft 0.25s ease;
  max-width: 280px;
  pointer-events: all;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--error); }

@keyframes slideLeft {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ============================================================
   DESKTOP ENHANCEMENTS
   ============================================================ */
@media (min-width: 768px) {
  body { padding-bottom: 0; }

  .bottom-nav { display: none; }

  .top-header { padding: 0 24px; }

  .top-header nav {
    display: flex;
    gap: 4px;
  }

  .top-nav-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
    min-height: 36px;
    white-space: nowrap;
  }

  .top-nav-btn.active { background: var(--steel); color: var(--text); }
  .top-nav-btn:hover  { background: var(--navy-light); color: var(--text); }

  .search-hero, .page-header { padding: 24px; }
  .search-results, .tsb-list, .admin-panel { padding: 24px; }
  .container { padding: 0 24px; }
}

/* Print-friendly for techs who need paper */
@media print {
  .bottom-nav, .top-header { display: none; }
  .search-hero { display: none; }
  body { background: white; color: black; padding: 0; }
  .code-card { border: 1px solid #ccc; break-inside: avoid; }
  .code-detail { display: block !important; }
}


/* ============================================================
   MOBILE & TABLET — ALL DEVICES
   Breakpoints: mobile <768px | tablet 768-1023px | desktop 1024px+
   ============================================================ */

/* Global: prevent horizontal scroll on all devices */
html { overflow-x: hidden; }
/* Keep images from forcing horizontal overflow (scoped to media, not every element) */
img { max-width: 100%; }

/* ── MOBILE (phones, all sizes) ── */
@media (max-width: 767px) {

  /* Header */
  .top-header       { padding: 0 12px; height: 52px; }
  .logo-text        { display: none; }
  .logo-sub         { display: none; }
  .header-logo-img  { height: 24px !important; max-width: 130px; }
  .user-badge       { display: none !important; }
  .btn-logout       { font-size: 0.75rem; padding: 5px 10px; min-height: 34px; }
  #desktop-nav      { display: none !important; }
  /* Controls (bell + account) never shrink; the logo yields space if it's tight. */
  .header-user      { flex-shrink: 0; gap: 8px; }
  .top-header .logo { min-width: 0; flex: 0 1 auto; overflow: hidden; }
  .notif-bell, .btn-logout { flex-shrink: 0; }

  /* Page padding accounts for sticky header + bottom nav */
  .page             { padding-top: 0; }

  /* Search / hero areas */
  .search-hero      { padding: 14px 14px 12px; }
  .search-hero h2   { font-size: 1.05rem; margin-bottom: 10px; }
  .search-hint      { font-size: 0.78rem; line-height: 1.4; }

  /* Search bar: input full width, filter below */
  .search-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .search-bar .search-input-wrap { width: 100%; flex: none; }
  .search-bar select              { width: 100%; min-height: 44px; }

  /* Filter rows */
  .filter-row           { flex-direction: column; gap: 8px; }
  .filter-row select    { width: 100%; }
  .parts-filters        { flex-direction: column; gap: 8px; }
  .parts-filters select { width: 100%; }

  /* Content padding */
  .search-results       { padding: 0 12px 12px; }
  .page-header          { padding: 14px 14px; }
  .forum-content        { padding: 12px; }
  .tsb-list             { padding: 12px; }
  .admin-panel          { padding: 12px; }
  .admin-tabs           { padding: 0 12px; }

  /* Results count */
  .results-count { padding: 8px 0; font-size: 0.8rem; }

  /* Bottom nav — fixed to bottom on all mobile */
  .bottom-nav {
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    min-height: var(--bottom-nav);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottom-nav .nav-item { padding: 8px 2px; min-height: 44px; }
  body {
    padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Nav labels: hide on very small screens */
  @media (max-width: 359px) {
    .nav-label { display: none; }
    .nav-icon  { font-size: 1.4rem; }
  }

  /* Checklists */
  #checklist-cat-row         { flex-direction: column; gap: 8px; }
  #checklist-cat-row select  { width: 100%; }
  .cl-progress-bar           { width: 80px; }
  .cl-trouble-row            { grid-template-columns: 1fr; gap: 6px; }

  /* Diagnostic */
  .diag-trouble-row  { grid-template-columns: 1fr; gap: 4px; }
  .diag-detail-row   { grid-template-columns: 1fr; }
  .diag-code-row     { flex-wrap: wrap; gap: 6px; }

  /* Parts table horizontal scroll */
  .parts-table-wrap  { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .parts-table       { min-width: 460px; }

  /* Forum */
  .forum-post        { padding: 12px; }
  .reply-form-wrap   { padding: 12px; }
  .cl-header-bar     { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* TSB cards */
  .tsb-card          { padding: 14px; }

  /* Admin user table scroll */
  .user-table-wrap   { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modals slide up from bottom */
  .modal {
    border-radius: 16px 16px 0 0;
    max-height: 85vh;
    padding: 20px 16px;
  }
}

/* ── TABLET (768px - 1023px) ── */
@media (min-width: 768px) and (max-width: 1023px) {
  .top-header       { padding: 0 20px; }
  .search-hero      { padding: 20px; }
  .search-results   { padding: 0 20px 20px; }
  .forum-content    { padding: 16px; }
  .page-header      { padding: 20px; }

  /* Keep bottom nav on tablets */
  .bottom-nav       { display: flex; }
  #desktop-nav      { display: none !important; }
  body              { padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom, 0px)) !important; }

  /* Search bar side by side on tablet */
  .search-bar { flex-direction: row; }
  .search-bar .search-input-wrap { flex: 1; }

  /* Two column grids where applicable */
  .diag-trouble-row { grid-template-columns: 1fr 1fr; }
}

/* ── DESKTOP (1024px+) ── */
@media (min-width: 1024px) {
  body              { padding-bottom: 0 !important; }
  .bottom-nav       { display: none !important; }
  .top-header       { padding: 0 28px; }
  .search-hero, .page-header  { padding: 28px; }
  .search-results, .tsb-list,
  .admin-panel                { padding: 28px; }
  .forum-content              { padding: 20px; }
  .container                  { padding: 0 28px; }
}

/* ── Safe area (notch/Dynamic Island on any device) ── */
@supports (padding-top: env(safe-area-inset-top)) {
  .top-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(52px + env(safe-area-inset-top, 0px));
  }
}
