:root {
  --bg: #090d16;
  --bg-elev: #111827;
  --bg-card: #151e30;
  --bg-hover: #1e293b;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-hover: #059669;
  --gold: #f59e0b;
  --danger: #ef4444;
  --blue: #3b82f6;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-top: var(--safe-top);
  padding-bottom: calc(74px + var(--safe-bottom));
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.ios-banner {
  background: linear-gradient(90deg, #065f46, #047857);
  color: #ecfdf5;
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px 32px;
}

.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  object-fit: cover;
  box-shadow: 0 3px 12px rgba(16, 185, 129, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.brand h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  font-size: 12px;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Navigation: Desktop top bar, Mobile bottom iOS dock */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  background: var(--bg-elev);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  position: relative;
  transition: all 0.16s ease;
}

.nav-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-btn.active {
  background: var(--bg-card);
  color: #34d399;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.nav-badge {
  background: var(--accent);
  color: #052e16;
  font-size: 11px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
}

.badge-gold {
  background: var(--gold);
  color: #451a03;
}

@media (max-width: 720px) {
  .tab-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 6px 6px calc(6px + var(--safe-bottom));
    z-index: 50;
  }
  .nav-btn {
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    padding: 6px 4px;
  }
  .nav-icon {
    font-size: 17px;
  }
  .nav-badge {
    position: absolute;
    top: 2px;
    right: 14%;
  }
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.card,
.toolbar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.toolbar-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbar-card h2 {
  font-size: 17px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease, opacity 0.15s ease, background 0.15s ease;
  color: var(--text);
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #042f2e;
}
.btn-primary:hover {
  background: #34d399;
}

.btn-secondary {
  background: var(--bg-hover);
  border-color: var(--border);
}

.btn-gold {
  background: var(--gold);
  color: #451a03;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.btn-icon {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--muted);
}

.pill-high {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}
.pill-medium {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
}
.pill-low {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}
.pill-amber {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}
.pill-green {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
}

.filter-group,
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.flex-1 {
  flex: 1;
  min-width: 210px;
}

.input-text,
.input-select,
.input-textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: inherit;
}

.input-textarea {
  width: 100%;
  resize: vertical;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.mt-8 {
  margin-top: 8px;
}
.mt-12 {
  margin-top: 12px;
}
.mb-10 {
  margin-bottom: 10px;
}

.chat-kind-btn.active {
  background: var(--accent);
  color: #042f2e;
  border-color: transparent;
}

/* Interactive Assistant Q&A Chat */
.qa-shell {
  display: flex;
  flex-direction: column;
  min-height: 68vh;
}

.qa-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.qa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0;
}

.qa-messages {
  flex: 1;
  min-height: 300px;
  max-height: 54vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 4px;
}

.qa-bubble {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: 13px;
  font-size: 13.8px;
  white-space: pre-wrap;
}

.qa-bubble.user {
  align-self: flex-end;
  background: #065f46;
  color: #ecfdf5;
  border-bottom-right-radius: 4px;
}

.qa-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.qa-actions-taken {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.qa-input-bar {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Digest cards */
.digest-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.digest-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.digest-exec {
  font-size: 14.5px;
  background: rgba(16, 185, 129, 0.08);
  border-left: 3px solid var(--accent);
  padding: 10px 13px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.stats-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chat-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.chat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px;
}

.chat-card h4 {
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-card ul {
  padding-left: 17px;
  font-size: 13px;
  color: #cbd5e1;
}
.chat-card li {
  margin-bottom: 4px;
}

/* Tasks & Billables */
.cards-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.task-card.done {
  opacity: 0.66;
}

.task-check {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--accent);
  background: transparent;
  color: #052e16;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.task-check.checked {
  background: var(--accent);
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.task-title {
  font-size: 15px;
  font-weight: 600;
}

.done .task-title {
  text-decoration: line-through;
}

.quote-box {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-elev);
  padding: 6px 10px;
  border-radius: 7px;
  border-left: 2px solid #475569;
}

.comments-box {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.comment-item {
  font-size: 12.5px;
  background: rgba(59, 130, 246, 0.1);
  color: #dbeafe;
  padding: 6px 10px;
  border-radius: 7px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
}

.kpi-box .kpi-val {
  font-size: 22px;
  font-weight: 800;
  margin-top: 3px;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 14px;
}

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.list-row {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.status-banner {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
}

.qr-box {
  margin-top: 12px;
  background: #ffffff;
  padding: 14px;
  border-radius: 12px;
  text-align: center;
  color: #0f172a;
}
.qr-box img {
  max-width: 240px;
  height: auto;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  padding: 18px;
}

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

.toast {
  position: fixed;
  bottom: calc(84px + var(--safe-bottom));
  right: 18px;
  background: #065f46;
  color: #ecfdf5;
  border: 1px solid #10b981;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Observed Chat Tilde (Checkbox) & Categorization Rows */
.chat-obs-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  transition: border-color 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.chat-obs-row.is-observed {
  border-color: rgba(16, 185, 129, 0.42);
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.07) 0%, var(--bg-elev) 36%);
}

.chat-obs-row.is-ignored {
  opacity: 0.72;
}

.obs-check-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-top: 2px;
  flex-shrink: 0;
  user-select: none;
}

.obs-check-wrap input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.obs-check-box {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.7);
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  transition: all 0.15s ease;
}

.obs-check-wrap:hover .obs-check-box {
  border-color: var(--accent);
}

.obs-check-wrap input:checked + .obs-check-box {
  background: var(--accent);
  border-color: var(--accent);
  color: #042f2e;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

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

.chat-obs-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-obs-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-obs-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.group-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-top: 10px;
  margin-bottom: 4px;
  background: rgba(30, 41, 59, 0.65);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 700;
}
