/*
 * ERP · interface built on the Demairan design system (v1).
 * Tokens: color (midnight, mimosa, mimosa-text, dawn, surface, mist, ink, ink-muted, line, on-mimosa),
 * type (Manrope; titles 500, text 400), spacing 4/8/12/16/24/32/48, radius 4/8/16.
 * Extensions kept in the same spirit: --danger (errors and refusals) and --chart-cost.
 * Suggested balance: ~60% neutrals, 25% midnight, 12% mimosa, 3% dawn.
 */

:root {
  --midnight: #0F1B2D;
  --mimosa: #22C39A;
  --mimosa-text: #0B7A5E;
  --dawn: #F5A524;
  --surface: #FFFFFF;
  --mist: #F3F5F8;
  --ink: #0F1B2D;
  --ink-muted: #5A6576;
  --line: #DDE2E8;
  --on-mimosa: #0F1B2D;

  --danger: #B3362F;
  --danger-tint: rgba(179, 54, 47, .10);
  --mimosa-tint: rgba(34, 195, 154, .14);
  --dawn-tint: rgba(245, 165, 36, .18);
  --dawn-text: #8A5A00;
  --info-tint: rgba(15, 27, 45, .07);
  --chart-cost: #0F1B2D;
  --sidebar-bg: #0F1B2D;
  --sidebar-ink: #F3F5F8;
  --sidebar-muted: #A7B1BF;
  --sidebar-hover: rgba(243, 245, 248, .07);
  --focus: 0 0 0 3px rgba(34, 195, 154, .35);
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px rgba(15, 27, 45, .06);

  --font-sans: "Manrope", "Helvetica Neue", Arial, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;

  --sidebar-w: 256px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --midnight: #22385A;
    --mimosa-text: #4FD8B3;
    --surface: #0F1B2D;
    --mist: #172840;
    --ink: #F3F5F8;
    --ink-muted: #A7B1BF;
    --line: #24364F;
    --danger: #F28B82;
    --danger-tint: rgba(242, 139, 130, .14);
    --mimosa-tint: rgba(34, 195, 154, .16);
    --dawn-tint: rgba(245, 165, 36, .16);
    --dawn-text: #F5C46B;
    --info-tint: rgba(243, 245, 248, .08);
    --chart-cost: #A7B1BF;
    --sidebar-bg: #0B1422;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --midnight: #22385A;
  --mimosa-text: #4FD8B3;
  --surface: #0F1B2D;
  --mist: #172840;
  --ink: #F3F5F8;
  --ink-muted: #A7B1BF;
  --line: #24364F;
  --danger: #F28B82;
  --danger-tint: rgba(242, 139, 130, .14);
  --mimosa-tint: rgba(34, 195, 154, .16);
  --dawn-tint: rgba(245, 165, 36, .16);
  --dawn-text: #F5C46B;
  --info-tint: rgba(243, 245, 248, .08);
  --chart-cost: #A7B1BF;
  --sidebar-bg: #0B1422;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 500; letter-spacing: -.005em; }
h1 { font-size: 36px; line-height: 44px; }
h2 { font-size: 24px; line-height: 32px; }
h3 { font-size: 18px; line-height: 26px; }
p { margin: 0 0 var(--space-3); }
small, .small { font-size: 14px; line-height: 20px; }
.caption { font-size: 12px; line-height: 16px; font-weight: 500; }
.muted { color: var(--ink-muted); }
.danger-text { color: var(--danger); }
.success-text { color: var(--mimosa-text); }
.warning-text { color: var(--dawn-text); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

a { color: var(--mimosa-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

/* ---------- App shell ---------- */

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  padding: var(--space-6) var(--space-4);
}

.brand { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2) var(--space-6); color: var(--sidebar-ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; }
.brand-name { font-size: 18px; line-height: 26px; font-weight: 500; letter-spacing: .32em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: var(--space-4); flex: 1; }
.nav-group-title {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-2) var(--space-1);
  color: var(--sidebar-muted); font-size: 12px; line-height: 16px; font-weight: 500;
}
.nav-group-title .icon { width: 16px; height: 16px; }
.nav-link {
  position: relative; display: block;
  padding: var(--space-2) var(--space-3) var(--space-2) 32px;
  border-radius: var(--radius-md);
  color: var(--sidebar-ink); font-size: 14px; line-height: 20px;
}
.nav-link:hover { background: var(--sidebar-hover); text-decoration: none; }
.nav-link.active { background: var(--sidebar-hover); font-weight: 500; }
.nav-link.active::before {
  content: ""; position: absolute; left: 14px; top: 50%;
  width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--mimosa);
}

.sidebar-footer { border-top: 1px solid rgba(243, 245, 248, .1); margin-top: var(--space-6); padding-top: var(--space-4); }
.user-chip { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--mimosa); color: var(--on-mimosa);
  font-size: 12px; line-height: 16px; font-weight: 500;
}
.avatar-muted { background: var(--mist); color: var(--ink); border: 1px solid var(--line); }
.user-chip-text { min-width: 0; flex: 1; }
.user-chip-name { font-size: 14px; line-height: 20px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-role { font-size: 12px; line-height: 16px; color: var(--sidebar-muted); }
.sidebar-actions { display: flex; gap: var(--space-1); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: var(--sidebar-hover); }

.main { min-width: 0; display: flex; flex-direction: column; }
/* Mobile drawer backdrop. Fixed and hidden by default so it never takes a grid cell. */
.scrim { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(15, 27, 45, .45); }

.topbar {
  display: none; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
  padding: var(--space-3) var(--space-4);
  background: var(--sidebar-bg); color: var(--sidebar-ink);
}

.content { padding: var(--space-8); max-width: 1440px; width: 100%; }

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
  gap: var(--space-4); margin-bottom: var(--space-6);
}
.page-header p { margin: var(--space-1) 0 0; color: var(--ink-muted); font-size: 14px; line-height: 20px; max-width: 720px; }
.page-header .eyebrow { display: block; margin-bottom: var(--space-1); color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 500; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }

.backlink { display: inline-flex; align-items: center; gap: var(--space-1); font-size: 14px; line-height: 20px; margin-bottom: var(--space-2); }

/* ---------- Cards and layout ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-6);
}
.card + .card { margin-top: var(--space-6); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.card-header h3 { font-size: 18px; line-height: 26px; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-header { padding: var(--space-4) var(--space-6) 0; }
.card-tint { background: var(--mist); }

.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }

/* KPI tiles */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-4) var(--space-6); }
.kpi-label { color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 500; }
.kpi-value { margin-top: var(--space-1); font-size: 24px; line-height: 32px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-note { margin-top: var(--space-1); color: var(--ink-muted); font-size: 12px; line-height: 16px; }
.kpi-accent { background: var(--midnight); border-color: var(--midnight); color: #F3F5F8; }
.kpi-accent .kpi-label, .kpi-accent .kpi-note { color: #A7B1BF; }

/* Description list */
.dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--space-2) var(--space-6); margin: 0; font-size: 14px; line-height: 20px; }
.dl dt { color: var(--ink-muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: var(--space-2) var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  font: inherit; font-size: 14px; line-height: 20px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--mimosa); color: var(--on-mimosa); }
.btn-primary:hover { background: #1DB08B; }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { background: var(--mist); }
.btn-dark { background: var(--midnight); color: #F3F5F8; }
.btn-dark:hover { filter: brightness(1.15); }
.btn-ghost { background: transparent; color: var(--mimosa-text); padding-left: var(--space-2); padding-right: var(--space-2); }
.btn-ghost:hover { background: var(--mimosa-tint); }
.btn-danger { background: transparent; border-color: var(--line); color: var(--danger); }
.btn-danger:hover { background: var(--danger-tint); border-color: var(--danger); }
.btn-sm { min-height: 32px; padding: var(--space-1) var(--space-3); font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-6); }
.form-grid .span-full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label, .label { font-size: 14px; line-height: 20px; font-weight: 500; }
.field .req { color: var(--danger); margin-left: 2px; }
.help { color: var(--ink-muted); font-size: 12px; line-height: 16px; }
.error { color: var(--danger); font-size: 12px; line-height: 16px; font-weight: 500; }

.input, .select, .textarea {
  width: 100%; min-height: 40px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-md);
  font: inherit; font-size: 14px; line-height: 20px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-muted); opacity: .8; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--mimosa); box-shadow: var(--focus); }
.textarea { min-height: 96px; resize: vertical; }
.select {
  appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%), linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--danger); }
.input-sm { min-height: 32px; padding: var(--space-1) var(--space-2); }

.check { display: flex; align-items: flex-start; gap: var(--space-2); font-size: 14px; line-height: 20px; cursor: pointer; padding-top: var(--space-6); }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--mimosa); flex: none; }
.check-inline { padding-top: 0; }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: flex-end; margin-top: var(--space-6); padding-top: var(--space-6); border-top: 1px solid var(--line); }
.form-actions .left { margin-right: auto; }

.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); }
.filters .input, .filters .select { width: auto; min-width: 160px; }
.filters .search { flex: 1 1 240px; position: relative; }
.filters .search .input { width: 100%; padding-left: 36px; }
.filters .search .icon { position: absolute; left: 10px; top: 10px; color: var(--ink-muted); }

/* ---------- Tables ---------- */

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.table th {
  text-align: left; white-space: nowrap;
  padding: var(--space-3) var(--space-4);
  color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 500;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--mist) 60%, transparent); }
.table .right { text-align: right; }
.table tfoot td { font-weight: 500; border-top: 1px solid var(--line); border-bottom: 0; }
.table-link { color: var(--ink); font-weight: 500; }
.table-link:hover { color: var(--mimosa-text); }
.cell-sub { display: block; color: var(--ink-muted); font-size: 12px; line-height: 16px; }
.card-flush .table th:first-child, .card-flush .table td:first-child { padding-left: var(--space-6); }
.card-flush .table th:last-child, .card-flush .table td:last-child { padding-right: var(--space-6); }

.empty { padding: var(--space-8) var(--space-6); text-align: center; color: var(--ink-muted); font-size: 14px; line-height: 20px; }
.empty strong { display: block; color: var(--ink); font-size: 16px; line-height: 24px; font-weight: 500; margin-bottom: var(--space-1); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-6); border-top: 1px solid var(--line); font-size: 14px; line-height: 20px; color: var(--ink-muted); }
.pagination .row { gap: var(--space-2); }

/* ---------- Badges, alerts ---------- */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2); border-radius: var(--radius-sm);
  font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-success { background: var(--mimosa-tint); color: var(--mimosa-text); }
.badge-warning { background: var(--dawn-tint); color: var(--dawn-text); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-info { background: var(--info-tint); color: var(--ink); }
.badge-neutral { background: var(--mist); color: var(--ink-muted); border-color: var(--line); }
.badge-muted { background: transparent; color: var(--ink-muted); border-color: var(--line); border-style: dashed; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-dawn { background: var(--dawn); }
.dot-mimosa { background: var(--mimosa); }

.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-6);
  border-radius: var(--radius-md); border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; line-height: 20px;
}
.alert .icon { margin-top: 0; }
.alert-success { border-color: color-mix(in srgb, var(--mimosa) 45%, var(--line)); }
.alert-success .icon { color: var(--mimosa-text); }
.alert-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: var(--danger-tint); }
.alert-danger .icon { color: var(--danger); }
.alert-warning { border-color: color-mix(in srgb, var(--dawn) 50%, var(--line)); }
.alert-warning .icon { color: var(--dawn); }
.alert-list { margin: var(--space-1) 0 0; padding-left: 18px; }
.brand-compact { padding: 0; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: var(--space-4); }
.w-full { width: 100%; }
.alert-close { margin-left: auto; border: 0; background: none; color: var(--ink-muted); cursor: pointer; padding: 0; line-height: 0; }

/* ---------- Lists ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 20px; }
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list li:first-child { padding-top: 0; }
.list-main { min-width: 0; }
.list-title { font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 var(--space-6) var(--space-6); border-left: 1px solid var(--line); margin-left: 6px; }
.timeline li:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 2px solid var(--mimosa); }
.timeline-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: 14px; line-height: 20px; }
.timeline-body { margin-top: var(--space-1); color: var(--ink-muted); font-size: 14px; line-height: 20px; white-space: pre-line; }

/* ---------- Charts (inline SVG) ---------- */

.chart { width: 100%; height: auto; display: block; }
.chart .bar-revenue { fill: var(--mimosa); }
.chart .bar-cost { fill: var(--chart-cost); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.chart text { fill: var(--ink-muted); font-family: var(--font-sans); font-size: 12px; }
.legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.legend span { display: inline-flex; align-items: center; gap: var(--space-2); }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch-revenue { background: var(--mimosa); }
.swatch-cost { background: var(--chart-cost); }

.meter { display: block; width: 100%; height: 8px; }
.meter .track { fill: var(--mist); }
.meter .fill { fill: var(--mimosa); }
.meter .fill-warning { fill: var(--dawn); }
.meter .fill-danger { fill: var(--danger); }
.meter .fill-ink { fill: var(--chart-cost); }

/* ---------- Pipeline board ---------- */

.board { display: grid; grid-template-columns: repeat(6, minmax(190px, 1fr)); gap: var(--space-4); overflow-x: auto; padding-bottom: var(--space-2); }
.board-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); min-height: 200px; }
.board-col-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); padding: var(--space-1) var(--space-1) var(--space-3); }
.board-col-head h3 { font-size: 14px; line-height: 20px; }
.board-card { background: var(--mist); border-radius: var(--radius-md); padding: var(--space-3); margin-bottom: var(--space-2); font-size: 14px; line-height: 20px; }
.board-card form { margin-top: var(--space-2); }
.board-card .select { min-height: 32px; padding-top: 4px; padding-bottom: 4px; font-size: 12px; }

/* ---------- Calendar ---------- */

.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { padding: var(--space-2); color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 500; text-align: left; border-bottom: 1px solid var(--line); }
.cal td { height: 116px; vertical-align: top; padding: var(--space-1); border: 1px solid var(--line); }
.cal tr td:first-child { border-left: 0; }
.cal tr td:last-child { border-right: 0; }
.cal tbody tr:last-child td { border-bottom: 0; }
.cal .out { background: var(--mist); }
.cal .out .cal-day { color: var(--ink-muted); }
.cal-day { display: flex; justify-content: space-between; align-items: center; padding: 2px var(--space-1); font-size: 12px; line-height: 16px; font-weight: 500; }
.cal-day a { color: var(--ink-muted); opacity: 0; }
.cal td:hover .cal-day a { opacity: 1; }
.cal .today .cal-day-num { background: var(--mimosa); color: var(--on-mimosa); border-radius: 999px; padding: 0 6px; }
.cal-event {
  display: block; margin-top: 2px; padding: 2px 6px;
  border-radius: var(--radius-sm); font-size: 12px; line-height: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink); background: var(--info-tint);
}
.cal-event:hover { text-decoration: none; filter: brightness(.97); }
.ev-meeting { background: var(--info-tint); }
.ev-delivery, .ev-milestone { background: var(--mimosa-tint); color: var(--mimosa-text); }
.ev-deploy { background: var(--dawn-tint); color: var(--dawn-text); }
.ev-absence { background: transparent; border: 1px dashed var(--line); color: var(--ink-muted); }
.ev-due { background: var(--danger-tint); color: var(--danger); }
.ev-other { background: var(--mist); }
.cal-more { font-size: 12px; color: var(--ink-muted); padding: 0 6px; }

/* Team availability grid */
.avail { border-collapse: separate; border-spacing: 2px; font-size: 12px; line-height: 16px; }
.avail th, .avail td { text-align: center; padding: 0; }
.avail th.person, .avail td.person { text-align: left; padding-right: var(--space-4); white-space: nowrap; font-size: 14px; line-height: 20px; }
.avail .day-head { width: 32px; color: var(--ink-muted); font-weight: 500; padding-bottom: var(--space-1); }
.avail .day-head.weekend { opacity: .55; }
.avail .day-head.today { color: var(--mimosa-text); }
.avail .cell { width: 32px; height: 28px; border-radius: var(--radius-sm); background: var(--mist); }
.avail .cell.weekend { background: transparent; border: 1px dashed var(--line); }
.avail .cell.approved { background: var(--chart-cost); } /* midnight in light theme, graphite in dark for contrast */
.avail .cell.pending { background: var(--dawn-tint); border: 1px solid var(--dawn); }
.swatch[data-legend="approved"] { background: var(--chart-cost); }
.swatch[data-legend="pending"] { background: var(--dawn-tint); border: 1px solid var(--dawn); }
.swatch[data-legend="free"] { background: var(--mist); border: 1px solid var(--line); }
.row-end { justify-content: flex-end; flex-wrap: nowrap; }

/* Line-item editor */
.items-table input, .items-table select { min-width: 0; }
.items-table td { padding: var(--space-2); vertical-align: top; }
.items-table .col-product { width: 220px; }
.items-table .col-kind { width: 170px; }
.items-table .col-qty { width: 96px; }
.items-table .col-price { width: 140px; }
.items-table .col-total { width: 130px; padding-top: 18px; }
.items-table .col-remove { width: 44px; }
.totals { margin-left: auto; width: 100%; max-width: 360px; font-size: 14px; line-height: 20px; }
.totals div { display: flex; justify-content: space-between; padding: var(--space-1) 0; }
.totals .grand { font-size: 18px; line-height: 26px; font-weight: 500; border-top: 1px solid var(--line); margin-top: var(--space-2); padding-top: var(--space-2); }

/* Module toggles */
.module-row { display: flex; gap: var(--space-4); align-items: flex-start; padding: var(--space-4) 0; border-bottom: 1px solid var(--line); }
.module-row:last-child { border-bottom: 0; }
.module-icon { width: 40px; height: 40px; border-radius: var(--radius-md); display: grid; place-items: center; background: var(--mist); color: var(--ink); flex: none; }
.module-row.on .module-icon { background: var(--midnight); color: var(--mimosa); }
.module-body { flex: 1; min-width: 0; }
.module-body p { margin: var(--space-1) 0 0; color: var(--ink-muted); font-size: 14px; line-height: 20px; }

/* ---------- Guest (login) ---------- */

.guest { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: var(--surface); }
.guest-art { position: relative; background: var(--midnight); overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; padding: var(--space-12); color: #F3F5F8; }
.guest-art svg.art { position: absolute; top: 0; right: 0; width: 100%; height: 100%; }
.guest-art .tagline { position: relative; max-width: 420px; }
.guest-art .tagline h1 { font-size: 56px; line-height: 60px; }
.guest-art .tagline p { margin-top: var(--space-3); color: #A7B1BF; font-size: 16px; }
.guest-panel { display: flex; align-items: center; justify-content: center; padding: var(--space-8); }
.guest-box { width: 100%; max-width: 380px; }
.guest-box .brand { color: var(--ink); padding: 0 0 var(--space-8); }
.guest-box h2 { margin-bottom: var(--space-1); }
.guest-box .stack-sm > * + * { margin-top: var(--space-4); }

/* OAuth consent (MCP connection) */
.consent-user { margin: var(--space-6) 0 0; padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); }
.consent-user .user-chip-name, .consent-user .user-chip-role { display: block; }
.consent-user .user-chip-role { color: var(--ink-muted); }
.consent-list { list-style: none; margin: var(--space-6) 0; padding: 0; display: grid; gap: var(--space-4); font-size: 14px; line-height: 20px; }
.consent-list li { display: flex; gap: var(--space-3); align-items: flex-start; }
.consent-list .icon { width: 20px; height: 20px; flex: none; }
.consent-ok { color: var(--mimosa-text); }
.consent-no { color: var(--danger); }
.consent-info { color: var(--ink-muted); }
.consent-actions { display: grid; gap: var(--space-3); }
.steps { margin: 0; padding-left: var(--space-6); display: grid; gap: var(--space-4); font-size: 14px; line-height: 20px; }
.steps li::marker { color: var(--mimosa-text); font-weight: 500; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.token-url { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; padding: var(--space-2) var(--space-3); background: var(--mist); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow-wrap: anywhere; }

.error-page { max-width: 560px; margin: var(--space-12) auto; text-align: center; }
.error-page .code { font-size: 56px; line-height: 60px; font-weight: 500; color: var(--mimosa-text); }

/* ---------- Responsive ---------- */

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.nav-open .scrim { display: block; }
  .content { padding: var(--space-6) var(--space-4); }
  .grid-main, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .guest { grid-template-columns: minmax(0, 1fr); }
  .guest-art { display: none; }
}

@media (max-width: 640px) {
  h1 { font-size: 28px; line-height: 36px; }
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .card { padding: var(--space-4); }
  .card-flush { padding: 0; }
  .card-flush .card-header { padding: var(--space-4) var(--space-4) 0; }
  .card-flush .table th:first-child, .card-flush .table td:first-child { padding-left: var(--space-4); }
  .card-flush .table th:last-child, .card-flush .table td:last-child { padding-right: var(--space-4); }
  .page-header { align-items: flex-start; }
  .page-actions, .page-actions .btn { width: 100%; }
  .filters .input, .filters .select { flex: 1 1 100%; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 0 0; }
  .dl dd { margin-bottom: var(--space-3); }
  .check { padding-top: 0; }
  .cal td { height: 72px; }
  .cal-event { font-size: 0; height: 6px; padding: 0; }
  .items-table thead { display: none; }
  .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100% !important; }
  .items-table tr { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-2); margin-bottom: var(--space-3); }
  .items-table td { border: 0; padding: var(--space-1); }
  .items-table .col-total { padding-top: var(--space-1); text-align: left; }
  .form-actions .btn { flex: 1 1 auto; }
}

@media print {
  .sidebar, .topbar, .page-actions, .no-print, .alert, form { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
  .content { padding: 0; }
}
