/* ============================================================
   Sacred Command v2 — app.css (shell layout only)
   Rail · topbar · view container · drawers · palette ·
   mobile tab bar · present mode · single 768px breakpoint.
   ============================================================ */

/* Ambient crimson glow, top-left, very subtle */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(900px 620px at -8% -12%, var(--crimson-dim), transparent 62%);
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

/* ---------- Rail (240px, desktop) ---------- */
#rail {
  flex: 0 0 240px;
  width: 240px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg1);
  border-right: 1px solid var(--line);
}
.rail-logo {
  padding: 2px 10px 16px;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1.25;
  user-select: none;
}
.rail-logo .l1 { display: block; font-size: 15px; color: var(--cream); }
.rail-logo .l2 { display: block; font-size: 11px; color: var(--red); }

#railNav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13.5px;
  font-weight: 600;
  transition: background var(--speed) ease, color var(--speed) ease;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--text); }
.nav-item .nav-icon { width: 20px; text-align: center; font-size: 15px; }
.nav-item .badge { margin-left: auto; }

/* MRR goal thermometer */
.thermo {
  margin-top: auto;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg2);
}
.thermo-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}
.thermo-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
}
.thermo-num { font-size: 16px; font-weight: 600; color: var(--text); }
.thermo-track {
  height: 8px;
  border-radius: 999px;
  background: var(--bg3);
  overflow: hidden;
}
.thermo-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--crimson), var(--red));
  transition: width 1200ms cubic-bezier(0.22, 0.9, 0.3, 1);
}
.thermo-pace { margin-top: 7px; font-size: 10.5px; color: var(--text3); }

/* Rail footer */
.rail-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
}
.user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--crimson);
  color: #fff;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  flex: 0 0 auto;
}
.settings-btn {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text3);
  font-size: 15px;
  transition: background var(--speed) ease, color var(--speed) ease;
}
.settings-btn:hover, .settings-btn.active { background: var(--bg2); color: var(--text); }

/* ---------- Main column ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
  background: rgba(10, 11, 16, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#pageTitle {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-right: 6px;
  white-space: nowrap;
}
.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 7px 12px;
  min-width: 200px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text3);
  font-size: 12.5px;
  transition: border-color var(--speed) ease, color var(--speed) ease;
}
.search-trigger:hover { border-color: var(--line-hi); color: var(--text2); }
.search-trigger kbd {
  margin-left: auto;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg3);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text3);
}
.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text2);
  font-size: 12.5px;
  font-weight: 600;
  position: relative;
  transition: border-color var(--speed) ease, color var(--speed) ease, background var(--speed) ease;
}
.topbar-btn:hover { border-color: var(--line-hi); color: var(--text); }
.topbar-btn .badge {
  position: absolute;
  top: -6px; right: -6px;
  border: 2px solid var(--bg0);
  height: 17px; min-width: 17px;
}
#sageBtn { color: var(--cream); border-color: rgba(237, 231, 218, 0.18); }
#sageBtn:hover { border-color: rgba(237, 231, 218, 0.38); }

/* View container */
#view {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
}
#view.view-in { animation: viewIn var(--speed) ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } }

.stub-card { max-width: 560px; margin: 8vh auto 0; text-align: center; padding: 34px 26px; }
.stub-card h2 { margin-bottom: 8px; }
.stub-card .stub-icon { font-size: 28px; margin-bottom: 12px; }

/* ---------- Bell drawer ---------- */
.alert-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}
.alert-row:last-child { border-bottom: none; }
.alert-row.resolved { opacity: 0.45; }
.sev {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex: 0 0 auto;
}
.sev-red    { background: var(--red);  box-shadow: 0 0 8px rgba(255, 59, 78, 0.6); }
.sev-yellow { background: var(--warn); }
.sev-green  { background: var(--good); }
.alert-main { flex: 1; min-width: 0; }
.alert-title { font-size: 13px; font-weight: 600; }
.alert-meta { font-size: 11.5px; color: var(--text3); margin-top: 2px; }

/* ---------- Sage drawer ---------- */
#sageDrawer .drawer-body { display: flex; flex-direction: column; gap: 10px; }
.sage-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  animation: msgIn 200ms ease;
}
.sage-msg.sage {
  align-self: flex-start;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.sage-msg.me {
  align-self: flex-end;
  background: var(--crimson);
  color: #fff;
  border-bottom-right-radius: 5px;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.sage-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

/* ---------- Command palette ---------- */
#palette {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
  background: rgba(6, 7, 10, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 120ms ease;
}
#palette[hidden] { display: none; }
.palette-box {
  width: 560px;
  max-width: 100%;
  background: var(--bg1);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modalIn 160ms cubic-bezier(0.32, 0.72, 0.28, 1);
}
#palInput {
  width: 100%;
  padding: 15px 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  color: var(--text);
}
#palInput:focus { outline: none; }
#palInput::placeholder { color: var(--text3); }
#palList { max-height: 330px; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  cursor: pointer;
}
.palette-item .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.sel { background: var(--bg3); }
.pal-empty { padding: 18px; text-align: center; color: var(--text3); font-size: 13px; }
.pal-hint {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--text3);
  display: flex;
  gap: 14px;
}

/* ---------- Mobile bottom tab bar ---------- */
#mobileTabs {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: rgba(16, 17, 23, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.mtab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 7px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 600;
  position: relative;
  transition: color var(--speed) ease;
}
.mtab .mtab-icon { font-size: 17px; line-height: 1; }
.mtab.active { color: var(--text); }
.mtab .badge {
  position: absolute;
  top: 3px;
  left: calc(50% + 6px);
  height: 15px; min-width: 15px;
  font-size: 9px;
}

/* ---------- Present mode ---------- */
body.present #rail,
body.present #topbar,
body.present #mobileTabs,
body.present #toasts { display: none; }
body.present #view { max-width: none; padding: 0; }
body.present::before { background: radial-gradient(1100px 700px at 50% -20%, var(--crimson-dim), transparent 65%); }
#presentExit {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  z-index: 95;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(20, 21, 26, 0.85);
  border: 1px solid var(--line-hi);
  color: var(--text2);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--speed) ease, border-color var(--speed) ease;
}
#presentExit:hover { color: var(--text); border-color: var(--text3); }
#presentExit[hidden] { display: none; }

/* ---------- Settings ---------- */
.settings-card { max-width: 620px; margin: 0 auto; }
.settings-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 2px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.settings-row .lab { width: 130px; flex: 0 0 auto; color: var(--text3); font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }

/* ---------- Single breakpoint: <768px ---------- */
@media (max-width: 767px) {
  #rail { display: none; }
  #mobileTabs { display: flex; }
  #view { padding: 16px 14px calc(86px + env(safe-area-inset-bottom)); }
  #topbar { padding: 0 12px; padding-top: env(safe-area-inset-top); gap: 6px; }
  .search-trigger { min-width: 0; flex: 0 0 auto; margin-left: auto; padding: 7px 9px; }
  .search-trigger .st-label, .search-trigger kbd { display: none; }
  .topbar-btn .tb-label { display: none; }
  .drawer { width: 100vw; border-left: none; }
  #palette { padding: 8vh 10px 10px; }
  #toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); align-items: center; }
}
