:root {
  --ink: #102033;
  --muted: #6d7d90;
  --line: #e3ebf3;
  --card: #ffffff;
  --green: #059669;
  --green-d: #047857;
  --red: #e11d48;
  --blue: #2563eb;
  --violet: #7c3aed;
  --amber: #d97706;
  --teal: #0f766e;
  --shadow: 0 8px 24px rgba(16, 32, 51, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #dff3ee 0, #f3f7fb 240px);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea { color: var(--ink); }

.layout { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  padding: 18px 14px 20px;
  overflow: auto;
  z-index: 5;
  color: #d7e4ef;
  background: linear-gradient(185deg, #0c2340 0%, #12344a 48%, #0e4a45 100%);
}
.brand { font-size: 24px; font-weight: 800; color: #fff; padding: 8px 12px 18px; letter-spacing: -0.4px; }
.brand span { color: #34d399; }
.brand small { display: block; margin-top: 4px; font-size: 10px; letter-spacing: 1.4px; color: #9eb4c8; font-weight: 700; }
.nav-label { font-size: 10px; letter-spacing: 1.6px; color: #8ea3b8; padding: 16px 12px 6px; font-weight: 800; }
.nav a {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  color: #d5e2ee;
  margin: 3px 0;
  font-weight: 600;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav a.active { background: linear-gradient(90deg, #059669, #0d9488); color: #fff; box-shadow: 0 8px 18px rgba(5, 150, 105, 0.28); }
.nav-icon { width: 20px; text-align: center; }
.sidebar-note {
  margin: 22px 6px 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: #c5d5e4;
  line-height: 1.45;
}
.main { margin-left: 252px; min-height: 100vh; display: flex; flex-direction: column; }
.header {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.header-search { max-width: 420px; width: 100%; background: #f7fafc; }
.header-right { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #047857;
  background: linear-gradient(180deg, #d1fae5, #a7f3d0);
}
.user-name { font-size: 13px; font-weight: 800; }
.user-role { font-size: 11px; color: var(--muted); }
.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 24px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-heading h1 { margin: 0; font-size: 28px; letter-spacing: -0.6px; }
.lede { margin: 4px 0 0; color: var(--muted); }
.heading-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 0.14em; color: var(--green); text-transform: uppercase; margin-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.green { color: var(--green); }
.red { color: var(--red); }
.purple { color: var(--violet); }

.btn {
  border: 1px solid #d5deea;
  border-radius: 10px;
  background: #fff;
  padding: 10px 14px;
  color: #31445a;
  font-weight: 700;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: #f4f8fb; border-color: #c3d0df; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.25); }
.btn-primary { background: linear-gradient(180deg, #10b981, #059669); color: #fff; border-color: #059669; }
.btn-primary:hover { background: linear-gradient(180deg, #059669, #047857); border-color: #047857; }
.icon-btn { width: 36px; height: 36px; padding: 0; font-size: 22px; line-height: 1; border-radius: 10px; }
td .btn { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.danger { color: #be123c; background: #fff1f2; border-color: #fecdd3; }
.danger:hover { background: #ffe4e6; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.card, .stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { position: relative; overflow: hidden; padding: 16px 16px 14px 18px; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, var(--teal)); }
.tone-teal { --tone: #0d9488; background: linear-gradient(180deg, #f0fdfa, #fff 70%); }
.tone-blue { --tone: #2563eb; background: linear-gradient(180deg, #eff6ff, #fff 70%); }
.tone-emerald { --tone: #059669; background: linear-gradient(180deg, #ecfdf5, #fff 70%); }
.tone-amber { --tone: #d97706; background: linear-gradient(180deg, #fffbeb, #fff 70%); }
.tone-violet { --tone: #7c3aed; background: linear-gradient(180deg, #f5f3ff, #fff 70%); }
.tone-rose { --tone: #e11d48; background: linear-gradient(180deg, #fff1f2, #fff 70%); }
.stat-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -0.6px; }
.stat-foot { font-size: 12px; color: #8b98aa; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 16px; margin: 0; }
.card-search { width: 260px; max-width: 100%; }
.panel-body { padding: 18px; display: grid; gap: 14px; }
.panel-body .lede { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.filters input, .filters select, .field input, .field select, .field textarea, .header-search {
  min-width: 0;
  border: 1px solid #d5deea;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.filters input:focus, .filters select:focus, .field input:focus, .field select:focus, .field textarea:focus, .header-search:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.16);
  background: #fff;
}
.filters input { flex: 1.4; min-width: 180px; }
.filters select, .filters input[type="date"] { flex: 1; min-width: 140px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
th { background: #f7fafc; text-align: left; color: #64748b; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; padding: 12px; }
td { padding: 12px; border-top: 1px solid #edf2f7; }
tbody tr:hover { background: #f5fbf8; }
.pill { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.pill-open { background: #fef3c7; color: #a16207; }
.pill-closed { background: #d1fae5; color: #047857; }
.pill-loss { background: #ffe4e6; color: #be123c; }
.pill-manual { background: #dbeafe; color: #1d4ed8; }
.pill-fo { background: #ede9fe; color: #6d28d9; }
.pill-equity { background: #e0f2fe; color: #0369a1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 16px 0; }
.tab { background: transparent; color: #64748b; border: 0; border-radius: 10px 10px 0 0; padding: 9px 12px; font-weight: 800; font-size: 12px; }
.tab.active { background: #ecfdf5; color: #047857; }
.lower { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; margin-top: 16px; }
.client-row { display: grid; grid-template-columns: 1.3fr 0.7fr 0.9fr 1fr; gap: 10px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.client-row:hover { background: #f8fafc; }
.bar { height: 6px; background: #e7edf4; border-radius: 8px; margin-top: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, #10b981, #2563eb); }
.overview { padding: 4px 16px 8px; }
.overview-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.overview-row:last-child { border: 0; }
.footer {
  margin-top: auto;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 14px 24px;
  color: #8290a3;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.modal-bg { display: none; position: fixed; inset: 0; background: rgba(11, 23, 39, 0.72); z-index: 20; align-items: center; justify-content: center; padding: 18px; backdrop-filter: blur(3px); }
.modal-bg.show { display: flex; }
.modal { width: min(920px, 100%); max-height: 94vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: 0 24px 80px rgba(11, 23, 39, 0.28); }
.modal-sm { width: min(480px, 100%); }
.modal-head, .modal-foot { padding: 18px 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; background: #fff; }
.modal-head { position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); }
.modal-foot { position: sticky; bottom: 0; border-top: 1px solid var(--line); justify-content: flex-end; align-items: center; }
.modal-body { padding: 18px 22px 8px; }
.modal-title { font-size: 20px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: #3d4e63; min-width: 0; }
.label-text { display: flex; align-items: center; gap: 4px; }
.label-text em { color: var(--red); font-style: normal; }
.hint { font-weight: 500; color: #8b98aa; font-size: 11px; line-height: 1.4; }
.field input, .field select, .field textarea { width: 100%; font-weight: 500; background: #fbfcfe; }
.field textarea { resize: vertical; min-height: 78px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--red); box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.12); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.form-section { background: #f8fafc; border: 1px solid #e6eef6; border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.section-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.section-head h3 { margin: 0; font-size: 14px; color: var(--ink); }
.section-head p { margin: 2px 0 0; font-size: 12px; font-weight: 500; color: #7b8799; }
.step { width: 30px; height: 30px; border-radius: 9px; background: #d1fae5; color: #047857; display: grid; place-items: center; font-size: 11px; font-weight: 800; flex-shrink: 0; }
.estimates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 4px 0 14px; }
.estimate { padding: 13px 14px; border-radius: 12px; background: #fff; border: 1px solid #e6eef6; }
.estimate small { display: block; color: #7b8799; font-weight: 600; }
.estimate strong { display: block; font-size: 17px; margin-top: 4px; letter-spacing: -0.3px; }
.form-note { margin: 0; background: #fffbeb; color: #854d0e; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #102033; color: #fff; padding: 12px 16px; border-radius: 12px; display: none; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); border-left: 4px solid #34d399; }
.toast.show { display: block; }
.menu-toggle { display: none; }
.empty { text-align: center; padding: 28px; color: #8793a4; }
.client-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.client-grid > .empty, .client-grid > .card.empty { grid-column: 1 / -1; }
.expiry-card { padding: 16px 16px 6px; }
.expiry-title { font-size: 15px; }
#expiryNext { font-size: 20px; }
#resultCount { border-bottom: 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 700; }

@media (max-width: 1100px) {
  .stats, .client-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lower { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { width: 252px; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-block; }
  .header { padding: 0 14px; }
  .content { padding: 16px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .stats { gap: 10px; }
  .stat-value { font-size: 22px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3 { grid-column: span 2; }
  .estimates { grid-template-columns: 1fr 1fr; }
  .footer { padding: 14px; flex-direction: column; }
  .user-info { display: none; }
  .client-grid { grid-template-columns: 1fr; }
  .modal-body, .modal-head, .modal-foot { padding-left: 14px; padding-right: 14px; }
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
  .estimates, .stats { grid-template-columns: 1fr; }
  .header-search { display: none; }
  .content { padding: 12px; }
  .filters > * { width: 100%; flex: auto; }
  .client-row { grid-template-columns: 1fr 1fr; }
}

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #0c2340 0%, #0e4a45 55%, #dff3ee 55.1%); }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 18px; box-shadow: 0 24px 60px rgba(12, 35, 64, 0.28); padding: 28px 26px 22px; }
.login-card .brand { color: var(--ink); padding: 0 0 8px; }
.login-card h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.4px; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.login-error { margin: 0; color: #be123c; background: #fff1f2; border: 1px solid #fecdd3; border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; }
.demo-box { margin-top: 16px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; padding: 12px 14px; font-size: 13px; }
.demo-box strong { display: block; margin-bottom: 4px; color: #047857; }
.demo-box code { font-weight: 800; color: #102033; }
