:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --primary:      #0f766e;
  --primary-dark: #0d6460;
  --accent:       #e11d48;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --border:       #e2e8f0;
  --sidebar-bg:   #ffffff;
  --sidebar-w:    248px;
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;
  --radius:       8px;
}

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

html { font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* ── Sidebar ────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-link {
  display: block;
  padding: 8px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: background 100ms, color 100ms;
  position: relative;
}

.nav-link:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-link.active {
  color: var(--primary);
  background: #f0fdf4;
  font-weight: 500;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 20px 4px;
}

.nav-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.sidebar-user-name {
  font-weight: 500;
  color: var(--text);
}

.sidebar-user-email {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main wrapper ───────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

.main-content {
  max-width: 1100px;
  padding: 28px 32px;
}

/* ── Mobile header ──────────────────────────── */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.mobile-brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.mobile-menu-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-menu-btn span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--text);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 90;
}

/* ── Bare layout (login) ────────────────────── */
body.bare {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-shell {
  width: 100%;
  max-width: 380px;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}

.login-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.login-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.login-separator::before,
.login-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-card .form-group { text-align: left; margin-bottom: 14px; }

/* ── Page header ────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

/* ── Balance grid ───────────────────────────── */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.balance-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.balance-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.balance-negative { color: var(--danger); }

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

/* ── Section ────────────────────────────────── */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  font-size: 15px;
  font-weight: 600;
}

/* ── Tables ─────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--bg);
}

.td-reason {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-inactive { opacity: 0.55; }

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  line-height: 1.5;
  text-transform: capitalize;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef9c3; color: #92400e; }
.badge-neutral { background: #f1f5f9; color: var(--text-muted); }

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  transition: background 100ms, border-color 100ms;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover { background: #15803d; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: center; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
}

.btn-link:hover { color: var(--text); }

/* ── Forms ──────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 540px;
}

.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
  transition: border-color 100ms;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,118,110,0.12);
}

.form-control-sm {
  padding: 5px 8px;
  font-size: 13px;
}

textarea.form-control { resize: vertical; }

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.inline-form { display: inline; }

/* ── Flash messages ─────────────────────────── */
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
  border: 1px solid transparent;
}

.flash-success { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.flash-error   { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.flash-warning { background: #fef9c3; color: #92400e; border-color: #fde68a; }

/* ── Callouts ───────────────────────────────── */
.callout {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  margin-bottom: 20px;
  font-size: 14px;
}

.callout a { color: inherit; font-weight: 500; }

.callout-warning { background: #fef9c3; color: #92400e; border-color: #fde68a; }
.callout-info    { background: #e0f2fe; color: #075985; border-color: #bae6fd; }

/* ── Detail layout ──────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  align-items: start;
}

.detail-list { display: grid; gap: 0; }

.detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }

.detail-row dt {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding-top: 1px;
}

.detail-row dd { color: var(--text); }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ── Approval list ──────────────────────────── */
.approval-list { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.approval-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  padding: 14px 20px;
}

.approval-item:hover { background: var(--bg); }

.approval-who { font-weight: 500; margin-bottom: 2px; }
.approval-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.approval-reason { font-size: 13px; color: var(--text-muted); }

.approval-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Credit list ────────────────────────────── */
.credit-list { display: grid; gap: 12px; }
.credit-item { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.credit-item:last-child { border-bottom: none; padding-bottom: 0; }
.credit-who { font-weight: 500; font-size: 13px; }
.credit-meta { font-size: 12px; color: var(--text-muted); margin: 2px 0; }
.credit-reason { font-size: 12px; color: var(--text-muted); }

/* ── Filter bar ─────────────────────────────── */
.filter-bar { display: flex; gap: 8px; }

/* ── Empty state ────────────────────────────── */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* ── Misc ───────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.link-secondary { color: var(--text-muted); text-decoration: none; font-size: 13px; }
.link-secondary:hover { color: var(--text); text-decoration: underline; }

h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
    transition: transform 200ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  .sidebar-overlay.visible { display: block; }

  .main-wrapper { margin-left: 0; }

  .mobile-header { display: flex; }

  .main-content { padding: 20px 16px; }

  .balance-grid { grid-template-columns: repeat(2, 1fr); }

  .detail-grid { grid-template-columns: 1fr; }

  .page-header { flex-wrap: wrap; }

  .approval-item { flex-direction: column; align-items: flex-start; }
  .approval-actions { flex-wrap: wrap; }

  .table { font-size: 13px; }
  .table th, .table td { padding: 8px 12px; }

  .form-card { padding: 20px 16px; }
}

@media (max-width: 480px) {
  .balance-grid { grid-template-columns: 1fr 1fr; }
  .balance-value { font-size: 20px; }
}
