/* InfraEngine PWA — mobile-first */
:root {
  /* Softer "Daytona Gray Pearl" graphite scale — matches the desktop app */
  --bg0: #1b1d20;
  --bg1: #222529;
  --bg2: #2a2e33;
  --bg3: #33383e;
  --border: rgba(255,255,255,0.10);
  --text0: #EDF0F2;
  --text1: #C4CBD2;
  --text2: #8B949E;
  --accent: #1ED7A6;
  --accent2: #5AA6FF;
  --warning: #F5C451;
  --danger: #FF5C68;
  --success: #1ED7A6;
  --purple: #A78BFA;
  --radius: 12px;
  --space: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.35);
  --shadow: 0 4px 14px rgba(0,0,0,0.40);
  --on-accent: #06211a; /* text on accent fills (dark in dark mode) */
}

/* Light theme — matches the desktop app; default is light (set in index.html) */
:root[data-theme="light"] {
  --bg0: #eef1f5;
  --bg1: #ffffff;
  --bg2: #f5f8fa;
  --bg3: #eceff3;
  --border: rgba(13,70,58,0.14);
  --text0: #0f1c18;
  --text1: #31414a;
  --text2: #63707a;
  --accent: #009e78;
  --accent2: #2f7fe0;
  --warning: #c98a00;
  --danger: #dc2b40;
  --success: #009e78;
  --purple: #7c5cff;
  --shadow-sm: 0 1px 3px rgba(20,45,40,0.08);
  --shadow: 0 6px 18px rgba(20,45,40,0.12);
  --on-accent: #ffffff; /* white on accent fills in light mode */
}
:root[data-theme="light"] body { background: var(--bg0); }

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

/* CRITICAL: HTML's hidden attribute must always win over any display rule */
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg0); color: var(--text0);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  font-size: 15px; line-height: 1.45;
  min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
/* Safe-area insets on BODY ONLY. Previously this was on `html, body`, so the
   top inset was applied twice — a big empty gap above the header on notch /
   Dynamic Island phones (e.g. iPhone 16 Pro Max). */
body {
  overscroll-behavior: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Screens */
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ─── LOGIN ──────────────────────────────────────────────────────────────── */
#screen-login.active { justify-content: center; align-items: center; padding: 24px; }
.login-wrap { width: 100%; max-width: 360px; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 36px; }
.brand-text { text-align: center; }
.logo-mark {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  border-radius: 14px;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(0,217,163,0.25);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 28px; letter-spacing: -2px;
  color: var(--on-accent);
  text-shadow: 0 1px 0 rgba(255,255,255,0.12);
}
.logo-mark::before { content: 'iE'; }

/* 3D bevel to match the desktop logo (was the old flat tile) */
.logo-mark, .logo-mark-sm {
  box-shadow: 0 4px 12px rgba(0,180,150,0.40),
              inset 0 1.5px 0 rgba(255,255,255,0.5),
              inset 0 -3px 6px rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.18);
}
.logo-mark::before, .logo-mark-sm::before {
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

.brand h1 {
  font-size: 22px; margin: 0;
  letter-spacing: 0.4px; font-weight: 800;
  color: var(--text0);
}
.brand h1 strong { color: var(--accent); font-weight: 800; }
.brand-sub { color: var(--text2); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; margin-top: 4px; }

/* Small logo in the app header */
.logo-mark-sm {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  border-radius: 6px;
  position: relative;
  flex-shrink: 0;
  font-weight: 800; font-size: 13px; letter-spacing: -1px;
  color: var(--bg1);
}
.logo-mark-sm::before { content: 'iE'; }
.header-title { font-weight: 800; font-size: 14px; letter-spacing: 0.4px; color: var(--text0); }
.header-title strong { color: var(--accent); }

form#login-form { display: flex; flex-direction: column; gap: 14px; }
form#login-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 10px; letter-spacing: 1.2px; color: var(--text2); font-weight: 600;
}
form#login-form input {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text0); padding: 14px 16px; border-radius: 10px;
  font-size: 16px; /* iOS won't zoom on focus when ≥16px */
  outline: none; transition: border 0.15s;
}
form#login-form input:focus { border-color: var(--accent); }
form#login-form button {
  background: var(--accent); color: var(--on-accent); border: none;
  padding: 16px; border-radius: 10px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3px;
  margin-top: 8px; cursor: pointer; transition: transform 0.05s;
}
form#login-form button:active { transform: scale(0.98); }
form#login-form button:disabled { opacity: 0.5; }

.error {
  background: rgba(255,78,78,0.1); border: 1px solid rgba(255,78,78,0.3);
  color: var(--danger); padding: 10px 12px; border-radius: 8px;
  font-size: 13px; margin-top: 8px;
}
/* Neutral (not an error) — used for the "enter your 2FA code" prompt. */
.error.info {
  background: rgba(30,215,166,0.10); border-color: rgba(30,215,166,0.35);
  color: var(--text1);
}

/* ─── APP SHELL ──────────────────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text0); width: 36px; height: 36px; border-radius: 8px;
  font-size: 20px; cursor: pointer; line-height: 1;
}

/* Push status card */
.push-card {
  margin: 16px; padding: 16px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px;
}
.push-card .status-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.push-card .status-row:last-child { border-bottom: none; }
.push-card .status-row .label { flex: 1; color: var(--text1); }
.push-card .status-row .value { color: var(--text0); font-weight: 600; }
.push-card .status-ok { color: var(--success); }
.push-card .status-warn { color: var(--warning); }
.push-card .status-err { color: var(--danger); }
.push-card button {
  width: 100%; padding: 12px; margin-top: 12px;
  background: var(--accent); color: var(--on-accent); border: none; border-radius: 8px;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.push-card button:active { transform: scale(0.98); }
.push-card button:disabled { opacity: 0.5; }

/* Empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center; color: var(--text2);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h2 { color: var(--text1); font-size: 18px; margin: 0 0 12px 0; }
.empty-state p { font-size: 14px; max-width: 320px; }

/* ─── HEADER RIGHT ───────────────────────────────────────────────────────── */
.header-right { display: flex; align-items: center; gap: 8px; }
.header-right .icon-btn { font-size: 18px; }
.header-right .icon-btn.spinning { animation: spin 0.6s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ─── FILTER CHIPS ──────────────────────────────────────────────────────── */
.filter-chips {
  display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto;
  background: var(--bg1); border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text2);
  padding: 6px 12px; border-radius: 16px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.chip:active { transform: scale(0.96); }
.chip.active { background: rgba(0,217,163,0.15); border-color: var(--accent); color: var(--accent); }
.chip-count {
  background: var(--bg3); color: var(--text2);
  padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 700;
  min-width: 18px; text-align: center;
}
.chip.active .chip-count { background: var(--accent); color: var(--on-accent); }

/* ─── ALERT LIST ────────────────────────────────────────────────────────── */
.alert-list-wrap {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.alert-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.loading-state {
  padding: 32px; text-align: center; color: var(--text2); font-size: 13px;
}

.alert-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text2);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  transition: background 0.15s;
  position: relative;
}
.alert-item:active { background: var(--bg3); }
.alert-item.severity-danger  { border-left-color: var(--danger); }
.alert-item.severity-warning { border-left-color: var(--warning); }
.alert-item.severity-success { border-left-color: var(--success); }
.alert-item.severity-info    { border-left-color: var(--accent2); }
.alert-item.acknowledged { opacity: 0.55; }
.alert-item.flash-new { animation: alertFlashIn 0.6s ease-out; }
@keyframes alertFlashIn {
  0% { background: rgba(255,164,0,0.20); transform: translateX(-8px); }
  100% { background: var(--bg2); transform: translateX(0); }
}
.alert-item.severity-danger.flash-new { animation-name: alertFlashInDanger; }
@keyframes alertFlashInDanger {
  0%, 30% { background: rgba(255,78,78,0.25); transform: translateX(-8px); }
  100% { background: var(--bg2); transform: translateX(0); }
}

.alert-top {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.alert-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
}
.alert-badge.severity-danger  { background: rgba(255,78,78,0.15); color: var(--danger); }
.alert-badge.severity-warning { background: rgba(255,164,0,0.15); color: var(--warning); }
.alert-badge.severity-success { background: rgba(0,217,163,0.15); color: var(--success); }
.alert-badge.severity-info    { background: rgba(74,158,255,0.15); color: var(--accent2); }
.alert-badge.category {
  background: var(--bg3); color: var(--text2);
}
.alert-badge.category-asset_monitoring { background: rgba(0,217,163,0.10); color: var(--accent); }
.alert-badge.category-new_relic { background: rgba(74,158,255,0.10); color: var(--accent2); }
.alert-badge.category-domain_rotation { background: rgba(167,139,250,0.10); color: var(--purple); }

.alert-time {
  margin-left: auto;
  color: var(--text2); font-size: 11px;
}
/* Rotation card — a live domain went down, so show the switch, not prose. */
.alert-item.rot .rot-site {
  font-size: 14px; font-weight: 700; color: var(--text0);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rot-flow { display: flex; flex-direction: column; gap: 6px; }
.rot-dom {
  display: flex; flex-direction: column; gap: 2px;
  padding: 7px 10px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
}
.rot-dom-l { font-size: 8.5px; font-weight: 800; letter-spacing: 0.6px; color: var(--text2); }
.rot-dom-d {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; color: var(--text0); word-break: break-all;
}
.rot-dom.was .rot-dom-l { color: var(--danger); }
.rot-dom.was .rot-dom-d { text-decoration: line-through; text-decoration-color: rgba(255,92,104,0.9); text-decoration-thickness: 1.5px; }
.rot-dom.now { background: rgba(30,215,166,0.08); border-color: rgba(30,215,166,0.35); }
.rot-dom.now .rot-dom-l { color: var(--success); }
/* Blocked with an empty queue: nothing is serving. Loudest state on the card. */
.rot-dom.held { background: rgba(90,166,255,0.08); border-color: rgba(90,166,255,0.35); }
.rot-dom.held .rot-dom-l { color: var(--accent2, #5AA6FF); }
.rot-dom.none { background: rgba(255,92,104,0.10); border-color: rgba(255,92,104,0.45); border-style: dashed; }
.rot-dom.none .rot-dom-l { color: var(--danger); }
.rot-dom.none .rot-dom-d { color: var(--danger); font-style: italic; }
.rot-foot { font-size: 11.5px; color: var(--text2); }

.alert-title {
  font-size: 14px; font-weight: 600; color: var(--text0);
  line-height: 1.35;
}
.alert-detail {
  font-size: 13px; color: var(--text1); line-height: 1.4;
}
.alert-actions {
  display: flex; gap: 8px; margin-top: 6px;
  align-items: center;
}
.alert-ack-btn {
  background: var(--accent); color: var(--on-accent); border: none;
  padding: 8px 14px; border-radius: 6px;
  font-size: 12px; font-weight: 700; cursor: pointer; letter-spacing: 0.3px;
  flex-shrink: 0;
}
.alert-ack-btn:active { transform: scale(0.96); }
.alert-copy-btn {
  background: var(--bg3); color: var(--text1); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  flex-shrink: 0; margin-left: auto;
}
.alert-copy-btn:active { transform: scale(0.96); background: var(--bg2); }
.alert-copy-btn:disabled { opacity: 0.6; }
.alert-acked-by { color: var(--success); font-size: 11px; }

/* Pull-to-refresh — progress ring fills as you pull, then a smooth arc spinner */
.ptr-indicator {
  position: absolute; top: 0; left: 50%; margin-left: -20px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg2);
  box-shadow: 0 6px 18px rgba(0,0,0,0.38), inset 0 0 0 1px var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 17px; font-weight: 700;
  opacity: 0; transform: translateY(-46px) scale(0.6);
  transition: transform 0.28s cubic-bezier(.2,.9,.2,1), opacity 0.2s;
  z-index: 30; pointer-events: none;
  --ptr: 0;
}
/* the fill ring (conic gradient masked into a 3px ring) */
.ptr-indicator::before {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--ptr) * 1turn), rgba(127,127,127,0.18) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}
.ptr-indicator .ptr-glyph { transition: transform 0.18s ease; line-height: 1; }
.ptr-indicator.armed { color: var(--accent2); }
.ptr-indicator.armed::before { filter: drop-shadow(0 0 5px var(--accent)); }
/* spinning: swap the fill ring for a rotating arc, hide the arrow */
.ptr-indicator.spinning::before {
  background: none; -webkit-mask: none; mask: none;
  border: 2.5px solid rgba(127,127,127,0.22); border-top-color: var(--accent);
  animation: ptr-spin 0.7s linear infinite;
}
.ptr-indicator.spinning .ptr-glyph { display: none; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* iOS install banner */
.ios-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-top: 1px solid var(--accent);
  z-index: 1000; padding: 16px;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}
.ios-banner-inner { max-width: 480px; margin: 0 auto; }
.ios-banner strong { display: block; margin-bottom: 6px; }
.ios-banner p { margin: 8px 0; font-size: 13px; color: var(--text1); line-height: 1.5; }
.ios-share { display: inline-block; padding: 2px 8px; background: var(--bg3); border-radius: 4px; font-weight: 700; }
.ios-banner button {
  margin-top: 8px; background: none; border: 1px solid var(--border);
  color: var(--text0); padding: 8px 16px; border-radius: 6px; cursor: pointer;
}

/* Drawer */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 85%; max-width: 320px;
  background: var(--bg1); border-left: 1px solid var(--border);
  z-index: 100;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,0.5);
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: 14px; font-weight: 700; letter-spacing: 0.4px; color: var(--text0); text-transform: uppercase; }
#btn-drawer-close { font-size: 20px; line-height: 1; width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.drawer-inner { display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; }
.drawer-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px; background: var(--bg2); border-radius: 8px;
}
.drawer-row strong { font-size: 10px; letter-spacing: 1px; color: var(--text2); }
.drawer-row span { font-size: 14px; color: var(--text0); }
.drawer button {
  padding: 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text0);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.drawer .btn-danger { background: rgba(255,78,78,0.1); border-color: var(--danger); color: var(--danger); }
.drawer-msg {
  padding: 10px 12px; background: rgba(0,217,163,0.08); border: 1px solid rgba(0,217,163,0.3);
  border-radius: 8px; font-size: 13px; color: var(--accent);
}

/* ─── 2026 polish: card depth + theme toggle + toasts ─────────────────────── */
.push-card, .alert-item, .drawer-row { box-shadow: var(--shadow-sm); }
.alert-item { border-radius: 12px; }
.chip { box-shadow: var(--shadow-sm); }
.login-wrap form#login-form input { box-shadow: var(--shadow-sm); }

/* theme toggle button in the drawer */
#btn-theme {
  display: flex; align-items: center; justify-content: space-between;
}
#btn-theme .theme-state { color: var(--accent); font-weight: 700; }

/* toasts (replace native alert popups) */
#toast-stack {
  position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100000; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg2); color: var(--text0);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 12px; padding: 13px 15px;
  box-shadow: var(--shadow); font-size: 14px; line-height: 1.4;
  pointer-events: auto; animation: toastIn 0.2s ease; transition: opacity 0.2s;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast .toast-x { margin-left: auto; color: var(--text2); font-size: 15px; padding-left: 8px; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Password show/hide (eye) toggle — wraps the input; button sits at its right. */
.pw-field { position: relative; display: block; }
.pw-field > input { padding-right: 46px !important; width: 100%; }
/* !important throughout: the login form styles ALL its buttons (Sign In), which
   would otherwise turn the eye into a green filled button. Force a flat icon. */
.pw-eye {
  position: absolute !important; right: 6px; top: 50%;
  transform: translateY(-50%) !important;
  width: 34px !important; height: 34px !important; min-width: 0 !important;
  padding: 0 !important; margin: 0 !important;
  background: none !important; border: none !important; box-shadow: none !important;
  border-radius: 6px !important; cursor: pointer;
  display: flex !important; align-items: center; justify-content: center;
  font-size: 18px !important; line-height: 1; color: var(--text2) !important; opacity: 0.6;
}
.pw-eye:active { opacity: 1; transform: translateY(-50%) !important; }

/* Rotation card in light mode: the dark-theme translucent teal/red wash reads as
   almost-white on a light ground, so restate the tints against the light tokens. */
:root[data-theme="light"] .rot-dom.now { background: rgba(0,158,120,0.09); border-color: rgba(0,158,120,0.32); }
:root[data-theme="light"] .rot-dom.was .rot-dom-d { text-decoration-color: rgba(220,43,64,0.85); }
:root[data-theme="light"] .rot-kind { background: rgba(220,43,64,0.10); border-color: rgba(220,43,64,0.30); }
