:root {
  --bg: #0A0A0C;
  --surface: #111216;
  --surface-elev: rgba(255, 255, 255, 0.05);
  --pill-bg: #14151A;
  --border: rgba(255, 255, 255, 0.09);
  --border-top: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #FFFFFF;
  --text-sec: #D4D4D8;
  --text-muted: #8E8E93;
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.18);
  --danger: #FF453A;
  --warning: #FF9F0A;
  --success: #32D74B;
  --ease-snappy: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select, a {
  font-family: inherit;
}

button:active, .tap:active, .card-head:active, .acc-head:active, .nav-btn:active, .pill:active {
  transform: scale(0.97) !important;
  transition: transform 100ms var(--ease-snappy) !important;
}

/* Login Screen */
.login-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 15vh 20px 24px;
  background: var(--bg);
}

.login-inner {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.login-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.input, .textarea, .select {
  width: 100%;
  background: #14151A;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 13px;
  font-size: 16px; /* Prevents iOS Safari auto-zoom */
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.input, .select {
  height: 40px;
}

.textarea {
  padding: 10px 13px;
  min-height: 84px;
  resize: vertical;
  line-height: 1.45;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25);
}

.input-pin {
  text-align: center;
  letter-spacing: 0.35em;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  height: 46px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-full { width: 100%; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.btn-subdued {
  height: 36px;
  border-radius: 10px;
  background: var(--pill-bg);
  border: 1px solid #26262C;
  color: var(--text-sec);
  font-size: 13px;
  padding: 0 10px;
}

.btn-subdued.copied {
  border-color: var(--success);
  color: var(--success);
}

.btn-record {
  background: rgba(255, 69, 58, 0.14);
  border-color: rgba(255, 69, 58, 0.45);
  color: #FFFFFF;
}

.btn-record.recording {
  background: var(--danger);
  border-color: var(--danger);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* Main App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
  padding-top: max(env(safe-area-inset-top, 0px), 10px);
  background: var(--bg);
}

.topbar {
  height: 46px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.topbar-count {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.controls-bar {
  flex-shrink: 0;
  padding: 8px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-row::-webkit-scrollbar { display: none; }

.pill {
  flex-shrink: 0;
  height: 32px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid #26262C;
  background: var(--pill-bg);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
}

.pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 104px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  border-radius: 12px;
  padding: 10px 11px;
}

.card-head {
  display: flex;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.card-quick {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.badge-prio {
  flex-shrink: 0;
  height: 22px;
  padding: 0 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-sec);
}
.badge-prio.p-A {
  background: rgba(10, 132, 255, 0.16);
  border-color: rgba(10, 132, 255, 0.45);
  color: #64B5FF;
}
.badge-prio.p-B {
  background: rgba(255, 159, 10, 0.14);
  border-color: rgba(255, 159, 10, 0.38);
  color: #FFB340;
}
.badge-prio.p-C {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
}

.fns-pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 7px;
  background: rgba(50, 215, 75, 0.10);
  border: 1px solid rgba(50, 215, 75, 0.28);
  color: #7AE582;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.card-title {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  word-break: break-word;
}

.card-meta {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.card-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-sec);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-badge.active-stage {
  background: var(--accent-soft);
  border-color: rgba(10, 132, 255, 0.45);
  color: var(--text);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}
.dot.accent { background: var(--accent); box-shadow: 0 0 6px rgba(10, 132, 255, 0.6); }
.dot.danger { background: var(--danger); box-shadow: 0 0 6px rgba(255, 69, 58, 0.6); }
.dot.warn { background: var(--warning); }
.dot.ok { background: var(--success); }

.prio-tag {
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-expand {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.info-line {
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.38;
}
.info-line strong {
  color: var(--text-muted);
  font-weight: 500;
}

.risk-line {
  font-size: 12.5px;
  color: var(--warning);
  background: rgba(255, 159, 10, 0.09);
  border: 1px solid rgba(255, 159, 10, 0.25);
  border-radius: 8px;
  padding: 6px 9px;
}

/* Split Contact Grid (Apple Design Standard) */
.contact-row-1 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 6px;
}

.contact-row-2 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.contact-pill {
  height: 36px;
  border-radius: 10px;
  border: 1px solid #26262C;
  background: var(--pill-bg);
  color: var(--text-sec);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.contact-pill.disabled {
  opacity: 0.38;
  pointer-events: none;
}

.contact-pill.copied {
  border-color: var(--success);
  color: var(--success);
}

/* Bottom Navigation (Exact RULES.md iOS Safe Area Standard) */
.bottom-nav {
  height: 50px;
  touch-action: none;
  flex-shrink: 0;
  box-sizing: content-box;
  padding-bottom: max(calc(env(safe-area-inset-bottom, 0px) - 8px), 4px);
  background: rgba(14, 15, 19, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
}

.nav-btn {
  height: 50px;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}

.nav-btn.active {
  color: var(--text);
}

.nav-btn svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-counter {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #FFFFFF;
  color: #000000;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Portal Sheet / Modal */
.sheet-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  padding-top: max(env(safe-area-inset-top, 0px), 10px);
}

.sheet-header {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.sheet-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 56px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-body > *, .screen-content > * {
  flex-shrink: 0;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stage-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-chip {
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid #26262C;
  background: var(--pill-bg);
  color: var(--text-sec);
  font-size: 13px;
  cursor: pointer;
}

.stage-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #FFFFFF;
}

.field-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Audio Module */
.audio-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rec-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.4);
  border-radius: 10px;
  padding: 8px 11px;
  font-variant-numeric: tabular-nums;
}

.rec-pulse {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #FFFFFF;
}

.audio-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.audio-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.audio-item audio {
  width: 100%;
  height: 36px;
}

.transcript-box {
  font-size: 13px;
  color: var(--text-sec);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 8px;
  white-space: pre-wrap;
  line-height: 1.45;
}

/* KPI Grid & Segmented Control */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
}

.kpi-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi-label {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--pill-bg);
  border: 1px solid #26262C;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.seg-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
}

.calc-result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.calc-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 10px;
}

.calc-val {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.calc-lbl {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 66px);
  transform: translateX(-50%);
  background: #1C1C22;
  border: 1px solid var(--border-strong);
  color: #FFFFFF;
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  z-index: 10000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.muted { color: var(--text-muted); font-size: 13px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 28px 14px; font-size: 14px; }

/* Company Sheet Hero & Collapsible Accordions (Zero Chevrons) */
.sheet-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  border-radius: 12px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sheet-hero-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.acc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border-top);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.acc-card.open {
  background: #13151B;
  border-color: rgba(255, 255, 255, 0.2);
}

.acc-head {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 13px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.acc-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.acc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.acc-summary {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 52%;
}

.acc-card.open .acc-summary {
  color: var(--text-sec);
}

.acc-body {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  flex-direction: column;
  gap: 9px;
}

.acc-card.open .acc-body {
  display: flex;
  padding-top: 11px;
}

/* FNS Financials Grid & Table */
.fin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.fin-tile {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 10px;
}

.fin-tile-lbl {
  font-size: 11.5px;
  color: var(--text-muted);
}

.fin-tile-val {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fin-tile-sub {
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.fin-tile-sub.pos { color: var(--warning); }
.fin-tile-sub.neg { color: var(--text-muted); }

.fin-ratios {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.fin-ratio-item {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 9px;
  padding: 7px 8px;
}

.fin-ratio-k {
  font-size: 11px;
  color: var(--text-muted);
}

.fin-ratio-v {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
  font-variant-numeric: tabular-nums;
}

.fin-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
}

.fin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.fin-table th, .fin-table td {
  padding: 6px 7px;
  text-align: right;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.fin-table th:first-child, .fin-table td:first-child {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
}

.fin-table th {
  color: var(--text-muted);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.03);
}

.fin-table td {
  color: var(--text-sec);
}

.fin-table tr:last-child td {
  border-bottom: none;
}

.fns-note-box {
  font-size: 12px;
  color: var(--text-sec);
  background: rgba(10, 132, 255, 0.09);
  border: 1px solid rgba(10, 132, 255, 0.25);
  border-radius: 8px;
  padding: 7px 9px;
  line-height: 1.4;
}

.fns-pill-inline {
  color: var(--text-sec);
  font-variant-numeric: tabular-nums;
}
