:root {
  --bg: #f4f6f9; --card: #fff; --text: #1e293b; --muted: #64748b; --line: #e2e8f0;
  --brand: #2563eb; --brand-dark: #1d4ed8; --up: #059669; --down: #dc2626; --warn: #d97706;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.up { color: var(--up); font-weight: 600; }
.down { color: var(--down); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.topbar {
  background: #0f172a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: .55rem 1rem;
}
.topbar-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 2.4rem;
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.brand:hover { text-decoration: none; }
.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: .45rem .8rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.nav-toggle .nav-chevron {
  display: inline-block;
  font-size: .85rem;
  line-height: 1;
  transition: transform .15s ease;
}
.topbar.nav-open .nav-toggle {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.topbar.nav-open .nav-chevron { transform: rotate(180deg); }

/* Default: tabs are gone. Only the brand + Tabs button show. */
.site-nav {
  display: none;
  position: absolute;
  left: .5rem;
  right: .5rem;
  top: calc(100% + .2rem);
  margin: 0;
  max-height: min(70vh, 28rem);
  overflow: auto;
  flex-direction: column;
  align-items: stretch;
  gap: .15rem;
  padding: .45rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.topbar.nav-open .site-nav { display: flex; }

.site-nav a, .linkbtn {
  color: #cbd5e1;
  padding: .7rem .85rem;
  border-radius: 6px;
  font-size: 1rem;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.site-nav a:hover, .linkbtn:hover { background: #1e293b; color: #fff; text-decoration: none; }
.site-nav a.active { background: var(--brand); color: #fff; }
.site-nav .inline { display: block; }
.site-nav .inline .linkbtn { width: 100%; text-align: left; }

/* Always use the Tabs button — never leave the full tab row stuck open. */

.container { max-width: 1150px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.15rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .grid.cols-4 { grid-template-columns: 1fr; } .container { padding: .75rem; } }
.grid .card { margin-bottom: 0; }

.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; margin: .15rem 0; }
.kpi .sub { font-size: .85rem; color: var(--muted); }

.flash { padding: .65rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: .65rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.right, th.right { text-align: right; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
tr.subtotal td { font-weight: 600; background: #f8fafc; }
.table-wrap { overflow-x: auto; }
td.indent { padding-left: 1.6rem; }

form.stack label, .formgrid label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { width: 100%; padding: .5rem .6rem; border: 1px solid #cbd5e1; border-radius: 7px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.formgrid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.formgrid .wide { grid-column: 1 / -1; }
.formgrid .span2 { grid-column: span 2; }
form.inline { display: inline; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  background: linear-gradient(180deg, #3b82f6 0%, var(--brand) 55%, var(--brand-dark) 100%);
  color: #fff;
  border: 1px solid #1e40af;
  padding: .55rem 1.05rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  letter-spacing: .01em;
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 4px 10px rgba(37, 99, 235, .28);
  transform: translateY(0);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
}
.btn:hover {
  filter: brightness(1.05);
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(255,255,255,.3) inset, 0 6px 14px rgba(37, 99, 235, .34);
}
.btn:active {
  transform: translateY(1px) scale(.98);
  box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 0 2px 4px rgba(15, 23, 42, .25);
  filter: brightness(.97);
}
.btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}
.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: grayscale(.15);
}
.btn.secondary {
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  color: var(--text);
  border-color: #94a3b8;
  box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, 0 3px 8px rgba(15, 23, 42, .08);
}
.btn.secondary:hover {
  background: linear-gradient(180deg, #fff 0%, #cbd5e1 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.9) inset, 0 5px 12px rgba(15, 23, 42, .12);
}
.btn.danger {
  background: linear-gradient(180deg, #fecaca 0%, #f87171 55%, #dc2626 100%);
  color: #7f1d1d;
  border-color: #b91c1c;
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 4px 10px rgba(220, 38, 38, .22);
}
.btn.danger:hover {
  filter: brightness(1.04);
  color: #450a0a;
}
.btn.small { padding: .28rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn.good {
  background: linear-gradient(180deg, #6ee7b7 0%, #10b981 55%, #059669 100%);
  color: #064e3b;
  border-color: #047857;
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 4px 10px rgba(5, 150, 105, .28);
}
.btn.good:hover {
  filter: brightness(1.04);
  color: #022c22;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(127, 29, 29, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.confirm-modal[hidden] { display: none !important; }
.confirm-modal-card {
  width: min(400px, 100%);
  background: #fff5f5;
  border: 3px solid #dc2626;
  border-radius: 16px;
  padding: 1.15rem 1.1rem 1.25rem;
  text-align: center;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .2), 0 16px 40px rgba(127, 29, 29, .35);
  animation: confirm-pop .22s ease-out;
}
.confirm-modal-banner {
  margin: 0 0 .55rem;
  padding: .55rem .7rem;
  border-radius: 10px;
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.confirm-modal-msg {
  margin: 0 0 1rem;
  color: #7f1d1d;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.35;
}
.confirm-modal-actions {
  display: grid;
  gap: .55rem;
}
@keyframes confirm-pop {
  from { transform: scale(.94); opacity: .5; }
  to { transform: scale(1); opacity: 1; }
}
.pw-field { position: relative; display: block; }
.pw-field input { width: 100%; padding-right: 2.4rem; }
.pw-toggle { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: .25rem; line-height: 0; border-radius: 4px; }
.pw-toggle:hover { color: var(--text); background: #e2e8f0; }
.pw-toggle[aria-pressed="true"] { color: var(--brand); }
.pw-toggle .eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .eye-on { display: none; }
.pw-toggle[aria-pressed="true"] .eye-off { display: block; }
.actions { display: flex; gap: .35rem; justify-content: flex-end; flex-wrap: wrap; }

.tabs { display: flex; gap: .35rem; flex-wrap: wrap; }
.tabs a {
  padding: .35rem .85rem;
  border-radius: 99px;
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  color: var(--text);
  font-size: .88rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 2px 6px rgba(15, 23, 42, .06);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.tabs a.active {
  background: linear-gradient(180deg, #3b82f6 0%, var(--brand) 100%);
  color: #fff;
  border-color: #1e40af;
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 3px 8px rgba(37, 99, 235, .3);
}
.tabs a:hover { text-decoration: none; filter: brightness(1.03); }
.tabs a:active { transform: scale(.97); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #e2e8f0; color: #334155; }
.badge.high { background: #fee2e2; color: #991b1b; }
.badge.low { background: #e0f2fe; color: #075985; }
.badge.overdue { background: #fee2e2; color: #991b1b; }
.badge.today { background: #fef3c7; color: #92400e; }
.badge.cogs { background: #fef3c7; color: #92400e; }
.badge.income { background: #d1fae5; color: #065f46; }
.badge.other_out { background: #ede9fe; color: #5b21b6; }

.chartbox { position: relative; height: 280px; }
.chartbox.tall { height: 340px; }
.chartbox.short { height: 220px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: .75rem; align-items: center; }
.list li:last-child { border-bottom: 0; }
.done-title { text-decoration: line-through; color: var(--muted); }

.cal { table-layout: fixed; }
.cal th { text-align: center; }
.cal td { height: 104px; vertical-align: top; border: 1px solid var(--line); padding: .25rem; background: #fff; }
.cal td.other { background: #f8fafc; color: #94a3b8; }
.cal td.today { background: #eff6ff; outline: 2px solid var(--brand); outline-offset: -2px; }
.cal td.selected { background: #fefce8; }
.cal .daynum { font-weight: 600; font-size: .85rem; display: block; color: inherit; }
.chip { display: block; font-size: .72rem; padding: 1px 5px; margin-top: 2px; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { text-decoration: none; filter: brightness(.95); }
.chip.event { background: #dbeafe; color: #1e40af; }
.chip.task { background: #fef3c7; color: #92400e; }
.chip.bill { background: #fee2e2; color: #991b1b; }
@media (max-width: 700px) { .cal td { height: 70px; } .chip { font-size: .62rem; } }

.badge.p1 { background: #fee2e2; color: #991b1b; }
.badge.p2 { background: #fef3c7; color: #92400e; }
.badge.p3 { background: #dbeafe; color: #1e40af; }
.badge.p4 { background: #e2e8f0; color: #475569; }
.badge.acct { background: #ede9fe; color: #5b21b6; }
.kpi.p1box { border-top: 4px solid #ef4444; }
.kpi.p2box { border-top: 4px solid #f59e0b; }
.kpi.p3box { border-top: 4px solid #3b82f6; }
.kpi.p4box { border-top: 4px solid #94a3b8; }
.maillist { list-style: none; margin: 0; padding: 0; }
.mailrow { display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.mailrow:last-child { border-bottom: 0; }
.mailrow.handled { opacity: .55; }
.mailmain { min-width: 0; flex: 1; }
.mailtop { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; font-size: .88rem; }
.mailsubject { font-weight: 600; margin-top: .15rem; overflow-wrap: anywhere; }
.mailsnippet { font-size: .85rem; overflow-wrap: anywhere; }
.mailactions { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; max-width: 270px; }
.mailtriage { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .45rem; }
.mailtriage .notenput { flex: 1 1 180px; min-width: 140px; margin: 0; padding: .35rem .55rem; font-size: .9rem; }
.mailtriage select { width: auto; min-width: 140px; margin: 0; padding: .35rem .45rem; font-size: .9rem; }
.mailnote { margin-top: .35rem; font-size: .88rem; color: var(--muted); font-style: italic; }
.badge.company { background: #e2e8f0; color: #0f172a; }
.folders { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .6rem; }
.folder { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--text); background: var(--card, #fff); font-size: .9rem; }
.folder:hover { border-color: var(--accent, #2563eb); }
.folder.active { background: var(--accent, #2563eb); color: #fff; border-color: transparent; }
.folder.active .badge { background: rgba(255,255,255,.25); color: #fff; }
details.why summary { cursor: pointer; font-size: .78rem; color: var(--muted); margin-top: .2rem; }
details.why p { margin: .3rem 0; font-size: .82rem; }
.prioform { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.prioform select { width: auto; padding: .2rem .4rem; }
label.check { display: inline-flex; gap: .3rem; align-items: center; font-size: .82rem; font-weight: 400; color: var(--text); margin: 0; }
label.check input { width: auto; }
@media (max-width: 700px) { .mailrow { flex-direction: column; } .mailactions { justify-content: flex-start; max-width: none; } }
.mt { margin-top: 1rem; }
.fullw { width: 100%; }
.login-box { max-width: 380px; margin: 12vh auto 0; }
.login-box h1 { text-align: center; }
