:root {
  color-scheme: light;
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #eef6f4;
  --text: #16202c;
  --muted: #647187;
  --line: #e1e6ef;
  --line-soft: #eef1f6;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --primary-soft: #d6f0ec;
  --blue: #2563eb;
  --amber: #b7791f;
  --danger: #b42318;
  --green: #15803d;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow: 0 6px 16px rgba(16, 24, 40, .07), 0 2px 5px rgba(16, 24, 40, .05);
  --shadow-lg: 0 18px 40px rgba(16, 24, 40, .14);
  --radius: .7rem;
  --radius-sm: .5rem;
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 100% -10%, #e7efff 0%, rgba(231, 239, 255, 0) 55%),
    radial-gradient(900px 500px at -10% 0%, #e3f5f1 0%, rgba(227, 245, 241, 0) 50%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, Helvetica, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; }
button, .btn { min-height: 2.4rem; }

/* ---------- Shell ---------- */
.app-shell { display: grid; grid-template-columns: 17.5rem minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: linear-gradient(185deg, #1b2735 0%, #131c27 100%);
  color: #f8fafc;
  padding: 1rem .9rem 2rem;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, .05);
}
.brand { display: flex; gap: .7rem; align-items: center; padding: .45rem .35rem 1.1rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 2.5rem; height: 2.5rem;
  background: linear-gradient(150deg, #ffd84d, #f4b21a);
  color: #1b2735;
  border-radius: .6rem; font-weight: 800;
  box-shadow: 0 6px 14px rgba(244, 178, 26, .35);
}
.brand strong { font-size: 1.02rem; line-height: 1.15; }
.nav { display: grid; gap: .12rem; }
.nav a {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .7rem;
  border-radius: .5rem;
  color: #c7d2e0;
  text-decoration: none;
  font-size: .95rem;
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease, transform .05s ease;
}
.nav a:hover, .nav a:focus-visible { background: rgba(255, 255, 255, .07); color: #fff; outline: none; }
.nav a.active {
  background: linear-gradient(90deg, rgba(45, 212, 191, .22), rgba(45, 212, 191, .06));
  color: #fff;
  border-color: rgba(45, 212, 191, .35);
  box-shadow: inset 3px 0 0 0 #2dd4bf;
}
.nav-group {
  margin: 1rem .55rem .3rem;
  color: #8295a9;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.main { min-width: 0; padding: 1.4rem 1.5rem 2.5rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1.3rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.5rem; line-height: 1.2; font-weight: 700; }
.topbar > div:first-of-type { display: flex; flex-direction: column; }
.topbar span { color: var(--muted); font-size: .9rem; }
.topbar form { display: flex; align-items: center; }
.menu-btn { display: none; }
.tenant-switcher { display: flex; align-items: end; gap: .45rem; flex-wrap: wrap; }
.tenant-switcher label { display: grid; gap: .2rem; color: var(--muted); font-size: .8rem; }
.tenant-switcher select { min-width: 12rem; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .6rem; background: #fff; }

/* ---------- Panels & cards ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1.15rem;
}
.panel h2 { margin: 0 0 .9rem; font-size: 1.1rem; }
.panel h3 { margin: .2rem 0 .7rem; font-size: 1rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.dashboard-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.15rem; }
.metric {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.05rem 1.1rem;
  text-decoration: none; text-align: left;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease;
}
.metric::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: .3rem;
  background: var(--primary);
}
.metric:nth-child(4n+2)::before { background: var(--blue); }
.metric:nth-child(4n+3)::before { background: var(--amber); }
.metric:nth-child(4n+4)::before { background: var(--green); }
.metric span { display: block; color: var(--muted); font-size: .82rem; font-weight: 600; }
.metric strong { display: block; margin: .4rem 0 .15rem; font-size: 1.6rem; font-weight: 700; overflow-wrap: anywhere; }
.metric p { margin: 0; color: var(--muted); font-size: .85rem; }
.metric.link { cursor: pointer; width: 100%; }
.metric.link:hover, a.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.15rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line-soft); }
.table-wrap > table { border: 0; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; background: #fff; }
th, td { padding: .72rem .8rem; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: #f4f7fb; color: #44546a;
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
tbody tr { transition: background .1s ease; }
tbody tr:nth-child(2n) td { background: #fafbfd; }
tbody tr:hover td { background: var(--primary-soft); }
td { overflow-wrap: anywhere; }
.right { text-align: right; }

/* Sortable headers */
th.sortable, table.js-sort thead th { cursor: pointer; user-select: none; }
th.sortable a { display: inline-flex; align-items: center; gap: .25rem; text-decoration: none; color: inherit; }
th.sortable:hover, table.js-sort thead th:hover { background: #e9eff7; color: var(--primary-strong); }
th.sorted { color: var(--primary-strong); background: #e6f3f0; }
.sort-arrow { font-size: .7rem; color: var(--primary); }
table.js-sort thead th[aria-sort="ascending"], table.js-sort thead th[aria-sort="descending"] { color: var(--primary-strong); background: #e6f3f0; }
table.js-sort thead th[aria-sort]::after { content: ""; }
.cell-debt { color: var(--danger); font-weight: 600; }

/* ---------- Buttons ---------- */
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: .35rem; flex-wrap: wrap; }
.search { display: flex; gap: .45rem; min-width: min(100%, 28rem); flex-wrap: wrap; align-items: center; }
.search input[type="text"], .search input:not([type]), .search input[name="q"] { flex: 1; min-width: 8rem; }
.actions, .form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: .48rem .85rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background .12s ease, border-color .12s ease, transform .05s ease, box-shadow .12s ease;
}
.btn:hover { border-color: #c4ccd9; box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #14857b, var(--primary)); border-color: var(--primary-strong); color: #fff; }
.btn.primary:hover { background: linear-gradient(180deg, var(--primary), var(--primary-strong)); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { min-height: 2rem; padding: .3rem .6rem; }
.btn.tiny { min-height: 1.85rem; padding: .28rem .55rem; font-size: .84rem; box-shadow: none; }
.btn.danger { color: var(--danger); border-color: #f0c0bb; }
.btn.danger:hover { background: #fff4f2; }

/* ---------- Alerts & pills ---------- */
.alert { margin: 0 0 1rem; padding: .85rem 1.05rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: #eef6f4; border-left: .25rem solid var(--primary); }
.alert.error { background: #fff4f2; color: var(--danger); border-color: #f0c0bb; border-left-color: var(--danger); }
.alert.success { background: #ecfdf3; color: #027a48; border-color: #abefc6; border-left-color: var(--green); }
.alert ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.pill { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e0f2fe; color: #075985; white-space: nowrap; }
.pill.warn { background: #fff7ed; color: #9a3412; }
.pill.danger { background: #fef3f2; color: var(--danger); }
.pill.success { background: #ecfdf3; color: #027a48; }

/* ---------- Forms ---------- */
.record-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.record-form.single { grid-template-columns: minmax(0, 1fr); max-width: 44rem; }
.field { display: grid; gap: .35rem; min-width: 0; }
.field span { font-weight: 600; color: #344054; font-size: .92rem; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  background: #fff;
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .15);
}
.field textarea { resize: vertical; }
.field small { color: var(--muted); font-size: .82rem; }
.form-actions { grid-column: 1 / -1; padding-top: .75rem; border-top: 1px solid var(--line); }
.inline-check { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.req { color: var(--danger); font-weight: 700; }
.info-list { margin: .25rem 0 0; padding-left: 1.1rem; color: var(--muted); display: grid; gap: .3rem; }
details.panel summary { cursor: pointer; }
.empty { color: var(--muted); margin: .5rem 0; }

.task-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.task-list li { display: grid; gap: .12rem; padding-bottom: .6rem; border-bottom: 1px solid var(--line-soft); }
.task-list span { color: var(--muted); font-size: .88rem; }

/* ---------- Login / install ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(1000px 600px at 50% -20%, #d6f0ec, rgba(214,240,236,0) 60%), #eef2f7; }
.login-card { width: min(100%, 28rem); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; box-shadow: var(--shadow-lg); }
.login-card h1 { margin: 0 0 .25rem; font-size: 1.55rem; }
.login-card > p { margin: 0 0 1rem; color: var(--muted); }
.login-card form, .install-form { display: grid; gap: .85rem; }
.login-card label { display: grid; gap: .32rem; font-weight: 600; }
.login-card input { width: 100%; border: 1px solid #cbd5e1; border-radius: var(--radius-sm); padding: .68rem; }
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
.login-links { margin-top: 1rem; display: flex; justify-content: center; gap: .8rem; font-size: .92rem; }
.login-links a { color: var(--primary); font-weight: 700; text-decoration: none; }
.login-links a:hover { text-decoration: underline; }
.install-note { width: min(100% - 2rem, 42rem); margin: 8vh auto; background: #fff; padding: 1.6rem; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
:focus-visible { outline: 3px solid #f4c430; outline-offset: 2px; }

/* ---------- Portal ---------- */
.eyebrow { display: block; color: var(--muted); font-size: .76rem; font-weight: 700; text-transform: uppercase; margin-bottom: .2rem; }
.portal-hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-left: .28rem solid var(--primary); }
.portal-hero h2 { margin: 0; font-size: 1.4rem; line-height: 1.2; }
.portal-hero p { margin: .3rem 0 0; color: var(--muted); }
.portal-hero-actions { display: inline-flex; align-items: center; gap: .7rem; margin-left: auto; }
.portal-notification-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: #fff;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}
.portal-notification-button:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.portal-bell {
  position: relative;
  width: 1rem;
  height: 1.1rem;
  border: 2px solid #344054;
  border-bottom: 0;
  border-radius: .55rem .55rem .25rem .25rem;
}
.portal-bell::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -.34rem;
  width: .34rem;
  height: .34rem;
  border-radius: 50%;
  background: #344054;
  transform: translateX(-50%);
}
.portal-bell::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -.36rem;
  width: .42rem;
  height: .42rem;
  border-radius: 50%;
  background: #344054;
  transform: translateX(-50%);
}
.notification-count {
  position: absolute;
  top: -.45rem;
  right: -.45rem;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 .25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  border: 2px solid #fff;
  font-size: .72rem;
  font-weight: 700;
}
.portal-notifications { margin-bottom: 1rem; }
.portal-notification-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .65rem; }
.portal-notification-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: .75rem;
  align-items: start;
  padding: .8rem;
  border: 1px solid var(--line-soft);
  border-radius: .5rem;
  background: #fcfdff;
}
.portal-notification-dot {
  width: .65rem;
  height: .65rem;
  margin-top: .35rem;
  border-radius: 999px;
  background: var(--blue);
}
.portal-notification-item.warn .portal-notification-dot { background: var(--amber); }
.portal-notification-item.danger .portal-notification-dot { background: var(--danger); }
.portal-notification-item span { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.portal-notification-item strong { display: block; margin-top: .05rem; color: var(--text); }
.portal-notification-item p { margin: .18rem 0 0; color: var(--muted); overflow-wrap: anywhere; }
.portal-notification-item time { color: var(--muted); font-size: .84rem; white-space: nowrap; }
.portal-metrics { margin-bottom: 1rem; }
.profile-list { margin: 0; display: grid; }
.profile-list div { display: grid; grid-template-columns: minmax(9rem, 13rem) minmax(0, 1fr); gap: 1rem; padding: .72rem 0; border-bottom: 1px solid var(--line-soft); }
.profile-list div:first-child { padding-top: 0; }
.profile-list div:last-child { border-bottom: 0; padding-bottom: 0; }
.profile-list dt { color: #344054; font-weight: 600; }
.profile-list dd { margin: 0; overflow-wrap: anywhere; }
.muted-value { color: var(--muted); }
.small-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel.narrow { max-width: 46rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .small-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 17rem;
    transform: translateX(-100%); transition: transform .22s ease; z-index: 20;
    box-shadow: var(--shadow-lg);
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 16, 24, .45); z-index: 15; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; min-height: 2.5rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; font-size: 1.2rem; box-shadow: var(--shadow-sm); }
  .topbar { align-items: center; }
  .topbar h1 { font-size: 1.25rem; }
}
@media (max-width: 760px) {
  .main { padding: 1rem; }
  .dashboard-grid, .record-form, .small-grid { grid-template-columns: 1fr; }
  .panel-head, .topbar { flex-wrap: wrap; }
  .tenant-switcher select { min-width: 9rem; }
  .search { width: 100%; }
  th, td { padding: .58rem .6rem; }
  .portal-hero { align-items: flex-start; flex-direction: column; }
  .portal-hero-actions { margin-left: 0; flex-wrap: wrap; }
  .portal-notification-item { grid-template-columns: auto minmax(0, 1fr); }
  .portal-notification-item time { grid-column: 2; white-space: normal; }
  .profile-list div { grid-template-columns: 1fr; gap: .18rem; }
}
@media print {
  body { background: #fff; }
  .sidebar, .topbar form, .menu-btn, .actions, .btn, .search { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel, .metric { box-shadow: none; break-inside: avoid; }
  thead th { position: static; }
}

/* ---------- Professional refinement ---------- */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #101828;
  --muted: #667085;
  --line: #d9e1ec;
  --line-soft: #edf1f6;
  --primary: #0e6f6a;
  --primary-strong: #0b5c59;
  --primary-soft: #e7f4f2;
  --blue: #1f5fbf;
  --amber: #b76e00;
  --danger: #b42318;
  --green: #15803d;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 6px 18px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 45px rgba(16, 24, 40, .14);
  --radius: .5rem;
  --radius-sm: .375rem;
}

body { background: var(--bg); }

.sidebar {
  background: #182230;
  border-right: 1px solid #101828;
  box-shadow: 8px 0 24px rgba(16, 24, 40, .08);
}

.brand-mark {
  background: #f6c542;
  border-radius: .5rem;
  box-shadow: none;
}

.nav a { border-radius: .375rem; }
.nav a.active {
  background: #233247;
  border-color: rgba(255, 255, 255, .08);
  box-shadow: inset 3px 0 0 0 #49c5b6;
}

.main { padding: 1.25rem 1.35rem 2.5rem; }
.topbar {
  background: rgba(245, 247, 250, .92);
  margin: -1.25rem -1.35rem 1.15rem;
  padding: 1rem 1.35rem;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 1.35rem; letter-spacing: 0; }

.panel,
.metric,
.login-card,
.install-note {
  border-radius: .5rem;
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 1rem; }
.panel h2 { letter-spacing: 0; }
.dashboard-grid { gap: .85rem; }
.metric { padding: .95rem 1rem; }
.metric strong { font-size: 1.45rem; letter-spacing: 0; }

.table-wrap { border-radius: .5rem; background: #fff; }
table { font-size: .9rem; }
th, td { padding: .66rem .75rem; }
thead th { background: #f8fafc; color: #475467; letter-spacing: 0; }
tbody tr:nth-child(2n) td { background: #fcfdff; }
tbody tr:hover td { background: #f0f7f6; }

.record-form { gap: .9rem 1rem; }
.field span { color: #344054; font-size: .88rem; }
.field input,
.field select,
.field textarea,
.login-card input,
.tenant-switcher select {
  border-color: #cfd8e6;
  border-radius: .375rem;
  min-height: 2.55rem;
  background-color: #fff;
}
.field textarea { min-height: 7rem; }
.field input:hover,
.field select:hover,
.field textarea:hover { border-color: #aebdcc; }

.btn {
  border-radius: .375rem;
  box-shadow: none;
  font-size: .92rem;
}
.btn:hover { box-shadow: var(--shadow-sm); }
.btn.primary {
  background: #0e6f6a;
  border-color: #0b5c59;
}
.btn.primary:hover { background: #0b5c59; }
.btn.ghost:hover { background: #eef2f6; }

.alert,
.pill { border-radius: .375rem; }
.pill { padding: .18rem .5rem; }

@media (max-width: 780px) {
  .main { padding: 1rem; }
  .topbar { margin: -1rem -1rem 1rem; padding: .85rem 1rem; }
}
/* ---------- Report utilities ---------- */
.muted { color: var(--muted); font-size: .86rem; }
tfoot th, tfoot td {
  background: #f8fafc;
  border-top: 1px solid var(--line);
  color: #344054;
}
/* ---------- Duplicate and print reports ---------- */
.duplicate-group {
  border: 1px solid var(--line-soft);
  border-radius: .5rem;
  padding: .85rem;
  margin-top: .85rem;
  background: #fcfdff;
}
.duplicate-group h3 { margin: 0 0 .7rem; }
.no-print { }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .sidebar,
  .topbar,
  .no-print,
  .row-actions,
  .nav,
  .actions,
  .form-actions { display: none !important; }
  .app-shell { display: block; min-height: auto; }
  .main { padding: 0; }
  .panel,
  .metric,
  .table-wrap {
    box-shadow: none !important;
    border-color: #d0d5dd;
  }
  .panel { page-break-inside: avoid; }
  .print-report { border: 0; padding: 0; }
  thead th { position: static; }
  a { text-decoration: none; }
}
