:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --sidebar-text: #cbd5e1;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { min-height: 100vh; overflow-x: hidden; background: var(--bg); color: var(--text); font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; }
button, input, select, textarea { font: inherit; }

.top-header { position: fixed; inset: 0 0 auto 0; height: 64px; z-index: 1000; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; color: white; background: linear-gradient(90deg, #111827, #1e293b); box-shadow: 0 2px 12px rgba(15,23,42,.24); }
.header-left, .header-right { display: flex; align-items: center; gap: 14px; }
.header-left h2 { line-height: 1; font-size: 20px; }
.header-left small { color: #cbd5e1; font-size: 12px; }
.toggle-btn, .search-btn { width: 42px; height: 42px; border: 0; border-radius: 12px; color: white; background: rgba(255,255,255,.08); cursor: pointer; }
.toggle-btn:hover, .search-btn:hover { background: rgba(255,255,255,.14); }
.user-menu-container { position: relative; }
.user-profile-btn { display: flex; align-items: center; gap: 8px; border: 0; color: white; background: rgba(255,255,255,.08); padding: 7px 10px; border-radius: 999px; cursor: pointer; }
.user-profile { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: #334155; }
.user-dropdown { position: absolute; top: calc(100% + 12px); right: 0; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); visibility: hidden; opacity: 0; transform: translateY(-6px); transition: .18s ease; overflow: hidden; }
.user-dropdown.show { visibility: visible; opacity: 1; transform: translateY(0); }
.user-dropdown a { display: flex; gap: 10px; align-items: center; padding: 12px 14px; color: var(--text); text-decoration: none; }
.user-dropdown a:hover { background: var(--surface-soft); color: var(--primary); }
.divider { height: 1px; background: var(--border); }

.app-container { display: flex; height: 100vh; padding-top: 64px; }
.sidebar { width: 260px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; padding: 14px 10px; color: var(--sidebar-text); background: linear-gradient(180deg, var(--sidebar-2), var(--sidebar)); transition: width .25s ease, left .25s ease; overflow-y: auto; }
.sidebar.collapsed { width: 76px; }
.menu-item { width: 100%; border: 0; background: transparent; color: inherit; text-decoration: none; }
.menu-link { display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 0 14px; border-radius: 14px; cursor: pointer; text-align: left; color: var(--sidebar-text); }
.menu-link:hover, .menu-link.active { color: white; background: rgba(255,255,255,.1); }
.menu-link.active { box-shadow: inset 3px 0 0 #60a5fa; }
.icon { width: 24px; text-align: center; font-size: 18px; }
.menu-text { white-space: nowrap; overflow: hidden; transition: opacity .16s ease; }
.sidebar.collapsed .menu-text, .sidebar.collapsed .arrow { opacity: 0; width: 0; display: none; }
.sidebar.collapsed .menu-link { justify-content: center; padding: 0; }
.arrow { margin-left: auto; transition: transform .2s ease; }
.has-dropdown.active .arrow { transform: rotate(90deg); }
.dropdown-menu { max-height: 0; overflow: hidden; transition: max-height .22s ease; }
.has-dropdown.active .dropdown-menu { max-height: 320px; }
.dropdown-item { display: block; margin: 4px 0 4px 52px; padding: 9px 10px; border-radius: 10px; color: #cbd5e1; text-decoration: none; }
.dropdown-item:hover { color: white; background: rgba(255,255,255,.08); }
.sidebar.collapsed .dropdown-menu { display: block; }
.sidebar-overlay { display: none; }
.sidebar-drawer-head { display: none; }

.main-content { flex: 1; min-width: 0; overflow-y: auto; padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.page-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 26px; margin-bottom: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(135deg, #ffffff, #eef5ff); box-shadow: var(--shadow); }
.page-hero h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.05; margin: 4px 0 8px; }
.page-hero p { color: var(--muted); max-width: 720px; }
.eyebrow { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--primary) !important; font-size: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card, .content-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card { padding: 18px; }
.stat-card p { color: var(--muted); font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.stat-card strong { display: block; font-size: 24px; }
.stat-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; margin-bottom: 10px; border-radius: 12px; color: var(--primary); background: #eff6ff; }
.content-card { padding: 20px; margin-bottom: 20px; }
.content-card h2 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin-bottom: 16px; }
.card-title-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 16px; }
.form-grid.two-col { grid-template-columns: repeat(2, minmax(200px, 1fr)); }
label { display: flex; flex-direction: column; gap: 7px; color: #334155; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; background: white; outline: none; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 4px rgba(37,99,235,.10); }
textarea { resize: vertical; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.button-row.compact { margin-top: 0; }
.primary-btn, .secondary-btn, .file-load-btn, .action-btn { border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer; font-weight: 800; }
.icon-btn {
  border: 0;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0f172a;
  background: #e2e8f0;
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover { background: #cbd5e1; }
.primary-btn { color: white; background: var(--primary); }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn, .file-load-btn { color: #0f172a; background: #e2e8f0; }
.secondary-btn:hover, .file-load-btn:hover { background: #cbd5e1; }

/* ============================================================
   Chores tab
   ============================================================ */
.chores-status-text { font-weight: 700; color: var(--text); }
/* .status-text is declared later in this file and overrides the plain
   .error-text/.success-text colors; scope a fix to this tab. */
#choresTab .error-text { color: #dc2626; }
#choresTab .success-text { color: #15803d; }

/* Kid view: the earned amount is the one big thing on the page */
.chores-earnings {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-left: 6px solid #16a34a;
}
.chores-earnings-label { color: var(--muted); font-weight: 700; }
.chores-earnings-amount {
  font-size: clamp(44px, 9vw, 72px); font-weight: 800; line-height: 1; letter-spacing: -.02em;
  color: #15803d; font-variant-numeric: tabular-nums; margin: 6px 0 8px;
}
.chores-earnings-sub { color: var(--muted); }

.chores-log-form { display: flex; gap: 10px; align-items: stretch; margin-top: 10px; flex-wrap: wrap; }
.chores-log-form textarea {
  flex: 1 1 260px; min-height: 52px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 12px; resize: vertical; font-size: 16px;
}
.chores-log-form textarea:focus, .chores-rate-input:focus, .chores-inline-form input:focus {
  outline: 2px solid var(--primary); outline-offset: 1px;
}

/* Parent: kid picker */
.chores-kid-card { cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%; }
.chores-kid-card:hover { border-color: var(--primary); }
.chores-kid-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.chores-kid-pending { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.chores-kid-pending.has-waiting { color: #b45309; font-weight: 700; }

/* Lists */
.chores-subhead { margin-top: 18px; font-size: 16px; }
.chores-item-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 20px; }
.chores-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); flex-wrap: wrap;
}
.chores-item-selectable { cursor: pointer; justify-content: flex-start; }
.chores-item-selectable .chores-item-amount { margin-left: auto; }
.chores-item-selectable input[type="checkbox"] { width: 18px; height: 18px; }
.chores-item-inactive { opacity: .6; }
.chores-item-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 200px; }
.chores-item-text strong { font-size: 15px; }
.chores-item-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.chores-item-amount { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chores-item-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chores-rate-field { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.chores-rate-input { width: 90px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.chores-all-kids { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
/* Global `label` is a flex column; keep these inline with their inputs. */
#choresTab .chores-rate-field,
#choresTab .chores-all-kids { flex-direction: row; gap: 4px; white-space: nowrap; }
#choresTab .chores-all-kids input { width: auto; }
#choresTab .form-help { color: var(--muted); font-size: 14px; font-weight: 400; }

/* Admin: households */
.chores-inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chores-inline-form input, .chores-inline-form select {
  flex: 1 1 180px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
}
.chores-inline-form button { flex: 0 0 auto; }
.chores-household-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 10px; }
.chores-household { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-soft); }
.chores-household h3 { font-size: 16px; margin-bottom: 8px; }
.chores-member-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.chores-member-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chores-role-tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; }
.chores-role-parent { background: #dbeafe; color: #1e40af; }
.chores-role-kid { background: #dcfce7; color: #166534; }

@media (max-width: 600px) {
  .chores-item-actions { width: 100%; }
  .chores-log-form .primary-btn { width: 100%; }
}

.danger-btn { border: 0; border-radius: 12px; padding: 11px 14px; cursor: pointer; font-weight: 800; color: white; background: #dc2626; }
.danger-btn:hover { background: #b91c1c; }
.file-load-btn input { display: none; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f8fafc; color: #334155; font-size: 13px; }
.action-btn { padding: 8px 10px; margin-right: 6px; }
.edit-btn { color: #92400e; background: #fef3c7; }
.delete-btn { color: #991b1b; background: #fee2e2; }
.summary-box { line-height: 1.7; padding: 16px; border-radius: 14px; background: #f8fafc; color: #334155; }
.schedule-wrap { max-height: 460px; overflow: auto; }

@media (max-width: 1000px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .top-header { padding: 0 12px; }
  .header-left small { display: none; }
  .header-left h2 { font-size: 17px; }
  .sidebar { position: fixed; top: 64px; bottom: 0; left: -280px; width: 260px; z-index: 999; padding-bottom: 24px; }
  .sidebar.mobile-open { left: 0; box-shadow: 12px 0 32px rgba(15,23,42,.28); }
  .sidebar.collapsed { width: 260px; }
  .sidebar.collapsed .menu-text, .sidebar.collapsed .arrow { display: inline; opacity: 1; width: auto; }
  .sidebar.collapsed .menu-link { justify-content: flex-start; padding: 0 14px; }
  .sidebar-overlay.active { display: block; position: fixed; inset: 64px 0 0 0; background: rgba(15,23,42,.48); z-index: 998; }
  .menu-link { min-height: 50px; }
  .sidebar-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,.1);
  }
  .sidebar-drawer-title { opacity: 1 !important; width: auto !important; display: inline !important; color: white; font-weight: 800; font-size: 15px; }
  .sidebar-drawer-close { width: 36px; height: 36px; border: 0; border-radius: 10px; background: rgba(255,255,255,.08); color: white; cursor: pointer; }

  .main-content { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); }
  .page-hero { flex-direction: column; align-items: flex-start; padding: 18px; gap: 14px; }
  .page-hero .primary-btn { width: 100%; justify-content: center; display: inline-flex; align-items: center; gap: 8px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 19px; }
  .form-grid, .form-grid.two-col { grid-template-columns: 1fr; }
  .content-card { padding: 16px; }

  /* Bigger, easier tap targets */
  .primary-btn, .secondary-btn, .file-load-btn, .action-btn, input, select {
    min-height: 44px;
  }
  .action-btn { margin-right: 0; }
  .button-row { gap: 8px; }
  .button-row .action-btn { flex: 1 1 auto; }
  .card-title-row { align-items: flex-start; }
  .card-title-row .button-row.compact { width: 100%; }
  .card-title-row .button-row.compact .secondary-btn,
  .card-title-row .button-row.compact .file-load-btn { flex: 1 1 auto; text-align: center; }

  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* ---------- Bottom tab bar (mobile only) ---------- */
.bottom-nav { display: none; }

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 997;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(15,23,42,.10);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav-item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 12px;
    cursor: pointer;
  }
  .bottom-nav-item i { font-size: 17px; }
  .bottom-nav-item span { font-size: 11px; font-weight: 700; }
  .bottom-nav-item:active { background: var(--surface-soft); }
  .bottom-nav-item.active { color: var(--primary); }
}

/* ---------- Responsive "card" tables ---------- */
@media (max-width: 768px) {
  table.responsive-table { min-width: 0; }
  table.responsive-table thead { display: none; }
  table.responsive-table tbody { display: block; }
  table.responsive-table tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 12px;
    padding: 4px 12px;
    background: var(--surface);
  }
  table.responsive-table tbody tr td[colspan] { border: 0; padding: 12px 4px; }
  table.responsive-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  table.responsive-table tbody td:last-child { border-bottom: 0; }
  table.responsive-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    text-align: left;
    margin-right: auto;
  }
  table.responsive-table tbody td.action-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  table.responsive-table tbody td.action-cell::before { margin-bottom: 2px; }
  table.responsive-table tbody td.action-cell .action-btn { width: 100%; margin: 0; }
  table.responsive-table.admin-table select, table.responsive-table select { width: 100%; min-width: 0; }

  /* Schedule table stays a true table (too many dynamic columns for cards) —
     keep it scrollable but pin the first two columns so Pmt#/Date stay visible */
  .schedule-wrap table th:first-child, .schedule-wrap table td:first-child,
  .schedule-wrap table th:nth-child(2), .schedule-wrap table td:nth-child(2) {
    position: sticky;
    background: var(--surface);
    z-index: 1;
  }
  .schedule-wrap table th:first-child, .schedule-wrap table td:first-child { left: 0; }
  .schedule-wrap table th:nth-child(2), .schedule-wrap table td:nth-child(2) { left: 56px; }
  .schedule-wrap table th { background: #f8fafc; }
}

.error-text {
  color: #dc2626;
  font-weight: 700;
}

/* Accessible focus ring for keyboard/switch users, without adding
   an outline on mouse click */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .auth-modal-close, .nexis-json-close {
    width: 44px; height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
  }
}

.action-cell {
  white-space: nowrap;
}

.user-dropdown a.is-working { pointer-events: none; opacity: .75; }

/* Auth menu state */
.hidden {
  display: none !important;
}

.user-profile-btn.logged-out span {
  min-width: 46px;
  font-size: 12px;
}

.user-profile-btn.logged-in span {
  min-width: auto;
}

/* Small status dot on the avatar so login state is visible at a
   glance without opening the dropdown. */
.user-profile-btn { position: relative; }
.user-profile-btn::after {
  content: "";
  position: absolute;
  bottom: 4px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid #1e293b;
  background: #64748b;
}
.user-profile-btn.logged-in::after { background: #22c55e; }
.user-profile-btn.logged-out::after { background: #64748b; }

.user-dropdown a.is-working {
  pointer-events: none;
  opacity: 0.75;
}


/* User/Admin Settings */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.full-span {
  grid-column: 1 / -1;
}

.status-text {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 700;
}

.success-text {
  color: #15803d;
}

.admin-create-form {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.admin-create-form h3 {
  margin-bottom: 12px;
}

.form-action-align {
  display: flex;
  align-items: end;
}

.admin-table select {
  min-width: 130px;
  padding: 8px 10px;
}

.admin-table td {
  vertical-align: middle;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.55);
}

.auth-modal.hidden {
  display: none !important;
}

.auth-modal-card {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.auth-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 28px;
  cursor: pointer;
}


/* NexisPlat chat result containment and full JSON viewer */
.nexis-chat-jobs,
.nexis-job-card,
.nexis-job-header,
.nexis-job-result,
.nexis-message-text {
  min-width: 0;
  max-width: 100%;
}

.nexis-job-card {
  width: 100%;
  overflow: hidden;
}

.nexis-job-prompt,
.nexis-job-status,
.nexis-message-text,
.nexis-job-id {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.nexis-job-result {
  max-height: 520px;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: .4rem;
}

.nexis-job-result h4 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 0 .65rem;
  padding: .35rem 0;
  background: var(--surface, #fff);
}

.nexis-message-text {
  white-space: pre-wrap;
  line-height: 1.55;
}

.nexis-code-block {
  max-width: 100%;
  overflow: auto;
  white-space: pre;
}

.nexis-json-modal {
  position: fixed;
  inset: 0;
  z-index: 120000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .72);
}

.nexis-json-modal.hidden {
  display: none !important;
}

.nexis-json-modal-card {
  width: min(1100px, calc(100vw - 36px));
  height: min(820px, calc(100vh - 36px));
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 16px;
  background: var(--surface, #fff);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .35);
}

.nexis-json-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.nexis-json-modal-header h2 {
  margin: 0 0 4px;
}

.nexis-json-job-id {
  color: var(--muted, #64748b);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.nexis-json-close {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.nexis-json-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.nexis-json-output {
  flex: 1;
  min-height: 0;
  max-width: 100%;
  margin: 0;
  padding: 18px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  white-space: pre;
  tab-size: 2;
}

.nexis-json-output code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.nexis-json-error {
  padding: 16px 18px;
}

.nexis-history-modal-card {
  height: min(560px, calc(100vh - 36px));
}

.nexis-history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 14px 14px;
}

@media (max-width: 600px) {
  .nexis-job-result {
    max-height: 420px;
  }

  .nexis-json-modal {
    padding: 8px;
  }

  .nexis-json-modal-card {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
  }
}

/* ============================================================
   Chat thread (conversation-style layout for the NexisPlat chat)
   ============================================================ */
.nexis-chat-card { display: flex; flex-direction: column; }

.nexis-chat-thread {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 60vh;
  min-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 4px 10px;
  margin-bottom: 14px;
  scroll-behavior: smooth;
}

.nexis-chat-empty {
  margin: auto;
  color: var(--muted);
  font-style: italic;
  padding: 24px 0;
  text-align: center;
}

.nexis-chat-login-action {
  display: block;
  margin: 0 auto;
}

.nexis-turn { display: flex; flex-direction: column; gap: 8px; }

.nexis-bubble {
  max-width: 82%;
  border-radius: 16px;
  padding: 12px 14px;
  min-width: 0;
}

.nexis-bubble-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.nexis-bubble-user {
  align-self: flex-end;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-bottom-right-radius: 4px;
}

.nexis-bubble-user .nexis-bubble-label { justify-content: flex-end; }

.nexis-bubble-label .nexis-diagnostics-btn {
  width: 22px;
  height: 22px;
  font-size: 13px;
  background: transparent;
  color: var(--muted, #64748b);
  margin-left: auto;
}
.nexis-bubble-label .nexis-diagnostics-btn:hover { background: var(--surface, #e2e8f0); color: var(--primary); }

/* Copy buttons (per message, per code block) */
.nexis-bubble-label .nexis-copy-btn {
  width: 22px;
  height: 22px;
  font-size: 12px;
  background: transparent;
  color: var(--muted, #64748b);
  opacity: .55;
}
.nexis-bubble-assistant .nexis-bubble-label .nexis-copy-btn { margin-left: auto; }
.nexis-bubble-assistant .nexis-bubble-label .nexis-diagnostics-btn:not([hidden]) + .nexis-copy-btn,
.nexis-bubble-assistant .nexis-bubble-label .nexis-diagnostics-btn:not([hidden]) ~ .nexis-copy-btn { margin-left: 0; }
.nexis-bubble:hover .nexis-copy-btn,
.nexis-copy-btn:focus-visible,
.nexis-copy-btn.nexis-copy-flash { opacity: 1; }
.nexis-copy-btn:hover { background: var(--surface, #e2e8f0); color: var(--primary); }
.nexis-copy-btn.nexis-copy-flash { color: var(--primary); }

.nexis-code-wrap { position: relative; }
.nexis-code-wrap .nexis-code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--surface-soft, #f1f5f9);
  border: 1px solid var(--border, #e2e8f0);
  color: var(--muted, #64748b);
  opacity: .7;
}
.nexis-code-wrap:hover .nexis-code-copy-btn { opacity: 1; }

.nexis-bubble-assistant {
  align-self: flex-start;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  width: 100%;
  max-width: 92%;
}

.nexis-bubble-text {
  white-space: pre-wrap;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.nexis-bubble-attachments {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.nexis-bubble-status {
  font-size: 14px;
  color: var(--muted);
}

.nexis-bubble-result {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  max-height: 480px;
  overflow: auto;
}

.nexis-status-pill {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: .03em;
  background: #e2e8f0;
  color: #334155;
}

.nexis-status-queued, .nexis-status-running { background: #dbeafe; color: #1e3a8a; }
.nexis-status-complete { background: #dcfce7; color: #14532d; }
.nexis-status-failed { background: #fee2e2; color: #7f1d1d; }

.nexis-progress-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 3px;
  background: #e2e8f0;
  overflow: hidden;
}
.nexis-progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width .4s ease;
  width: 0%;
}

.nexis-findings-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
}
.nexis-findings-table th,
.nexis-findings-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.nexis-findings-table th {
  font-weight: 700;
  color: #475569;
}
.nexis-limitations,
.nexis-citations {
  margin-top: 10px;
  font-size: 12px;
  color: #64748b;
}

.nexis-composer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.nexis-composer textarea { margin-top: 10px; }

@media (max-width: 768px) {
  .nexis-bubble { max-width: 92%; }
  .nexis-chat-thread { max-height: 50vh; }
}

/* ============================================================
   Admin dashboard tools (Home tab, admins only)
   ============================================================ */
.admin-badge {
  font-size: 12px;
  font-weight: 800;
  color: #92400e;
  background: #fef3c7;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.admin-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 14px;
}

.admin-tool-tile {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface-soft);
}

.admin-tool-tile h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  margin-bottom: 8px;
}

.admin-tool-tile p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
}

.presence-embed-wrap { margin-top: 12px; }
.presence-embed-wrap.hidden { display: none; }

/* ---------- Floating chat button + floating chat panel ---------- */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  background: var(--primary);
  box-shadow: 0 12px 28px rgba(37,99,235,.35);
  cursor: pointer;
  z-index: 90000;
  transition: transform .15s ease, background .15s ease;
}
.chat-fab:hover { background: var(--primary-dark); transform: translateY(-1px); }
.chat-fab:active { transform: translateY(0); }

.tab-panel.chat-floating {
  display: block;
  position: fixed;
  right: 20px;
  bottom: 92px;
  width: min(420px, calc(100vw - 40px));
  max-height: min(640px, calc(100vh - 140px));
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(15,23,42,.35);
  padding: 16px;
  z-index: 89999;
}
.tab-panel.chat-floating .page-hero { display: none; }

.chat-float-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  margin-bottom: 10px;
  margin-left: auto;
}
.tab-panel.chat-floating .chat-float-close { display: inline-flex; }

@media (max-width: 768px) {
  .chat-fab {
    right: 16px;
    bottom: calc(78px + env(safe-area-inset-bottom));
  }
  .tab-panel.chat-floating {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: calc(146px + env(safe-area-inset-bottom));
    max-height: min(70vh, calc(100vh - 220px));
  }
}

/* Network status tile */
.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot-online { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.status-dot-offline { background: #cbd5e1; }
.device-type-badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 2px 8px;
  border-radius: 999px;
}
.device-type-tailscale { background: #eff6ff; color: #1d4ed8; }
.device-type-wireguard { background: #f0fdf4; color: #15803d; }
.network-status-stale-note { color: #b45309; }

.presence-embed-frame {
  width: 100%;
  height: 480px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
}

@media (max-width: 768px) {
  .admin-tools-grid { grid-template-columns: 1fr; }
  .presence-embed-frame { height: 400px; }
}
/* ============================================================
   PWA / installed-app support
   With viewport-fit=cover and a black-translucent status bar, the
   app draws under the phone's status bar and home indicator. These
   rules push the header and edges back into the safe area. All
   env() values are 0 on desktop, so nothing changes there.
   ============================================================ */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --header-h: calc(64px + var(--safe-top));
}

.top-header {
  height: var(--header-h);
  padding-top: var(--safe-top);
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}

.app-container {
  padding-top: var(--header-h);
  height: 100vh;
  height: 100dvh; /* iOS: excludes the collapsing browser toolbar */
}

@media (max-width: 768px) {
  .top-header {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .sidebar { top: var(--header-h); }
  .sidebar-overlay.active { inset: var(--header-h) 0 0 0; }

  /* iOS zooms the page when focusing any field under 16px */
  input, select, textarea { font-size: 16px; }
}

/* Only when launched from the home screen */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }       /* no rubber-band bounce revealing blank space */
  button, .menu-link, .chat-fab { -webkit-tap-highlight-color: transparent; }
}

/* ============================================================
   Mobile chat: full-screen layout
   On phones the chat (whether opened from the menu or the floating
   button) fills the space under the header. The message thread gets
   whatever height is left and scrolls on its own; the input and Send
   button stay pinned at the bottom. The big drag-and-drop box is
   replaced by a paperclip button, since phones can't drag files.
   ID selectors are used on purpose so these win over the chat styles
   in index.html's inline <style> block.
   ============================================================ */
.nexis-attach-btn { display: none; }

@media (max-width: 768px) {
  #setupTab.active {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: none;
    z-index: 990;               /* under the sidebar drawer (998/999) and modals */
    display: flex;
    flex-direction: column;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }
  #setupTab .page-hero { display: none; }
  #setupTab .chat-float-close { flex-shrink: 0; margin: 0 0 6px auto; }

  #setupTab .nexis-chat-card {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 12px;
  }
  #setupTab .nexis-chat-card > .form-help { display: none; }
  #setupTab .nexis-chat-card h2 { font-size: 17px; margin-bottom: 8px; }

  #setupTab .nexis-chat-thread {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin-bottom: 8px;
  }
  #setupTab .nexis-file-list { flex-shrink: 0; margin-bottom: 6px; }

  #setupTab .nexis-composer { flex-shrink: 0; padding-top: 8px; }
  #setupTab .nexis-dropzone { display: none; }
  #setupTab .nexis-composer textarea {
    margin-top: 0;
    min-height: 48px;
    max-height: 30vh;
    resize: none;
  }
  #setupTab .nexis-chat-toolbar { justify-content: space-between; margin: 8px 0 0; }
  #setupTab .nexis-attach-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 48px; }

  /* The floating chat button would sit on top of Send while chat is open */
  body:has(#setupTab.active) .chat-fab { display: none; }
}

/* Files tab: the whole "Upload a File" card is a tap/drop target */
.upload-target-card { cursor: pointer; }
.upload-target-card input,
.upload-target-card select,
.upload-target-card textarea,
.upload-target-card #filesJobs { cursor: auto; }

/* Login modal: "Keep me signed in" checkbox row */
.login-remember { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.login-remember input { width: 20px; height: 20px; min-height: 0; flex: 0 0 auto; margin: 0; accent-color: var(--primary); }

/* ============================================================
   Document camera (camera-scan.js)
   ============================================================ */
.nexis-camera-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  margin-right: auto;          /* keeps it at the left; Send stays right */
}
#setupTab .nexis-attach-btn + .nexis-camera-btn { margin-left: 8px; }

body.cam-scan-open { overflow: hidden; }

.cam-scan {
  position: fixed;
  inset: 0;
  z-index: 130000;             /* above header, drawer and modals */
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  user-select: none;
  -webkit-user-select: none;
}
.cam-scan.hidden { display: none; }

.cam-top, .cam-bottom {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}
.cam-count { font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }

.cam-icon-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.cam-icon-btn.active { background: #facc15; color: #111827; }

.cam-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.cam-stage video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}
.cam-frame {
  position: absolute;
  inset: 6% 8%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 10px;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.18);
}
.cam-flash {
  position: absolute; inset: 0;
  background: #fff; opacity: 0;
  pointer-events: none;
}
.cam-flash.on { animation: cam-flash 0.25s ease-out; }
@keyframes cam-flash { from { opacity: 0.85; } to { opacity: 0; } }

.cam-message {
  position: absolute;
  left: 16px; right: 16px; top: 50%;
  transform: translateY(-50%);
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.9);
  text-align: center;
  line-height: 1.45;
}
.cam-message.hidden { display: none; }

.cam-strip {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  min-height: 84px;
  padding: 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.cam-thumb {
  position: relative;
  flex: 0 0 56px;
  height: 72px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #1f2937;
}
.cam-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-thumb span {
  position: absolute; left: 3px; bottom: 3px;
  min-width: 18px; padding: 0 4px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff; font-size: 11px; font-weight: 700;
}
.cam-thumb.selected { border-color: #60a5fa; }

.cam-page-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 12px 8px;
}
.cam-page-tools.hidden { display: none; }
.cam-page-tools span { min-width: 104px; text-align: center; font-size: 14px; }
.cam-page-tools button {
  width: 44px; height: 40px;
  border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff; font-size: 16px;
}
.cam-page-tools button:disabled { opacity: 0.3; }
.cam-page-tools .cam-danger { background: #b91c1c; }

.cam-bottom { padding-bottom: 16px; }
.cam-shutter {
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 0 0 4px #000;
}
.cam-shutter:active { background: #fff; }
.cam-side-btn {
  width: 72px;
  border: 0;
  background: transparent;
  color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 20px;
}
.cam-side-btn span { font-size: 12px; font-weight: 600; }
.cam-done { color: #4ade80; }
.cam-done:disabled { color: rgba(255, 255, 255, 0.3); }

/* Many scanned pages shouldn't push the input off screen */
@media (max-width: 768px) {
  #setupTab .nexis-file-list { max-height: 88px; overflow-y: auto; }
}

/* Buttons hidden via the hidden attribute must stay hidden even when a
   button class sets its own display */
#pushPanel [hidden] { display: none !important; }

/* Settings on phones: a wide child (admin user table) was stretching the
   whole grid past the screen edge. Let columns shrink and wide content
   scroll inside its own card instead. */
.settings-grid { grid-template-columns: minmax(0, 1fr); }
.settings-grid > .content-card { min-width: 0; overflow-x: auto; }
.push-diag { font-size: 12px; opacity: 0.75; margin-top: 6px; }
