:root {
  --primary: #183884;
  --primary-dark: #0f2456;
  --primary-light: #2a4fa8;
  --accent: #f59e0b;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --paper: #f6f7fa;
  --white: #fff;
  --blue-soft: #edf2ff;
  --red: #9b2c2c;
  --shadow: 0 8px 28px rgba(15, 36, 86, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--primary); }
.shell { min-height: 100vh; display: flex; }

.sidebar {
  width: 244px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 24px 18px;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  box-shadow: 8px 0 28px rgba(15, 36, 86, .12);
  transition: transform .2s ease;
}
.brand {
  display: block;
  margin: 0 4px 28px;
  padding: 10px;
  border-radius: 9px;
  background: white;
  text-decoration: none;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .12);
}
.brand img { display: block; width: 100%; height: auto; }
.brand span {
  display: block;
  margin-top: 8px;
  color: var(--primary);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .1em;
  text-align: center;
  text-transform: uppercase;
}
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a {
  display: block;
  position: relative;
  padding: 10px 12px;
  border-radius: 7px;
  color: rgba(255, 255, 255, .88);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .1); color: white; transform: translateX(2px); }
.sidebar nav a.active { background: white; color: var(--primary); }
.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}
.nav-scrim { display: none; }

.main { width: 100%; }
.authenticated .main { width: calc(100% - 244px); margin-left: 244px; }
header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  padding: 0 32px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(15, 36, 86, .035);
  backdrop-filter: blur(8px);
}
main { max-width: 1400px; margin: auto; padding: 36px; }
.nav-toggle { display: none; }
.user-name { color: var(--muted); font-size: 14px; }
.inline { display: inline; margin: 0; }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }
.link:hover { color: var(--primary-light); }

.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; color: var(--primary-dark); font-size: 30px; line-height: 1.2; letter-spacing: -.035em; }
.eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.actions, .row-actions { display: flex; align-items: center; gap: 10px; }
.row-actions { justify-content: flex-end; }

.rowmenu { position: relative; }
.menu-trigger { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; }
.menu-trigger:hover, .menu-trigger[aria-expanded="true"] { border-color: #b7c5e8; background: var(--blue-soft); color: var(--primary); }
.menu-pop { position: fixed; z-index: 50; display: grid; gap: 2px; min-width: 168px; padding: 6px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 36, 86, .16); transform: translateX(-100%); }
.menu-pop a, .menu-pop button { display: block; width: 100%; margin: 0; padding: 9px 11px; border: 0; border-radius: 6px; background: none; color: var(--ink); font: inherit; font-weight: 600; font-size: 13px; text-align: left; text-decoration: none; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--blue-soft); color: var(--primary); }
.menu-pop form { margin: 0; }
.menu-pop button.danger { color: var(--red); }
.menu-pop button.danger:hover { background: #fbe5e5; color: var(--red); }

.bulkbar { display: flex; align-items: center; gap: 14px; margin-bottom: 15px; padding: 11px 16px; border: 1px solid #c7d4f0; border-radius: 9px; background: var(--blue-soft); }
.bulkbar span { color: var(--primary-dark); font-size: 14px; }
.bulkbar .button { padding: 7px 13px; }
.danger-button { border-color: var(--red); background: var(--red); color: white; }
.danger-button:hover { border-color: #7a1f1f; background: #7a1f1f; }
.col-select { width: 38px; text-align: center; }
.col-select input { width: auto; margin: 0; cursor: pointer; }
.button { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; padding: 9px 14px; text-decoration: none; cursor: pointer; font-weight: 650; }
.button.primary { border-color: var(--primary); background: var(--primary); color: white; }
.button.primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button.secondary { background: white; color: var(--ink); }

.filters { margin-bottom: 15px; }
.filters input { max-width: 420px; }
.table-wrap, .card, .form-card, .auth-card { background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #fafbfc; color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #fbfcff; }
tbody tr:last-child td { border: 0; }
.empty { padding: 40px; color: var(--muted); text-align: center; }
.pagination { display: flex; justify-content: center; gap: 18px; padding: 20px; }

.form-card { max-width: 900px; padding: 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid label { display: grid; gap: 6px; font-weight: 600; }
.form-grid label:has(textarea), .form-grid label:has(select[multiple]) { grid-column: 1 / -1; }
input, select, textarea { width: 100%; border: 1px solid #c9ced8; border-radius: 6px; padding: 9px 10px; background: white; color: var(--ink); font: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--primary-light); outline: 3px solid rgba(42, 79, 168, .12); }
textarea { min-height: 110px; }
.form-card .actions { justify-content: flex-end; margin-top: 25px; }
.errorlist, .errors { color: var(--red); margin: 4px 0; padding-left: 20px; }
.message { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 15px; border-left: 4px solid var(--primary); border-radius: 7px; background: var(--blue-soft); margin-bottom: 18px; }
.message.error { border-left-color: var(--red); background: #fbe5e5; color: var(--red); }
.message.success { border-left-color: #1e7e45; background: #e6f4ea; color: #1e7e45; }
.message-close { flex: 0 0 auto; border: 0; background: none; color: inherit; font-size: 20px; line-height: 1; cursor: pointer; opacity: .65; padding: 0 2px; }
.message-close:hover { opacity: 1; }

.grid { display: grid; gap: 22px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.card { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.card h2 { margin: 0; color: var(--primary-dark); font-size: 18px; }
.list > div { display: grid; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list span, .muted, small { color: var(--muted); }
.timeline article { border-left: 2px solid #ccd7f2; padding: 2px 0 20px 18px; }
.timeline article p { margin: 8px 0; }
.badge { display: inline-block; border-radius: 20px; padding: 2px 8px; background: var(--blue-soft); color: var(--primary); font-size: 11px; font-weight: 750; text-transform: uppercase; white-space: nowrap; }
.badge.success { background: #e6f4ea; color: #1e7e45; }
.badge.warning { background: #fff4e0; color: #b06d00; }
.badge.danger { background: #fbe5e5; color: var(--red); }
.badge.muted { background: #eef0f3; color: var(--muted); }
.revision, .history { margin-top: 18px; }
.details div { display: grid; grid-template-columns: minmax(110px, 35%) 1fr; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.details dt { color: var(--muted); font-size: 13px; }
.details dd { margin: 0; font-weight: 600; }

.customer-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: -36px -36px 28px;
  padding: 34px 36px 30px;
  background: linear-gradient(115deg, var(--primary-dark), var(--primary));
  color: white;
}
.customer-hero h1 { margin: 0; font-size: 34px; letter-spacing: -.035em; }
.customer-hero p { margin: 6px 0 0; color: rgba(255, 255, 255, .75); }
.customer-hero .eyebrow { color: #bfcdf2; }
.customer-hero a:not(.button) { color: white; }
.customer-hero .button.secondary { border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: white; }
.customer-hero .button.primary { border-color: white; background: white; color: var(--primary); }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.summary-card { padding: 18px 20px; border: 1px solid var(--line); border-radius: 9px; background: white; box-shadow: var(--shadow); }
.summary-card strong { display: block; color: var(--primary); font-size: 28px; line-height: 1; }
.summary-card span { display: block; margin-top: 7px; color: var(--muted); font-size: 13px; }
.account-note { margin-bottom: 22px; padding: 16px 20px; border-left: 4px solid var(--accent); border-radius: 7px; background: #fffbeb; }
.account-note p { margin: 5px 0 0; }
.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-bottom: 22px; }
.contact-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.contact-card { display: flex; align-items: center; gap: 11px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); text-decoration: none; }
.contact-card:hover { border-color: #b7c5e8; background: var(--blue-soft); }
.contact-card > span:last-child { display: grid; min-width: 0; }
.contact-card em { color: var(--primary); font-size: 10px; font-style: normal; text-transform: uppercase; }
.contact-avatar { display: grid; width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; background: var(--primary); color: white; font-weight: 750; place-items: center; }
.section-heading { margin: 30px 0 14px; }
.section-heading h2 { margin: 0; color: var(--primary-dark); font-size: 23px; }
.linked-records { margin-top: 26px; }
.linked-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.linked-group { padding: 16px; border: 1px solid var(--line); border-radius: 9px; background: white; box-shadow: var(--shadow); }
.linked-group h3, .pipeline-column h3 { margin: 0 0 10px; color: var(--primary); font-size: 13px; letter-spacing: .05em; text-transform: uppercase; }
.linked-list { display: grid; }
.linked-list > a { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.linked-list > a:last-child { border: 0; }
.linked-list > a:hover strong { color: var(--primary); }
.linked-list a > span { display: grid; min-width: 0; }
.linked-list small { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.linked-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linked-list em { color: var(--muted); font-size: 12px; font-style: normal; white-space: nowrap; }
.linked-list em.overdue { color: var(--red); font-weight: 700; }
.linked-list.compact > a { padding: 9px 0; }
.commercial-section { margin-top: 30px; }
.pipeline-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: white; box-shadow: var(--shadow); }
.pipeline-column { min-width: 0; padding: 17px; border-right: 1px solid var(--line); }
.pipeline-column:last-child { border: 0; }
.pipeline-column > a { display: grid; padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.pipeline-column > a:last-child { border: 0; }
.pipeline-column > a:hover strong { color: var(--primary); }
.pipeline-column span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.auth-card { width: min(390px, calc(100% - 32px)); margin: 9vh auto; padding: 30px; border-top: 4px solid var(--primary); }
.login-logo { display: block; width: 230px; max-width: 100%; margin: 0 auto 24px; }
.auth-card h1 { color: var(--primary-dark); text-align: center; }
.auth-card label { display: grid; gap: 5px; margin: 15px 0; }
.auth-card button { width: 100%; justify-content: center; }

@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .nav-scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 36, 86, .45); }
  .authenticated .main { width: 100%; margin: 0; }
  header { padding: 0 20px; }
  .nav-toggle { display: grid; width: 38px; height: 38px; margin-right: auto; padding: 9px; border: 0; border-radius: 6px; background: var(--blue-soft); cursor: pointer; align-content: space-between; }
  .nav-toggle span { display: block; height: 2px; border-radius: 2px; background: var(--primary); }
  main { padding: 22px; }
  .grid.two, .form-grid { grid-template-columns: 1fr; }
  .customer-hero { margin: -22px -22px 22px; padding: 26px 22px; align-items: flex-start; flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .account-grid { grid-template-columns: 1fr; }
  .pipeline-grid { grid-template-columns: 1fr 1fr; }
  .pipeline-column:nth-child(2) { border-right: 0; }
  .pipeline-column:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .page-heading { align-items: flex-start; }
  .table-wrap { margin-right: -22px; border-radius: 10px 0 0 10px; }
  .user-name { display: none; }
}

@media (max-width: 520px) {
  .contact-list, .pipeline-grid { grid-template-columns: 1fr; }
  .pipeline-column { border-right: 0; border-bottom: 1px solid var(--line); }
  .pipeline-column:nth-child(3) { border-bottom: 1px solid var(--line); }
}
