/* =====================================================================
   Business Ledger - design system
   Colour tokens mirror the Ailooy Business Ledger palette.
   Every colour is defined once here; change a token and the whole
   application follows.
   ===================================================================== */

:root {
  /* Surfaces */
  --bg:            #f5f7f9;
  --card:          #ffffff;
  --popover:       #ffffff;

  /* Text */
  --fg:            #112a43;
  --muted:         #edf0f4;
  --muted-fg:      #677383;
  --secondary:     #e9edf2;
  --secondary-fg:  #344d66;

  /* Brand */
  --primary:       #112a43;
  --primary-fg:    #fbfcfd;
  --accent:        #00787d;
  --accent-fg:     #ffffff;
  --accent-soft:   #e2f1f2;

  /* Status */
  --success:       #0a7e3a;
  --success-soft:  #e3f3e9;
  --warning:       #d27908;
  --warning-soft:  #fbefdd;
  --danger:        #db2c2b;
  --danger-soft:   #fbe6e5;
  --info:          #00787d;
  --info-soft:     #e2f1f2;

  /* Lines */
  --border:        #dbe1e7;
  --input-border:  #dbe1e7;
  --ring:          #00787d;

  /* Sidebar */
  --sidebar:        #112a43;
  --sidebar-fg:     #e2e9f0;
  --sidebar-muted:  #93a4b8;
  --sidebar-accent: #263c54;
  --sidebar-border: #2b3f54;
  --sidebar-active: #00787d;

  /* Charts */
  --chart-1: #112a43;
  --chart-2: #00787d;
  --chart-3: #344d66;
  --chart-4: #d27908;
  --chart-5: #0a7e3a;
  --chart-6: #7c5cbf;

  /* Shape */
  --radius:    0.7rem;
  --radius-sm: 0.45rem;
  --radius-lg: 0.9rem;

  --shadow-sm: 0 1px 2px rgba(17, 42, 67, 0.05);
  --shadow:    0 1px 3px rgba(17, 42, 67, 0.07), 0 1px 2px rgba(17, 42, 67, 0.04);
  --shadow-lg: 0 10px 30px rgba(17, 42, 67, 0.12);

  --sidebar-w:          272px;
  --sidebar-w-collapsed: 74px;
  --topbar-h:           68px;

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg:            #091521;
  --card:          #12202f;
  --popover:       #12202f;
  --fg:            #ebeff2;
  --muted:         #1e2d3c;
  --muted-fg:      #9ba6b2;
  --secondary:     #1e2f41;
  --secondary-fg:  #ebeff2;
  --primary:       #e6ebf0;
  --primary-fg:    #12202f;
  --accent:        #1c989e;
  --accent-fg:     #06141d;
  --accent-soft:   #16333c;
  --success:       #43a65f;
  --success-soft:  #16301f;
  --warning:       #ec9845;
  --warning-soft:  #33240f;
  --danger:        #ec544b;
  --danger-soft:   #341715;
  --info:          #1c989e;
  --info-soft:     #16333c;
  --border:        rgba(255, 255, 255, 0.12);
  --input-border:  rgba(255, 255, 255, 0.16);
  --ring:          #1c989e;
  --sidebar:        #0f1c29;
  --sidebar-fg:     #e2e9f0;
  --sidebar-muted:  #8b99a8;
  --sidebar-accent: #1e2f41;
  --sidebar-border: rgba(255, 255, 255, 0.10);
  --chart-1: #98a8ba;
  --chart-2: #3aa9af;
  --chart-3: #6d8296;
  --chart-4: #ec9845;
  --chart-5: #43a65f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:    0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.55);
}

/* --- Reset ---------------------------------------------------------- */

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
p  { margin: 0 0 0.75rem; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --- Layout shell --------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: width 0.18s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.05rem 1.15rem;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: var(--topbar-h);
}

.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }

.brand-text { min-width: 0; }
.brand-name {
  font-size: 13.5px; font-weight: 650; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub {
  font-size: 11.5px; color: var(--sidebar-muted); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 0.6rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-accent) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-accent); border-radius: 3px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-fg);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 0;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--sidebar-accent); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ico { flex: 0 0 18px; width: 18px; height: 18px; opacity: 0.9; }
.nav-item .chev { margin-left: auto; width: 14px; height: 14px; opacity: 0.6; transition: transform 0.15s; }
.nav-group.open > .nav-item .chev { transform: rotate(180deg); }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-sub { display: none; margin: 0.15rem 0 0.35rem 0; padding-left: 1.55rem; }
.nav-group.open .nav-sub { display: block; }
.nav-sub .nav-item { font-size: 13px; font-weight: 450; padding: 0.4rem 0.65rem; }
.nav-sub .nav-item .ico { flex-basis: 15px; width: 15px; height: 15px; opacity: 0.75; }

.sidebar-foot {
  border-top: 1px solid var(--sidebar-border);
  padding: 0.6rem;
}

/* Collapsed sidebar */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .main    { margin-left: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .chev,
body.sidebar-collapsed .sidebar-foot .nav-label { display: none; }
body.sidebar-collapsed .nav-sub { display: none !important; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 0.55rem; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin 0.18s ease;
}

/* --- Topbar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.35rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.company-switcher { position: relative; }
.company-switcher > button {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.42rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  max-width: 260px;
}
.company-switcher > button:hover { background: var(--muted); }
.company-switcher .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-search {
  position: relative;
  flex: 1;
  max-width: 420px;
}
.topbar-search input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.15rem;
  border-radius: 999px;
  border: 1px solid var(--input-border);
  background: var(--bg);
  font-size: 13.5px;
}
.topbar-search input:focus { outline: none; border-color: var(--accent); background: var(--card); }
.topbar-search .ico {
  position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--muted-fg); pointer-events: none;
}

.topbar-spacer { flex: 1; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 0; background: none;
  color: var(--muted-fg);
  cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--muted); color: var(--fg); }
.icon-btn .count {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}

.user-chip {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.3rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 0; background: none; cursor: pointer;
  text-align: left;
}
.user-chip:hover { background: var(--muted); }
.user-chip .meta { line-height: 1.25; }
.user-chip .nm  { font-size: 13px; font-weight: 600; }
.user-chip .rl  { font-size: 11.5px; color: var(--muted-fg); }

.avatar {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 50%;
  background: var(--primary); color: var(--primary-fg);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650;
}
.avatar.sm { width: 28px; height: 28px; flex-basis: 28px; font-size: 11px; }
.avatar.accent { background: var(--accent); color: #fff; }

/* Dropdown menus */
.menu { position: relative; }
.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--popover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  display: none;
  z-index: 60;
}
.menu-panel.left { right: auto; left: 0; }
.menu.open .menu-panel { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 0; background: none;
  font-size: 13.5px; color: var(--fg);
  cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--muted); text-decoration: none; }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 0.35rem 0; }
.menu-head {
  padding: 0.4rem 0.6rem 0.3rem;
  font-size: 11px; font-weight: 650; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted-fg);
}

/* --- Page container ------------------------------------------------- */

.page { padding: 1.35rem 1.6rem 2.5rem; max-width: 1560px; width: 100%; }

.breadcrumbs {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 12.5px; color: var(--muted-fg);
  margin-bottom: 0.75rem;
}
.breadcrumbs a { color: var(--muted-fg); }
.breadcrumbs a:hover { color: var(--fg); }
.breadcrumbs .sep { opacity: 0.5; }

.page-head {
  display: flex; align-items: flex-start; gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 25px; line-height: 1.2; }
.page-head .sub { color: var(--muted-fg); font-size: 13.5px; margin-top: 0.25rem; }
.page-head .actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.52rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--card);
  color: var(--fg);
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .ico { width: 16px; height: 16px; }

.btn-primary  { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover  { background: #1c3a58; }
[data-theme="dark"] .btn-primary:hover { background: #cfd8e1; }

.btn-accent   { background: var(--accent); color: var(--accent-fg); }
.btn-accent:hover { filter: brightness(1.1); }

.btn-outline  { background: var(--card); border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }

.btn-ghost    { background: transparent; }
.btn-ghost:hover { background: var(--muted); }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { filter: brightness(0.97); }

.btn-sm { padding: 0.35rem 0.65rem; font-size: 12.5px; }
.btn-lg { padding: 0.68rem 1.15rem; font-size: 14.5px; }
.btn-block { width: 100%; }

/* --- Cards ---------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1.1rem; }

.card-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 600; }
.card-head .sub { font-size: 12.5px; color: var(--muted-fg); margin-top: 0.1rem; }
.card-head .actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.card-body { padding: 1.15rem; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  font-size: 13px; color: var(--muted-fg);
}

/* --- KPI cards ------------------------------------------------------ */

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

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.kpi .label { font-size: 12.5px; color: var(--muted-fg); font-weight: 500; }
.kpi .value { font-size: 23px; font-weight: 650; letter-spacing: -0.02em; margin-top: 0.35rem; line-height: 1.15; }
.kpi .foot  { margin-top: 0.6rem; display: flex; align-items: center; gap: 0.5rem; font-size: 12px; color: var(--muted-fg); flex-wrap: wrap; }
.kpi .kpi-ico {
  position: absolute; top: 1rem; right: 1.1rem;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.kpi .kpi-ico.green { background: var(--success-soft); color: var(--success); }
.kpi .kpi-ico.amber { background: var(--warning-soft); color: var(--warning); }
.kpi .kpi-ico.red   { background: var(--danger-soft);  color: var(--danger); }

.delta {
  display: inline-flex; align-items: center; gap: 0.2rem;
  padding: 0.12rem 0.42rem;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.delta.up   { background: var(--success-soft); color: var(--success); }
.delta.down { background: var(--danger-soft);  color: var(--danger); }
.delta.flat { background: var(--muted);        color: var(--muted-fg); }
.delta .ico { width: 11px; height: 11px; }

/* --- Grids ---------------------------------------------------------- */

.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
.grid-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1100px) {
  .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
}

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

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

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-fg);
  padding: 0.7rem 1.15rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--card);
}
table.table td {
  padding: 0.78rem 1.15rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr:hover { background: var(--bg); }
table.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.table .shrink { width: 1%; white-space: nowrap; }
table.table a.strong { font-weight: 600; color: var(--fg); }
table.table a.strong:hover { color: var(--accent); }
table.table .sub { font-size: 12px; color: var(--muted-fg); }
table.table tfoot td {
  font-weight: 650;
  border-top: 2px solid var(--border);
  border-bottom: 0;
  background: var(--bg);
}
table.table.rows-tight td { padding: 0.55rem 1.15rem; }

th.sortable a { color: var(--muted-fg); display: inline-flex; gap: 0.25rem; align-items: center; }
th.sortable a:hover { color: var(--fg); text-decoration: none; }

/* --- Status pills --------------------------------------------------- */

.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  white-space: nowrap;
  text-transform: capitalize;
}
.pill.ok      { background: var(--success-soft); color: var(--success); }
.pill.info    { background: var(--info-soft);    color: var(--info); }
.pill.warn    { background: var(--warning-soft); color: var(--warning); }
.pill.danger  { background: var(--danger-soft);  color: var(--danger); }
.pill.neutral { background: var(--muted);        color: var(--muted-fg); }
.pill.outline { background: transparent; border: 1px solid var(--border); color: var(--muted-fg); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem 1.1rem;
}
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) {
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
}
.field.span-2 { grid-column: span 2; }
.field.span-all { grid-column: 1 / -1; }
@media (max-width: 760px) { .field.span-2 { grid-column: span 1; } }

.field label, .field .label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  margin-bottom: 0.32rem;
  color: var(--fg);
}
.field .req { color: var(--danger); }

.input, .select, .textarea,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="tel"],
input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  padding: 0.52rem 0.7rem;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 13.5px;
  color: var(--fg);
}
textarea { min-height: 90px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23677383' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}
[data-theme="dark"] select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ba6b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 120, 125, 0.13);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--muted);
  color: var(--muted-fg);
  cursor: not-allowed;
}
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }

.field .help  { font-size: 11.5px; color: var(--muted-fg); margin-top: 0.28rem; }
.field .error { font-size: 11.5px; color: var(--danger); margin-top: 0.28rem; }

.input-group { display: flex; }
.input-group .addon {
  display: grid; place-items: center;
  padding: 0 0.7rem;
  border: 1px solid var(--input-border);
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--muted);
  color: var(--muted-fg);
  font-size: 13px;
  white-space: nowrap;
}
.input-group input, .input-group select { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.check {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 13.5px; cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.switch-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row .txt { flex: 1; }
.switch-row .txt .t { font-size: 13.5px; font-weight: 550; }
.switch-row .txt .d { font-size: 12.5px; color: var(--muted-fg); }

/* --- Filter bar ----------------------------------------------------- */

.filter-bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-bar .search-field { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.filter-bar .search-field input { padding-left: 2.1rem; }
.filter-bar .search-field .ico {
  position: absolute; left: 0.68rem; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--muted-fg); pointer-events: none;
}
.filter-bar select, .filter-bar input[type="date"] { width: auto; min-width: 140px; }
.filter-bar .spacer { flex: 1; }

/* --- Pagination ----------------------------------------------------- */

.pagination { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
.pagination a, .pagination span {
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--fg);
}
.pagination a:hover { background: var(--muted); text-decoration: none; }
.pagination .disabled { opacity: 0.45; }
.pagination .current { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }

/* --- Empty state ---------------------------------------------------- */

.empty { text-align: center; padding: 3rem 1.5rem; }
.empty .ico {
  width: 46px; height: 46px; margin: 0 auto 0.9rem;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--muted); color: var(--muted-fg);
}
.empty h3 { font-size: 15px; margin-bottom: 0.3rem; }
.empty p { color: var(--muted-fg); font-size: 13.5px; max-width: 420px; margin: 0 auto 1.1rem; }

/* --- Alerts --------------------------------------------------------- */

.alert {
  display: flex; align-items: flex-start; gap: 0.65rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert .ico { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.alert.success { background: var(--success-soft); color: var(--success); border-color: rgba(10,126,58,0.2); }
.alert.error   { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(219,44,43,0.2); }
.alert.warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(210,121,8,0.2); }
.alert.info    { background: var(--info-soft);    color: var(--info);    border-color: rgba(0,120,125,0.2); }
.alert .close { margin-left: auto; background: none; border: 0; cursor: pointer; color: inherit; opacity: 0.6; }
.alert .close:hover { opacity: 1; }

.toast-stack {
  position: fixed; top: 1rem; right: 1rem;
  z-index: 200; display: flex; flex-direction: column; gap: 0.6rem;
  max-width: 380px;
}
.toast-stack .alert {
  margin: 0;
  box-shadow: var(--shadow-lg);
  background: var(--card);
  animation: toast-in 0.22s ease;
}
.toast-stack .alert.success { background: var(--success-soft); }
.toast-stack .alert.error   { background: var(--danger-soft); }
.toast-stack .alert.warning { background: var(--warning-soft); }
.toast-stack .alert.info    { background: var(--info-soft); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* --- Line item editor ----------------------------------------------- */

.lines-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lines-table th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted-fg);
  padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.lines-table td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.lines-table td:first-child, .lines-table th:first-child { padding-left: 1.15rem; }
.lines-table td:last-child,  .lines-table th:last-child  { padding-right: 1.15rem; }
.lines-table input, .lines-table select, .lines-table textarea { padding: 0.42rem 0.55rem; font-size: 13px; }
.lines-table .num input { text-align: right; }
.lines-table .row-total { text-align: right; padding-top: 0.75rem; font-variant-numeric: tabular-nums; font-weight: 550; }
.lines-table .drag { cursor: grab; color: var(--muted-fg); width: 1%; padding-left: 0.6rem; }
.lines-table .remove-line {
  border: 0; background: none; color: var(--muted-fg); cursor: pointer;
  padding: 0.4rem; border-radius: var(--radius-sm);
}
.lines-table .remove-line:hover { background: var(--danger-soft); color: var(--danger); }
.lines-table tr.line-row.dragging { opacity: 0.4; }

.col-qty   { width: 90px; }
.col-price { width: 130px; }
.col-disc  { width: 90px; }
.col-tax   { width: 150px; }
.col-total { width: 130px; }
.col-acct  { width: 190px; }

.totals-panel { display: flex; justify-content: flex-end; padding: 1.15rem; }
.totals-panel .rows { width: 330px; max-width: 100%; }
.totals-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.42rem 0; font-size: 13.5px;
}
.totals-row .lbl { color: var(--muted-fg); }
.totals-row .amt { font-variant-numeric: tabular-nums; font-weight: 550; }
.totals-row.grand {
  border-top: 2px solid var(--border);
  margin-top: 0.45rem; padding-top: 0.75rem;
  font-size: 16px; font-weight: 650;
}
.totals-row.due { color: var(--accent); font-weight: 650; }

/* --- Kanban --------------------------------------------------------- */

.kanban {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  align-items: start;
}
.kanban-col {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  min-height: 130px;
}
.kanban-col.drop-target { border-color: var(--accent); background: var(--accent-soft); }
.kanban-head {
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid var(--border);
}
.kanban-head .t { display: flex; align-items: center; gap: 0.5rem; font-size: 13.5px; font-weight: 600; }
.kanban-head .count {
  margin-left: auto;
  min-width: 20px; padding: 0 0.35rem;
  border-radius: 999px; background: var(--muted); color: var(--muted-fg);
  font-size: 11px; font-weight: 650; text-align: center; line-height: 18px;
}
.kanban-head .sum { font-size: 12px; color: var(--muted-fg); margin-top: 0.15rem; }
.kanban-body { padding: 0.7rem; display: flex; flex-direction: column; gap: 0.7rem; }

.deal-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.8rem;
  background: var(--card);
  cursor: grab;
}
.deal-card:hover { border-color: var(--accent); }
.deal-card.dragging { opacity: 0.45; }
.deal-card .t { font-size: 13px; font-weight: 600; line-height: 1.35; }
.deal-card .c { font-size: 12px; color: var(--muted-fg); margin-top: 0.1rem; }
.deal-card .v { font-size: 12.5px; font-weight: 600; margin-top: 0.45rem; font-variant-numeric: tabular-nums; }
.deal-card .actions { display: flex; gap: 0.35rem; margin-top: 0.6rem; }
.deal-card .actions .btn { flex: 1; padding: 0.26rem 0.4rem; font-size: 11.5px; }

/* --- Charts --------------------------------------------------------- */

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis-text { fill: var(--muted-fg); font-size: 10.5px; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem;
  justify-content: center;
  margin-top: 0.85rem; font-size: 12px; color: var(--muted-fg);
}
.chart-legend .item { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 2px; }

.bar-track { height: 7px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 999px; background: var(--accent); }

/* --- Detail views --------------------------------------------------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem 1.5rem;
}
.detail-item .k { font-size: 11.5px; color: var(--muted-fg); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.detail-item .v { font-size: 13.5px; margin-top: 0.15rem; }

.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before {
  content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 1.1rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: ''; position: absolute; left: -1.4rem; top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--accent);
}
.timeline-item .when { font-size: 11.5px; color: var(--muted-fg); }
.timeline-item .what { font-size: 13.5px; }

/* --- Tabs ----------------------------------------------------------- */

.tabs {
  display: flex; gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.2rem;
  overflow-x: auto;
}
.tabs a {
  padding: 0.6rem 0.9rem;
  font-size: 13.5px; font-weight: 550;
  color: var(--muted-fg);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Auth pages ----------------------------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } }

.auth-side {
  background: var(--sidebar);
  color: var(--sidebar-fg);
  padding: 3rem;
  display: flex; flex-direction: column; justify-content: center;
}
@media (max-width: 900px) { .auth-side { display: none; } }
.auth-side h2 { font-size: 30px; line-height: 1.25; margin-bottom: 1rem; }
.auth-side p { color: var(--sidebar-muted); font-size: 15px; max-width: 460px; }
.auth-side ul { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: 0.85rem; }
.auth-side li { display: flex; align-items: flex-start; gap: 0.7rem; font-size: 14px; }
.auth-side li .ico { color: var(--accent); flex: 0 0 18px; margin-top: 2px; }

.auth-main {
  display: flex; align-items: center; justify-content: center;
  padding: 2.5rem 1.5rem;
  background: var(--bg);
}
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand { display: flex; align-items: center; gap: 0.65rem; margin-bottom: 1.8rem; }
.auth-card h1 { font-size: 22px; margin-bottom: 0.3rem; }
.auth-card .lede { color: var(--muted-fg); font-size: 13.5px; margin-bottom: 1.5rem; }
.auth-card form { display: grid; gap: 1rem; }
.auth-foot { margin-top: 1.4rem; font-size: 13px; color: var(--muted-fg); text-align: center; }

/* --- Print documents (invoices) ------------------------------------- */

.doc-sheet {
  background: #fff;
  color: #112a43;
  max-width: 820px;
  margin: 0 auto;
  padding: 3rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.doc-head { display: flex; gap: 2rem; align-items: flex-start; margin-bottom: 2.4rem; }
.doc-head .logo { max-height: 62px; max-width: 220px; }
.doc-head .right { margin-left: auto; text-align: right; }
.doc-title { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; }
.doc-meta { font-size: 13px; color: #677383; margin-top: 0.35rem; }
.doc-parties { display: flex; gap: 3rem; margin-bottom: 2rem; flex-wrap: wrap; }
.doc-parties .party { min-width: 210px; }
.doc-parties .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #677383; font-weight: 650; margin-bottom: 0.35rem; }
.doc-parties .nm { font-weight: 600; font-size: 14px; }
.doc-parties address { font-style: normal; font-size: 13px; color: #344d66; line-height: 1.6; }
table.doc-lines { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 1.6rem; }
table.doc-lines th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: #677383; padding: 0.6rem 0.5rem; border-bottom: 2px solid #dbe1e7;
}
table.doc-lines td { padding: 0.7rem 0.5rem; border-bottom: 1px solid #edf0f4; vertical-align: top; }
table.doc-lines .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-totals { display: flex; justify-content: flex-end; }
.doc-totals .rows { width: 300px; }
.doc-notes { margin-top: 2.4rem; padding-top: 1.4rem; border-top: 1px solid #edf0f4; font-size: 12.5px; color: #344d66; }
.doc-notes .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #677383; font-weight: 650; margin-bottom: 0.3rem; }
.doc-stamp {
  display: inline-block; padding: 0.3rem 0.8rem; border-radius: 999px;
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
}

@media print {
  .no-print, .sidebar, .topbar, .toast-stack { display: none !important; }
  .main { margin-left: 0 !important; }
  .page { padding: 0 !important; }
  .doc-sheet { border: 0; padding: 0; max-width: none; }
  body { background: #fff; }
}

/* --- Utilities ------------------------------------------------------ */

.muted     { color: var(--muted-fg); }
.strong    { font-weight: 600; }
.nowrap    { white-space: nowrap; }
.num       { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm   { font-size: 12.5px; }
.text-xs   { font-size: 11.5px; }
.text-lg   { font-size: 16px; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-accent  { color: var(--accent); }

.flex      { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.35rem; } .gap-2 { gap: 0.6rem; } .gap-3 { gap: 1rem; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
.mt-0 { margin-top: 0; }   .mt-1 { margin-top: 0.4rem; }
.mt-2 { margin-top: 0.8rem; } .mt-3 { margin-top: 1.2rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 0.4rem; }
.mb-2 { margin-bottom: 0.8rem; } .mb-3 { margin-bottom: 1.2rem; }
.hidden { display: none !important; }
.w-full { width: 100%; }

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

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(9, 21, 33, 0.45);
  z-index: 45;
}

@media (max-width: 980px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main { margin-left: 0 !important; }
  .page { padding: 1rem 1rem 2rem; }
  .topbar { padding: 0.6rem 0.9rem; }
  .topbar-search { display: none; }
  .user-chip .meta { display: none; }
  .page-head h1 { font-size: 21px; }
  .doc-sheet { padding: 1.5rem; }
  .form-grid.cols-3 { grid-template-columns: 1fr; }
}

.menu-toggle { display: none; }
@media (max-width: 980px) { .menu-toggle { display: grid; } }

/* Reconciliation: a row ticked off against the statement. The tint is what
   makes a long statement period scannable at a glance. */
.table tbody tr.is-cleared { background: var(--success-soft); }
.table tbody tr.is-cleared td:first-child { box-shadow: inset 3px 0 0 var(--success); }
.table tbody tr.is-cleared .num { font-weight: 600; }
