/* Payroll distribution — layout and components.
   Baseline: _examples/ui (sidebar shell, topbar, metric cards, panels). */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-muted: #f9fafc;
  --border: #e6e8ef;
  --border-strong: #d5d9e3;
  --text: #111827;
  --text-muted: #6b7280;
  --text-soft: #9aa1ae;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --blue: #2563eb;
  --blue-soft: #e8f0fe;
  --purple: #7c3aed;
  --purple-soft: #f1eafe;
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #b45309;
  --amber-soft: #fef3e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --sidebar-width: 248px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  flex-shrink: 0;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 22px;
  color: var(--text);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  width: 30px;
  height: 30px;
  padding: 5px;
  border-radius: 9px;
  background: var(--primary);
}

.brand-mark span { border-radius: 2px; background: rgba(255, 255, 255, 0.9); }
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) {
  background: rgba(255, 255, 255, 0.55);
}

.brand-name { font-size: 1.05rem; font-weight: 700; }
.brand-sub { display: block; font-size: 0.72rem; font-weight: 500; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  padding: 14px 10px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--text-muted);
}

.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }

.nav-icon { width: 18px; text-align: center; font-size: 15px; }

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
}

.nav-divider { height: 1px; margin: 10px 6px; background: var(--border); }

.workspace-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.workspace-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--purple-soft);
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 700;
}

.workspace-meta { display: flex; flex-direction: column; line-height: 1.25; }
.workspace-meta strong { font-size: 0.85rem; }
.workspace-meta span { font-size: 0.75rem; color: var(--text-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.breadcrumb { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.notice-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.page { width: 100%; max-width: 1280px; padding: 32px 32px 56px; }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.page-heading h1 { font-size: 1.6rem; font-weight: 700; }
.page-heading p { margin: 6px 0 0; color: var(--text-muted); }
.page-heading-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 4px; }
.page-date { padding-top: 6px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* -------------------------------------------------------------- buttons */
.primary-button, .secondary-button, .text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button { border: 1px solid var(--primary); background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-hover); color: #fff; }
.primary-button:disabled { opacity: 0.65; cursor: progress; }
.primary-button.large { height: 44px; padding: 0 22px; font-size: 0.95rem; }

.secondary-button { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.secondary-button:hover { background: var(--surface-muted); color: var(--text); }

.text-button { height: auto; padding: 0; border: 0; background: none; color: var(--primary); }

/* --------------------------------------------------------------- metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}

.metric-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
}

.metric-icon.blue, .feature-icon.blue { background: var(--blue-soft); color: var(--blue); }
.metric-icon.purple, .feature-icon.purple { background: var(--purple-soft); color: var(--purple); }
.metric-icon.green, .feature-icon.green { background: var(--green-soft); color: var(--green); }
.metric-icon.red { background: var(--red-soft); color: var(--red); }
.metric-icon.amber { background: var(--amber-soft); color: var(--amber); }

.metric-label { margin: 0 0 2px; color: var(--text-muted); font-size: 0.82rem; font-weight: 500; }
.metric-value-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.metric-value-row strong { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-hint { font-size: 0.78rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- panels */
.panel {
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 { font-size: 1rem; font-weight: 650; }
.panel-header p { margin: 2px 0 0; color: var(--text-muted); font-size: 0.85rem; }
.panel-header-actions { display: flex; align-items: center; gap: 14px; }
.panel-body { padding: 20px; }

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 24px;
  align-items: start;
  margin-bottom: 24px;
}

.two-column > .panel { margin-bottom: 0; }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); }

.tab {
  padding: 12px 10px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab.active { border-bottom-color: var(--primary); color: var(--primary); }
.tab .count { margin-left: 4px; color: var(--text-soft); font-weight: 500; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; }

table.data th {
  padding: 10px 20px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

table.data td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbfbfe; }
table.data tr.credit-row td { background: var(--surface-muted); font-weight: 600; }
table.data tfoot td {
  padding: 14px 20px;
  border-top: 2px solid var(--border-strong);
  background: var(--surface-muted);
  font-weight: 700;
}

table.data.compact td, table.data.compact th { padding-left: 16px; padding-right: 16px; }

.row-link { font-weight: 600; white-space: nowrap; }

/* ----------------------------------------------------------- pills/badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.completed, .pill.balanced { background: var(--green-soft); color: var(--green); }
.pill.failed, .pill.unbalanced { background: var(--red-soft); color: var(--red); }
.pill.pending { background: var(--amber-soft); color: var(--amber); }

.chip {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ------------------------------------------------------- definition list */
.meta-list { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; }
.meta-list dt { color: var(--text-muted); font-weight: 500; }
.meta-list dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ----------------------------------------------------------------- alerts */
.messages { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.alert {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 500;
}

.alert.success { border-color: #bfe5cb; background: var(--green-soft); color: #14532d; }
.alert.error { border-color: #f5c2c2; background: var(--red-soft); color: #7f1d1d; }
.alert.info { border-color: #c9d8fb; background: var(--blue-soft); color: #1e3a8a; }
.alert.warning { border-color: #f5d9a8; background: var(--amber-soft); color: #78350f; }

.error-panel { border-color: #f5c2c2; }
.error-panel .panel-header { background: var(--red-soft); border-bottom-color: #f5c2c2; }
.error-panel .panel-header h2 { color: #991b1b; }
.error-list { margin: 0; padding: 16px 20px 16px 40px; }
.error-list li { padding: 4px 0; }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; }
.field .help { color: var(--text-muted); font-size: 0.8rem; }
.field-errors { margin: 0; padding: 0; list-style: none; color: var(--red); font-size: 0.82rem; font-weight: 500; }

.field input[type="text"], .field select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  color: var(--text);
}

.field input:focus, .field select:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.field.has-error input, .field.has-error select { border-color: var(--red); }

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

.file-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  min-width: 0;
}

.file-card.has-error { border-color: var(--red); background: #fff8f8; }
.file-card-head { display: flex; align-items: center; gap: 12px; }
.file-card h3 { font-size: 0.95rem; }
.file-card p { margin: 0; color: var(--text-muted); font-size: 0.82rem; }

.feature-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  font-size: 16px;
}

.file-card input[type="file"] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

/* ------------------------------------------------------------ empty state */
.empty-state { padding: 48px 20px; text-align: center; color: var(--text-muted); }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 1rem; }
.empty-state .primary-button { margin-top: 16px; }

.pagination { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
  .two-column > .panel { margin-bottom: 0; }
}

@media (max-width: 960px) {
  .file-grid, .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    padding: 10px 16px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand { padding: 0; margin-right: auto; }
  .brand-name { font-size: 1rem; }
  .brand-sub, .nav-label, .nav-divider, .workspace-switcher, .nav-item.secondary { display: none; }
  .brand-mark { width: 28px; height: 28px; }
  .nav { flex-direction: row; }
  .nav-item { padding: 6px 10px; }
  .nav-item .nav-text { display: none; }

  .topbar { position: static; height: auto; padding: 12px 16px; }
  .page { padding: 24px 16px 40px; }
  .page-heading { flex-direction: column; gap: 12px; }
  .page-date { padding-top: 0; }
}

@media (max-width: 620px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .panel-header-actions { width: 100%; justify-content: space-between; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .notice-chip { display: none; }
  .form-actions { flex-direction: column; align-items: stretch; }
  table.data th, table.data td { padding-left: 12px; padding-right: 12px; }
  .hide-sm { display: none; }
}
.file-card .columns-label { margin-bottom: 4px; }
table.data td.mono { white-space: nowrap; }

/* ------------------------------------------------------------ user menu */
.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
}
.user-name { font-weight: 600; }
.user-menu form { margin: 0; }
.logout-button { color: var(--text-muted); font-weight: 500; }
.logout-button:hover { color: var(--text); }

/* ------------------------------------------------------------ login page */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: radial-gradient(circle at 20% 0%, var(--primary-soft), var(--bg) 55%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.08);
}
.auth-card .brand { padding: 0 0 24px; }
.auth-card h1 { font-size: 1.35rem; }
.auth-card > p { margin: 6px 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-card .field input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
}
.auth-card .field input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.auth-card .alert { margin-bottom: 16px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-footer { margin: 20px 0 0; font-size: 0.8rem; text-align: center; }

@media (max-width: 620px) {
  .user-name { display: none; }
}

/* metric card with label/value pairs (e.g. debit and credit) */
.metric-body { min-width: 0; flex: 1; }
.metric-pairs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 2px 0 0;
  align-items: baseline;
}
.metric-pairs dt { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; }
.metric-pairs dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
