/* ─── Custom Properties ──────────────────────────────────────────────────── */
:root {
  --bg-app:         #0d1b2a;
  --bg-header:      #0f2847;
  --bg-card:        #162640;
  --bg-card-hover:  #1e3254;
  --bg-selected:    #1a3560;
  --bg-nav:         #0b1e35;

  --border:         #2a4465;
  --border-selected:#3b82f6;

  --text-primary:   #e8f0f8;
  --text-secondary: #7fa8cc;
  --text-hint:      #4e7a9e;

  --green:          #4ade80;
  --green-bg:       #052e16;
  --green-border:   #166534;

  --yellow:         #fbbf24;
  --yellow-bg:      #1a1000;
  --yellow-border:  #92400e;

  --orange:         #fb923c;
  --orange-bg:      #1a0800;
  --orange-border:  #9a3412;

  --red:            #f87171;
  --red-bg:         #1a0000;
  --red-border:     #991b1b;

  --cat-pilot:      #2563eb;
  --cat-aircraft:   #7c3aed;
  --cat-env:        #059669;
  --cat-ext:        #d97706;

  --nav-height:     64px;
  --header-height:  auto;
  --radius:         10px;
  --radius-sm:      6px;
  --tap-min:        52px;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;      /* dynamic viewport height — handles iOS Safari toolbar */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input, select {
  font-family: inherit;
  font-size: inherit;
}

/* ─── App Shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
#app-header {
  flex-shrink: 0;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.app-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
}

.app-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* ─── Score Banner ───────────────────────────────────────────────────────── */
.score-banner {
  padding: 10px 16px 12px;
  text-align: center;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.score-banner.status-green  { background: var(--green-bg);  color: var(--green);  }
.score-banner.status-yellow { background: var(--yellow-bg); color: var(--yellow); }
.score-banner.status-orange { background: var(--orange-bg); color: var(--orange); }
.score-banner.status-red    { background: var(--red-bg);    color: var(--red);    }

.score-num {
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}

.score-status-label {
  font-size: 17px;
  font-weight: 700;
  margin-top: 2px;
}

.score-status-msg {
  font-size: 13px;
  margin-top: 2px;
  opacity: 0.85;
}

/* ─── Main Content ────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ─── Screens ─────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

.page-header {
  padding: 20px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ─── Assessment — Top Bar ───────────────────────────────────────────────── */
.assessment-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.assessment-hint {
  font-size: 13px;
  color: var(--text-hint);
}

.btn-ghost-sm {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  transition: background 0.15s;
}

.btn-ghost-sm:active { background: var(--bg-card-hover); }

/* ─── Category Sections ──────────────────────────────────────────────────── */
.cat-section {
  border-bottom: 1px solid var(--border);
}

.cat-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  min-height: var(--tap-min);
  background: var(--bg-card);
  color: var(--text-primary);
  text-align: left;
  border: none;
  transition: background 0.15s;
}

.cat-header:active { background: var(--bg-card-hover); }

.cat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.cat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.cat-label {
  font-size: 15px;
  font-weight: 600;
}

.cat-tally {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(59,130,246,0.15);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
}

.cat-chevron {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 8px;
}

/* ─── Category Body (collapsed/expanded) ─────────────────────────────────── */
.cat-body.collapsed { display: none; }
.cat-body.expanded  { display: block; }

/* ─── Factor Rows ─────────────────────────────────────────────────────────── */
.factor-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 12px;
  min-height: var(--tap-min);
  background: var(--bg-app);
  color: var(--text-primary);
  text-align: left;
  border-left: 3px solid transparent;
  border-bottom: 1px solid rgba(42,68,101,0.5);
  transition: background 0.12s, border-left-color 0.12s;
}

.factor-row:last-child { border-bottom: none; }

.factor-row:active { background: var(--bg-card); }

.factor-row.selected {
  background: var(--bg-selected);
  border-left-color: var(--border-selected);
}

.factor-check {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  font-size: 13px;
  color: #60a5fa;
  font-weight: 700;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s;
}

.factor-row.selected .factor-check {
  border-color: #3b82f6;
  background: #1d4ed8;
}

.factor-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.35;
  min-width: 0;
}

.factor-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.factor-row.selected .factor-value {
  color: #93c5fd;
}

/* ─── Results Screen ─────────────────────────────────────────────────────── */
.results-score-card {
  margin: 20px 16px 0;
  padding: 24px 20px;
  border-radius: var(--radius);
  text-align: center;
  border: 2px solid transparent;
}

.results-score-card.status-green  { background: var(--green-bg);  color: var(--green);  border-color: var(--green-border);  }
.results-score-card.status-yellow { background: var(--yellow-bg); color: var(--yellow); border-color: var(--yellow-border); }
.results-score-card.status-orange { background: var(--orange-bg); color: var(--orange); border-color: var(--orange-border); }
.results-score-card.status-red    { background: var(--red-bg);    color: var(--red);    border-color: var(--red-border);    }

.results-score-num {
  font-size: 72px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
}

.results-score-label {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

.results-score-msg {
  font-size: 14px;
  margin-top: 4px;
  opacity: 0.9;
}

.results-factor-list {
  margin: 20px 16px 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.results-section-title {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.results-factor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid rgba(42,68,101,0.5);
  gap: 12px;
}

.results-factor-row:last-child { border-bottom: none; }

.results-factor-text {
  font-size: 14px;
  flex: 1;
}

.results-factor-value {
  font-size: 14px;
  font-weight: 700;
  color: #93c5fd;
  flex-shrink: 0;
}

.results-actions {
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── History Screen ─────────────────────────────────────────────────────── */
.history-list {
  padding: 12px 0;
}

.history-card {
  margin: 0 12px 10px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.history-card-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  min-height: var(--tap-min);
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  gap: 12px;
}

.history-card-header:active { background: var(--bg-card-hover); }

.history-card-meta { flex: 1; min-width: 0; }

.history-date {
  font-size: 15px;
  font-weight: 600;
}

.history-time {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.history-card-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.history-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.history-badge.status-green  { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green-border);  }
.history-badge.status-yellow { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.history-badge.status-orange { background: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange-border); }
.history-badge.status-red    { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red-border);    }

.history-detail {
  border-top: 1px solid var(--border);
  padding: 8px 0 4px;
}

.history-factor-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
}

.history-factor-cat {
  color: var(--text-hint);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.history-factor-text { flex: 1; }

.history-factor-val {
  font-weight: 700;
  color: #93c5fd;
  flex-shrink: 0;
}

.history-no-factors {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.history-detail-footer {
  padding: 10px 14px 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.history-footer {
  padding: 4px 16px 28px;
  text-align: center;
}

/* ─── Profile & Settings Forms ───────────────────────────────────────────── */
.form-section {
  padding: 20px 16px 40px;
}

.form-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.form-hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;   /* 16px prevents iOS zoom-on-focus */
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: #3b82f6;
}

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='%237fa8cc' 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;
}

.form-error {
  font-size: 13px;
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

/* ─── Threshold Settings ─────────────────────────────────────────────────── */
.threshold-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}

.threshold-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.threshold-label-col {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  font-size: 14px;
}

.threshold-label-col label { margin: 0; text-transform: none; letter-spacing: 0; font-weight: 400; }

.threshold-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.threshold-dot.status-green  { background: var(--green);  }
.threshold-dot.status-yellow { background: var(--yellow); }
.threshold-dot.status-orange { background: var(--orange); }
.threshold-dot.status-red    { background: var(--red);    }

.threshold-input {
  width: 70px;
  text-align: center;
  flex-shrink: 0;
}

.threshold-static {
  width: 70px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--red);
  flex-shrink: 0;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { opacity: 0.8; transform: scale(0.98); }

.btn-primary   { background: #2563eb; color: #fff; }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-danger    { background: #7f1d1d; color: var(--red); border: 1px solid var(--red-border); }

.btn-sm {
  width: auto;
  padding: 8px 14px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}

/* ─── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
  line-height: 1.5;
}

.empty-sub {
  font-size: 13px;
  color: var(--text-hint);
  margin-top: 8px;
}

/* ─── Misc ────────────────────────────────────────────────────────────────── */
.save-msg {
  margin-top: 12px;
  font-size: 14px;
  color: var(--green);
  text-align: center;
}

.save-confirmation {
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--green);
  text-align: center;
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: var(--radius);
}

.hidden { display: none !important; }

/* ─── Bottom Navigation ───────────────────────────────────────────────────── */
#bottom-nav {
  flex-shrink: 0;
  display: flex;
  background: var(--bg-nav);
  border-top: 1px solid var(--border);
  height: var(--nav-height);
  z-index: 10;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  color: var(--text-hint);
  border: none;
  background: transparent;
  border-top: 2px solid transparent;
  transition: color 0.15s, border-top-color 0.15s;
  min-height: var(--nav-height);
}

.nav-tab.active {
  color: #60a5fa;
  border-top-color: #2563eb;
}

.nav-tab:active { opacity: 0.7; }

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg { display: block; }

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ─── Responsive: allow a bit more width on tablets ──────────────────────── */
@media (min-width: 480px) {
  #app {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.6);
  }

  body {
    background: #06111e;
    justify-content: center;
  }
}
