:root {
  --navy: #14303d;
  --navy-deep: #0d2129;
  --slate: #5f7d8c;
  --slate-light: #90a8b3;
  --bg: #ffffff;
  --bg-panel: #f5f8f9;
  --bg-field: #ffffff;
  --border-subtle: #e1e8eb;
  --accent-glow: rgba(20, 48, 61, 0.1);
  --text-primary: #14303d;
  --text-secondary: #5b6b74;
  --text-muted: #98a7ad;
  --danger: #c0392b;
  --danger-bg: #fbeaea;
  --success: #1f7a4d;
  --success-bg: #e6f4ec;
  --warning: #946200;
  --warning-bg: #fdf0da;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* Any author `display` rule below (.modal-overlay, .badge, ...) would
   otherwise beat the browser's built-in [hidden] { display: none }, leaving
   the element on screen even though JS set hidden = true. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 12% 15%, rgba(95, 125, 140, 0.07), transparent 45%),
    radial-gradient(circle at 88% 85%, rgba(20, 48, 61, 0.05), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

.portal {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  width: min(920px, 92vw);
  min-height: 560px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(20, 48, 61, 0.12);
}

/* Brand panel */
.brand-panel {
  background: var(--bg-panel);
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--border-subtle);
}

.brand-mark {
  margin-bottom: 40px;
}

.brand-logo {
  max-width: 260px;
  width: 100%;
  height: auto;
  display: block;
}

.brand-panel h1 {
  font-size: 1.9rem;
  line-height: 1.3;
  margin: 0 0 16px;
  font-weight: 650;
  color: var(--navy);
}

.brand-panel p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0 0 28px;
  font-size: 0.95rem;
}

.brand-points {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-points li {
  position: relative;
  padding-left: 26px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.brand-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-glow);
  border: 1px solid var(--slate);
}

.brand-points li::after {
  content: "✓";
  position: absolute;
  left: 3px;
  top: -1px;
  font-size: 0.65rem;
  color: var(--navy);
}

/* Form panel */
.form-panel {
  padding: 48px 44px;
  display: flex;
  align-items: center;
  background: var(--bg);
}

form { width: 100%; }

.mobile-logo {
  display: none;
  max-width: 180px;
  height: auto;
  margin: 0 auto 28px;
}

.form-header { margin-bottom: 28px; }
.form-header h2 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 650; color: var(--navy); }
.form-header p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-field);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder { color: var(--text-muted); }

.field input:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field input.invalid {
  border-color: var(--danger);
}

.password-wrap { position: relative; }

.password-wrap input { padding-right: 44px; }

.toggle-visibility {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  display: flex;
  border-radius: 6px;
  transition: color 0.15s ease;
}
.toggle-visibility:hover { color: var(--navy); }
.toggle-visibility.active { color: var(--slate); }

.error-msg {
  display: block;
  min-height: 18px;
  color: var(--danger);
  font-size: 0.78rem;
  margin-top: 5px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--navy);
  cursor: pointer;
}

.link-muted {
  font-size: 0.85rem;
  color: var(--slate);
  text-decoration: none;
}
.link-muted:hover { color: var(--navy); text-decoration: underline; }

.submit-btn {
  width: 100%;
  padding: 13px;
  background: var(--navy);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s ease, transform 0.1s ease;
}

.submit-btn:hover { background: var(--navy-deep); }
.submit-btn:active { transform: scale(0.99); }
.submit-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.status-msg {
  min-height: 20px;
  text-align: center;
  font-size: 0.85rem;
  margin-top: 12px;
}
.status-msg.success { color: var(--navy); }
.status-msg.error { color: var(--danger); }

.signup-line {
  text-align: center;
  margin: 22px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.signup-line a { color: var(--slate); text-decoration: none; font-weight: 600; }
.signup-line a:hover { color: var(--navy); text-decoration: underline; }

@media (max-width: 760px) {
  .portal { grid-template-columns: 1fr; width: 94vw; }
  .brand-panel { display: none; }
  .form-panel { padding: 36px 28px; }
  .mobile-logo { display: block; }
}

/* Dashboard */
.dashboard-body {
  display: block;
  align-items: initial;
  justify-content: initial;
}

/* Stacking order, one scale for the whole app. These must stay ordered:
     1   page content (.dashboard-main, .portal)
     10  header — MUST beat content, or the account dropdown hangs over
         .dashboard-main and every click in it lands on main instead of the
         menu. The dropdown's own z-index can't save it: it lives inside the
         header's stacking context, so it can never rise above a sibling of
         the header itself.
     40  account dropdown (within the header's context)
     100 drawer scrim
     110 drawer
     200 modals — above everything, including an open drawer */
.dashboard-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 44px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
}

.dashboard-logo {
  height: 40px;
  width: auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--navy);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--bg-panel); border-color: var(--slate-light); }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--navy);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Header popovers — account menu and notifications share the shell */
.header-popover { position: relative; }

.popover-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 224px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(20, 48, 61, 0.16);
  padding: 6px;
  z-index: 40;
}

.popover-title {
  padding: 10px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}

/* Notifications */
.notif-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1;
  border: 2px solid var(--bg);
}

.notif-panel {
  width: 320px;
  max-width: calc(100vw - 32px);
  max-height: 380px;
  overflow-y: auto;
}

.notif-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
}
.notif-item:hover { background: var(--bg-panel); }

.notif-item-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--navy);
  word-break: break-all;
}
.notif-item-detail {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.notif-item-when {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.notif-empty {
  margin: 0;
  padding: 16px 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.profile-dropdown-email {
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 6px;
  word-break: break-all;
}

.profile-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: pointer;
}
.profile-dropdown-item:hover { background: var(--bg-panel); }

/* Journal entry builder */
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.users-table th.num, .users-table td.num { text-align: right; }

.journal-meta {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.journal-meta .field { margin-bottom: 0; }
.journal-memo { flex: 1; min-width: 220px; }
.journal-meta input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-field);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}
.journal-meta input:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.journal-table select,
.journal-table input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-field);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
}
.journal-table input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.journal-table select:focus,
.journal-table input:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.journal-totals td {
  font-weight: 700;
  border-top: 2px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}
.journal-balance td { border-bottom: none; padding-top: 6px; }

/* Qualified with .users-table td: the bare class alone loses to
   `.users-table td { color: var(--text-primary) }`, which would silently
   strip the red off the out-of-balance warning. */
.users-table td.balance-ok,
.balance-ok { color: var(--success); font-weight: 600; font-size: 0.85rem; }
.users-table td.balance-bad,
.balance-bad { color: var(--danger); font-weight: 600; font-size: 0.85rem; }

.journal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Module tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.tile {
  display: block;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.tile:hover {
  border-color: var(--slate);
  box-shadow: 0 10px 26px rgba(20, 48, 61, 0.09);
}
.tile:active { transform: translateY(1px); }

.tile h2 { margin: 0 0 6px; font-size: 1rem; color: var(--navy); }
.tile p { margin: 0; font-size: 0.84rem; color: var(--text-secondary); line-height: 1.5; }

.tile-inert { opacity: 0.6; cursor: default; }
.tile-inert:hover { border-color: var(--border-subtle); box-shadow: none; }

.tile-soon {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Slide-out drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 48, 61, 0.45);
  opacity: 0;
  visibility: hidden;
  /* pointer-events, not just visibility: visibility only flips at the end of
     the transition, so without this the fading-out overlay keeps swallowing
     clicks on the header for another 220ms. */
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  z-index: 100;
}
.drawer-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 82vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border-subtle);
  box-shadow: 0 0 40px rgba(20, 48, 61, 0.12);
  transform: translateX(-100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.22s ease, visibility 0.22s ease;
  z-index: 110;
}
.drawer.open { transform: translateX(0); visibility: visible; pointer-events: auto; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.drawer-header h2 { margin: 0; font-size: 1rem; color: var(--navy); }

.drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 12px;
  overflow-y: auto;
}

.drawer-section-label {
  padding: 14px 12px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.drawer-link {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
}
.drawer-link:hover { background: var(--bg-panel); }
.drawer-link.active { background: var(--accent-glow); color: var(--navy); font-weight: 600; }
.drawer-link-inert { color: var(--text-muted); cursor: default; }
.drawer-link-inert:hover { background: none; }
.drawer-link-child { padding-left: 26px; font-size: 0.86rem; }

.drawer-admin-link { margin-top: 14px; border-top: 1px solid var(--border-subtle); padding-top: 14px; border-radius: 0; }

.drawer-empty {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.dashboard-main {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 82px);
  padding: 40px 24px;
}

.dashboard-content {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.welcome-card {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
}

.welcome-card h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
  color: var(--navy);
}

.user-email {
  margin: 0 0 18px;
  color: var(--slate);
  font-weight: 600;
}

.welcome-sub {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.6;
  font-size: 0.92rem;
}

/* Admin */
.admin-main {
  align-items: flex-start;
  padding-top: 56px;
}

.admin-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.admin-card {
  width: min(880px, 100%);
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 32px;
}

.admin-card-header { margin-bottom: 20px; }
.admin-card-header h1 { margin: 0 0 6px; font-size: 1.4rem; color: var(--navy); }
.admin-card-header p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }

.empty-msg {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 20px 0;
  text-align: center;
}

.table-wrap { overflow-x: auto; }

.users-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.users-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.users-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-approved { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }
.badge-role { background: var(--accent-glow); color: var(--navy); margin-right: 4px; }

.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }

.action-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--bg);
  color: var(--text-primary);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.approve-btn { border-color: var(--success); color: var(--success); }
.approve-btn:hover { background: var(--success-bg); }
.reject-btn { border-color: var(--danger); color: var(--danger); }
.reject-btn:hover { background: var(--danger-bg); }
.pending-btn:hover { background: var(--bg-panel); border-color: var(--slate-light); }
.access-btn { border-color: var(--slate); color: var(--slate); }
.access-btn:hover { background: var(--bg-panel); border-color: var(--navy); color: var(--navy); }

/* Modules */
.module-add-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.module-add-form input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-field);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.module-add-form input:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.module-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.module-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-size: 0.9rem;
}

/* Access modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 48, 61, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Above the drawer (110), not below it — at the old value of 10 the
     change-password modal opened underneath an open drawer. */
  z-index: 200;
  padding: 24px;
}

.modal {
  width: min(480px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(20, 48, 61, 0.25);
}

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

.modal-header h2 { margin: 0; font-size: 1.15rem; color: var(--navy); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.modal-close:hover { color: var(--navy); }

.access-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.access-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.access-list-child { padding-left: 18px; }
.access-list-child span { color: var(--text-secondary); font-size: 0.85rem; }

.access-note {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.module-list-child { margin-left: 20px; border-style: dashed; }

.module-slug {
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.access-list-item select {
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-field);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ------------------------------------------------------------------ */
/* Forms laid out as a grid — the transaction, project and memo pages   */
/* ------------------------------------------------------------------ */

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0 16px;
}

.field-grid .field { margin-bottom: 16px; min-width: 0; }
.field-wide { grid-column: span 2; }
.field-full { grid-column: 1 / -1; }

.field-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* The base .field rules only style text/email/password inputs. These pages
   also use date, number, search, file and select, which would otherwise fall
   back to the browser's default chrome and look nothing like the rest. */
.field input[type="date"],
.field input[type="number"],
.field input[type="search"],
.field input[type="file"],
.field select,
.filter-bar input,
.filter-bar select {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-field);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.92rem;
  font-family: inherit;
}

.field input[type="date"]:focus,
.field input[type="number"]:focus,
.field input[type="search"]:focus,
.field select:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field input[readonly] {
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-weight: 600;
}

.form-hint {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.84rem;
  line-height: 1.5;
}

.filter-bar {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.filter-bar .field { margin-bottom: 0; flex: 1; min-width: 160px; }
.filter-bar .field-wide { flex: 2; }

.inline-link { color: var(--slate); font-weight: 600; text-decoration: none; }
.inline-link:hover { color: var(--navy); text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Detail modals                                                        */
/* ------------------------------------------------------------------ */

.modal-wide { width: min(880px, 100%); max-height: 88vh; }
.modal-body { display: flex; flex-direction: column; gap: 4px; }

.detail-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.detail-amount { font-size: 1.5rem; font-weight: 700; color: var(--navy); }

.detail-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 20px;
  margin: 0 0 8px;
  font-size: 0.9rem;
}
.detail-grid dt { color: var(--text-secondary); font-weight: 600; }
.detail-grid dd { margin: 0; color: var(--text-primary); }

.detail-section {
  border-top: 1px solid var(--border-subtle);
  padding-top: 18px;
  margin-top: 18px;
}
.detail-section h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--navy);
}

.detail-note {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.5;
}

/* Spend tiles on the project page */

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }

.stat-tile {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--bg);
}
.stat-label { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); }
.stat-value { font-size: 1.2rem; font-weight: 700; color: var(--navy); }
.stat-note { font-size: 0.76rem; color: var(--text-muted); }

/* ------------------------------------------------------------------ */
/* Attachments                                                          */
/* ------------------------------------------------------------------ */

.attachment-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg);
}

.attachment-icon { font-size: 1.1rem; }
.attachment-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.attachment-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.attachment-meta { font-size: 0.76rem; color: var(--text-muted); }

.upload-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 14px;
  border: 1px dashed var(--border-subtle);
  border-radius: 12px;
  background: var(--bg);
}
.upload-row .field { margin-bottom: 0; flex: 1; min-width: 150px; }
.upload-row .field-wide { flex: 2; }

/* ------------------------------------------------------------------ */
/* Routing                                                              */
/* ------------------------------------------------------------------ */

.participant-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.participant-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg);
}

.participant-who { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.participant-name { font-size: 0.9rem; font-weight: 600; overflow-wrap: anywhere; }

.participant-state { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.participant-decision { font-size: 0.84rem; font-weight: 600; color: var(--text-muted); }
.participant-decision.is-done { color: var(--navy); }
.participant-seen { font-size: 0.76rem; color: var(--text-muted); }
.participant-comment {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-style: italic;
}

.chip {
  align-self: flex-start;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.chip-viewer { background: var(--bg-panel); color: var(--text-secondary); }
.chip-reviewer { background: var(--accent-glow); color: var(--navy); }
.chip-approver { background: var(--navy); color: #fff; }

/* ------------------------------------------------------------------ */
/* History                                                              */
/* ------------------------------------------------------------------ */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 18px;
  border-left: 2px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.timeline-item { position: relative; display: flex; flex-direction: column; gap: 2px; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -25px;
  top: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--slate-light);
}
.timeline-approved::before { background: var(--success); }
.timeline-rejected::before { background: var(--danger); }
.timeline-returned::before { background: var(--warning); }

.timeline-what { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.timeline-who { font-size: 0.76rem; color: var(--text-muted); }
.timeline-comment {
  margin-top: 4px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-panel);
  font-size: 0.83rem;
  color: var(--text-secondary);
}

/* Extra status badges */
.badge-draft { background: var(--bg-panel); color: var(--text-secondary); }
.badge-review { background: var(--accent-glow); color: var(--navy); }
.badge-returned { background: var(--warning-bg); color: var(--warning); }

@media (max-width: 720px) {
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-wide { grid-column: 1 / -1; }
  .detail-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .detail-grid dd { margin-bottom: 10px; }
  .participant-row { flex-direction: column; }
}

/* ------------------------------------------------------------------ */
/* The printable expense memo                                           */
/* ------------------------------------------------------------------ */

.memo-body {
  display: block;
  align-items: initial;
  justify-content: initial;
  background: var(--bg-panel);
  padding: 24px;
}

.memo-toolbar {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  width: min(900px, 100%);
  margin: 0 auto 16px;
}

.memo-doc {
  position: relative;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 48px 52px;
  background: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(20, 48, 61, 0.08);
  color: var(--text-primary);
}

.memo-draft-mark {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-22deg);
  font-size: 3.4rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: rgba(192, 57, 43, 0.12);
  pointer-events: none;
  white-space: nowrap;
}

.memo-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--navy);
}
.memo-logo { height: 46px; }
.memo-company { display: flex; flex-direction: column; text-align: right; gap: 2px; }
.memo-company-name { font-weight: 700; color: var(--navy); }
.memo-company-line { font-size: 0.8rem; color: var(--text-secondary); }

.memo-doc-title {
  margin: 26px 0 20px;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy);
}

.memo-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 32px;
  margin: 0 0 26px;
}
.memo-meta > div { display: flex; gap: 10px; font-size: 0.88rem; }
.memo-meta dt { min-width: 108px; color: var(--text-secondary); font-weight: 600; }
.memo-meta dd { margin: 0; font-weight: 600; }

.memo-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.memo-table th {
  text-align: left;
  padding: 9px 8px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--navy);
  color: var(--navy);
  font-weight: 700;
}
.memo-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
.memo-table th.num, .memo-table td.num { text-align: right; white-space: nowrap; }
.memo-table .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  /* A document number that wraps over three lines reads as three numbers. */
  white-space: nowrap;
  font-size: 0.72rem;
}

.memo-supplier { display: block; font-weight: 700; }
.memo-desc { display: block; }
.memo-ref { display: block; font-size: 0.74rem; color: var(--text-muted); }

.memo-totals td {
  border-top: 2px solid var(--navy);
  border-bottom: none;
  font-weight: 700;
  padding-top: 12px;
}

.memo-amount-words {
  margin: 14px 0 28px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.memo-notes h2,
.memo-breakdown h2,
.memo-approvals h2 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--navy);
}
.memo-notes { margin-bottom: 24px; }
.memo-notes p { margin: 0; font-size: 0.86rem; line-height: 1.6; }

/* Per-project split, shown only when a memo spans more than one target. */
.memo-breakdown { margin: 0 0 28px; }
.memo-breakdown-table { width: auto; min-width: min(560px, 100%); }
.memo-breakdown-table td { font-weight: 600; }

.memo-approval-note { margin: 0 0 8px; font-size: 0.78rem; color: var(--text-secondary); }
.memo-approval-list { list-style: none; margin: 0; padding: 0; font-size: 0.8rem; }
.memo-approval-list li { padding: 4px 0; border-bottom: 1px dotted var(--border-subtle); }
.memo-approval-ref {
  display: inline-block;
  min-width: 130px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
}
.memo-approval-who { color: var(--text-secondary); }

.memo-signatures {
  display: flex;
  gap: 32px;
  margin-top: 56px;
}
.memo-sign { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.memo-sign-line { display: block; border-top: 1px solid var(--navy); margin-bottom: 6px; }
.memo-sign-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 700;
}
.memo-sign-name { font-size: 0.8rem; color: var(--text-primary); overflow-wrap: anywhere; }

.memo-foot {
  margin-top: 36px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Archived projects                                                    */
/* ------------------------------------------------------------------ */

/* Dimmed rather than hidden when the filter includes them: an archived
   project is still real, it just isn't part of today's work. Kept legible —
   this is the state you read when deciding whether to restore one. */
.project-row-archived td { opacity: 0.6; }
.project-row-archived td:first-child { font-style: italic; }

/* ------------------------------------------------------------------ */
/* Accounting settings panels                                           */
/* ------------------------------------------------------------------ */

.users-table th.center, .users-table td.center { text-align: center; }

.settings-table input[type="text"],
.settings-table select {
  width: 100%;
  min-width: 120px;
  padding: 7px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-field);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
}

.settings-table input[type="text"]:focus,
.settings-table select:focus {
  outline: none;
  border-color: var(--slate);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.settings-table input:disabled,
.settings-table select:disabled {
  background: var(--bg-panel);
  color: var(--text-secondary);
  cursor: default;
}

.settings-table input[type="checkbox"] { accent-color: var(--navy); cursor: pointer; }
.settings-table input[type="checkbox"]:disabled { cursor: default; }

/* Retired, not deleted: a category or cost centre with history against it
   can't be removed (on delete restrict), so it stays visible and greyed. */
.settings-row-retired { opacity: 0.55; }

.settings-subhead {
  margin: 26px 0 4px;
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--navy);
}

.settings-subhead-note { margin-top: 0; margin-bottom: 16px; }

/* ------------------------------------------------------------------ */
/* Idle-timeout warning                                                 */
/* ------------------------------------------------------------------ */

/* Bottom-centred and non-blocking: the five minutes exist so someone can save
   what's on screen, and a modal would sit on top of the thing they need to
   reach. z-index clears the modals (200) — the warning has to be visible over
   an open transaction dialog, which is exactly where unsaved work lives. */
.idle-warning {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 14px 18px;
  background: var(--navy);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(20, 48, 61, 0.35);
}

.idle-warning-text { font-size: 0.86rem; line-height: 1.5; }

.idle-warning-btn {
  flex-shrink: 0;
  background: #fff;
  border-color: #fff;
  color: var(--navy);
  font-weight: 650;
}

.idle-warning-btn:hover { background: var(--bg-panel); border-color: var(--bg-panel); }

@media (max-width: 560px) {
  .idle-warning { flex-direction: column; align-items: stretch; text-align: center; gap: 10px; }
}

@media print { .idle-warning { display: none !important; } }

/* ------------------------------------------------------------------ */
/* Dashboard                                                            */
/* ------------------------------------------------------------------ */

/* The sign-in card is 520px because a login form should be narrow. The
   dashboard carries tables and a tile grid, and needs the room. */
.dashboard-wide { width: min(880px, 100%); }

/* Same shell as .welcome-card, but left-aligned and less padded: that card is
   a centred greeting, these hold tables and lists, which centring ruins. */
.dashboard-panel {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 24px 28px;
  text-align: left;
}

.dashboard-panel h2 {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--navy);
}

/* The panels carry their own background, so a tile needs to lift off it
   rather than blend in the way it does against a white card. */
.dashboard-panel .tile { background: var(--bg); }

.waiting-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.waiting-link {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 14px;
  align-items: baseline;
  padding: 12px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.waiting-link:hover { border-color: var(--slate-light); background: var(--bg-panel); }

.waiting-title {
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--navy);
  overflow-wrap: anywhere;
}

.waiting-detail {
  grid-column: 1;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Spans both rows in the right-hand column so the date sits beside the title
   and its detail rather than pushing either of them out of line. */
.waiting-when {
  grid-column: 2;
  grid-row: 1 / span 2;
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.card-more-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.84rem;
}

/* ------------------------------------------------------------------ */
/* Finance reports                                                      */
/* ------------------------------------------------------------------ */

.report-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 18px;
}

.report-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.report-tab:hover { color: var(--navy); background: var(--bg-panel); }
.report-tab.active { color: var(--navy); border-bottom-color: var(--navy); }

/* The buttons sit in the filter bar, which stretches its children — these
   should stay the width of their text and line up with the inputs' baseline. */
.filter-bar .field-actions-inline {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: 0 0 auto;
  min-width: 0;
}

.report-head { margin: 4px 0 16px; }
.report-head h2 { margin: 0 0 4px; font-size: 1.15rem; color: var(--navy); }
.report-head p { margin: 0; font-size: 0.84rem; color: var(--text-secondary); }

.report-subhead {
  margin: 26px 0 10px;
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--navy);
}

/* Figures are read by scanning a column, so they need to line up digit for
   digit even when the surrounding text is proportional. */
.report-table td.num, .report-table th.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* An account or project code is an identifier, not prose. Left to wrap it
   breaks as "P-2026-" / "001" across three lines and stops being scannable —
   the table scrolls horizontally instead (.table-wrap). */
.report-table td.mono, .report-table td.nowrap { white-space: nowrap; }

.report-section-row td {
  background: var(--bg-panel);
  font-weight: 700;
  color: var(--navy);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.report-total-row td {
  font-weight: 700;
  color: var(--navy);
  border-top: 1px solid var(--slate-light);
}

.report-result-row td {
  border-top: 2px solid var(--navy);
  border-bottom: 2px double var(--navy);
}

.report-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

/* The account code doubles as the drill-down control. Styled as a link rather
   than a button so a table of them doesn't read as a wall of chrome. */
.report-code-btn {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--slate);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.report-code-btn:hover { color: var(--navy); text-decoration-style: solid; }

.report-check {
  margin: 12px 0 0;
  font-size: 0.85rem;
}

.report-note {
  margin: 14px 0 0;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-secondary);
  padding: 10px 12px;
  background: var(--bg-panel);
  border-radius: 8px;
}

.report-note-warn {
  background: var(--warning-bg);
  color: var(--warning);
  font-weight: 500;
}

.report-inline-note {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 400;
}

@media print {
  /* The page IS the document — drop the app chrome and the paper effect so
     nothing but the memo reaches the printer. */
  .no-print { display: none !important; }

  .memo-body { background: #fff; padding: 0; }
  .memo-doc {
    width: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .memo-table { font-size: 0.74rem; }
  /* Keep a transaction's row off a page break where possible. */
  .memo-table tr { page-break-inside: avoid; }
  .memo-signatures { page-break-inside: avoid; }

  /* A printed report is the statement itself: strip the app frame, keep the
     title block (which carries the company and the period — without it a
     printed trial balance is a page of numbers with no provenance). */
  .dashboard-body { display: block; background: #fff; }
  .dashboard-main, .admin-main { padding: 0; display: block; }
  .admin-stack { gap: 0; }
  .admin-card {
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .report-table { font-size: 0.72rem; }
  .report-table tr { page-break-inside: avoid; }
  .report-table thead { display: table-header-group; }   /* repeat on each page */
  .report-code-btn { color: inherit; text-decoration: none; }
  .table-wrap { overflow-x: visible; }
  .report-note { background: none; padding: 0; }
  .stat-row { page-break-inside: avoid; }

  @page { size: A4 portrait; margin: 14mm; }
}
