:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8f9fc;
  --border: #e6e8f0;
  --text: #1c2333;
  --text-muted: #6b7280;
  --text-faint: #9aa1b2;
  --primary: #5b5ee0;
  --primary-dark: #4548c9;
  --primary-light: #eef0fe;
  --accent: #d6336c;
  --accent-light: #fdeef2;
  --success: #16a34a;
  --success-light: #e9f9ee;
  --warning: #d97706;
  --warning-light: #fef3e2;
  --danger: #e11d48;
  --danger-light: #fde8ec;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #201f3d 0%, #171633 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; }
.brand-text span { font-size: 12px; color: rgba(255,255,255,.55); }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-divider { height: 1px; background: rgba(255,255,255,.1); margin: 10px 8px; }
.nav-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: rgba(255,255,255,.35); padding: 4px 12px 6px;
}
.nav-link[target="_blank"] svg { stroke: currentColor; opacity: .75; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: rgba(255,255,255,.75); font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.12); color: #fff; }

.sidebar-footer { margin-top: auto; font-size: 11.5px; color: rgba(255,255,255,.35); padding: 0 8px; }
.sidebar-user { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.55); }
.sidebar-user strong { color: #fff; }
.sidebar-user a { color: var(--accent); font-weight: 600; }
.sidebar-user a:hover { text-decoration: underline; }

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

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 32px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; font-weight: 700; margin: 0; flex: 1; }
.menu-toggle { display: none; background: none; border: none; padding: 6px; cursor: pointer; }
.menu-toggle svg { width: 22px; height: 22px; stroke: var(--text); fill: none; stroke-width: 2; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 28px 32px 60px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(91,94,224,.35); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { padding: 8px; }

/* ---------- Cards / Form ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 20px; }
.card-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h2 { font-size: 15.5px; margin: 0; font-weight: 700; }
.card-header p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.card-body { padding: 24px; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 20px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field label .req { color: var(--accent); margin-left: 2px; }
.field .hint { font-size: 11.5px; color: var(--text-faint); }
.field .field-error { font-size: 11.5px; color: var(--danger); font-weight: 600; }
.field input.input-invalid { border-color: var(--danger); background: var(--danger-light); }
.field input.input-checking { border-color: var(--text-faint); }
.field input.input-valid { border-color: var(--success); }

input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=search], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-alt);
  font-size: 14px; color: var(--text); font-family: inherit;
  transition: border-color .15s, background .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; min-height: 70px; }
.input-money { position: relative; }
.input-money::before {
  content: '£'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); font-size: 13px; pointer-events: none;
}
.input-money input { padding-left: 26px; }

.checkbox-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; }
.checkbox-item {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-alt); cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.checkbox-item:hover { border-color: var(--primary); }
.checkbox-item.checked { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }
.checkbox-item input { width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }

.radio-pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.radio-pill {
  display: flex; align-items: center; gap: 7px; padding: 9px 14px;
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  font-size: 13.5px; font-weight: 500; background: var(--surface-alt);
  transition: border-color .15s, background .15s;
}
.radio-pill input { accent-color: var(--primary); }
.radio-pill.checked { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }

.section-title {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); margin: 0 0 4px;
}

.amounts-list { display: flex; flex-direction: column; gap: 10px; }
.amount-row {
  display: none; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 14px; background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.amount-row.active { display: flex; }
.amount-row label { font-size: 13.5px; font-weight: 500; flex: 1; }
.amount-row .input-money { width: 160px; }
.amount-row .input-money input { text-align: right; padding-right: 12px; }

.summary-box {
  background: var(--surface-alt); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 10px;
}
.summary-line { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--text-muted); }
.summary-line strong { color: var(--text); font-weight: 600; }
.summary-line.total { font-size: 16px; padding-top: 10px; border-top: 1px solid var(--border); }
.summary-line.total strong { color: var(--primary-dark); font-size: 18px; }

.form-actions {
  display: flex; justify-content: flex-end; gap: 10px; padding: 18px 24px;
  border-top: 1px solid var(--border); background: var(--surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); position: sticky; bottom: 0;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-confirmed { background: var(--success-light); color: var(--success); }
.badge-unread { background: var(--accent-light); color: var(--accent); }
.badge-read { background: var(--surface-alt); color: var(--text-faint); border: 1px solid var(--border); }
.badge-neutral { background: var(--primary-light); color: var(--primary-dark); }

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

/* ---------- Filters / Toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.toolbar select,
.toolbar input[type="date"],
.toolbar input[type="search"] {
  width: auto;
}
.search-box { position: relative; flex: 1 1 220px; min-width: 180px; max-width: 320px; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--text-faint); fill: none; stroke-width: 2; }
.search-box input { padding-left: 36px; width: 100%; }
.filter-select { flex: 0 1 160px; min-width: 130px; }
.toolbar input[type="date"] { flex: 0 1 140px; min-width: 125px; }
.toolbar .stats { font-size: 12.5px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }

@media (max-width: 860px) {
  .search-box, .filter-select, .toolbar input[type="date"] { flex: 1 1 100%; max-width: none; }
}

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card .kpi-value { font-size: 24px; font-weight: 800; margin-top: 6px; color: var(--text); }
.kpi-card .kpi-value.accent { color: var(--primary); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 1100px; }
table.data-table thead th {
  text-align: left; padding: 13px 16px; background: var(--surface-alt);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted);
  font-weight: 700; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data-table thead th a { color: inherit; display: flex; align-items: center; gap: 4px; }
table.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--surface-alt); }
.cell-name { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-checkbox, .header-checkbox { width: 16px; height: 16px; accent-color: var(--primary); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; stroke: var(--text-faint); fill: none; stroke-width: 1.5; margin-bottom: 12px; }
.empty-state h3 { margin: 0 0 6px; color: var(--text); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; gap: 12px; flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 4px; }
.pagination .pages a, .pagination .pages span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  color: var(--text-muted); border: 1px solid transparent;
}
.pagination .pages a:hover { background: var(--surface-alt); }
.pagination .pages .current { background: var(--primary); color: #fff; }

/* ---------- Modal / Toast ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(23,22,51,.45); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-body { padding: 26px 24px 10px; text-align: center; }
.modal-body .icon-wrap { width: 52px; height: 52px; border-radius: 50%; background: var(--danger-light); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.modal-body .icon-wrap svg { width: 24px; height: 24px; stroke: var(--danger); fill: none; stroke-width: 2; }
.modal-body h3 { margin: 0 0 6px; font-size: 16px; }
.modal-body p { margin: 0; font-size: 13.5px; color: var(--text-muted); }
.modal-actions { display: flex; gap: 10px; padding: 20px 24px; }
.modal-actions .btn { flex: 1; }

.toast-stack { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: #1c2333; color: #fff; padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: slideIn .2s ease-out;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Detail drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(23,22,51,.4); display: none; z-index: 90; }
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 100%; max-width: 460px;
  background: var(--surface); box-shadow: var(--shadow-lg); z-index: 95;
  transform: translateX(100%); transition: transform .25s ease; overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; }
.drawer-header h3 { margin: 0; font-size: 17px; }
.drawer-header .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.drawer-close { background: none; border: none; cursor: pointer; padding: 4px; }
.drawer-close svg { width: 20px; height: 20px; stroke: var(--text-muted); fill: none; stroke-width: 2; }
.drawer-body { padding: 20px 24px; }
.detail-group { margin-bottom: 20px; }
.detail-group h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin: 0 0 10px; }
.detail-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; border-bottom: 1px solid var(--surface-alt); }
.detail-row span:first-child { color: var(--text-muted); }
.detail-row span:last-child { font-weight: 600; text-align: right; }

@media (max-width: 1080px) {
  .form-grid, .form-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 20px 16px 50px; }
  .topbar { padding: 14px 16px; }
}
@media (max-width: 640px) {
  .form-grid, .form-grid.cols-2, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .field.span-2, .field.span-3 { grid-column: span 1; }
  .checkbox-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr; }
}
