:root {
  --ink: #1f2733;
  --muted: #687383;
  --cream: #fffaf0;
  --paper: #ffffff;
  --saffron: #e88724;
  --saffron-dark: #bd5d13;
  --gold: #f5c84c;
  --blue: #315b7d;
  --green: #377762;
  --plum: #76536d;
  --line: #e8e1d5;
  --shadow: 0 18px 55px rgba(61, 48, 30, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #f7f3eb; }
button, input, select, textarea { font: inherit; }
a { color: var(--saffron-dark); text-decoration: none; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; color: #fff; background: linear-gradient(165deg, #293746, #1e2833 72%, #151d25); display: flex; flex-direction: column; }
.brand { color: #fff; display: flex; gap: 12px; align-items: center; font-weight: 750; letter-spacing: .01em; }
.brand small { display: block; margin-top: 2px; color: #b9c3cc; font-size: .7rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.brand-mark { width: 46px; height: 46px; display: inline-grid; place-items: center; flex: 0 0 auto; border-radius: 50% 50% 45% 55%; background: linear-gradient(145deg, var(--gold), var(--saffron)); color: #71320c; font-family: Georgia, serif; font-size: 1.35rem; box-shadow: 0 7px 20px rgba(232, 135, 36, .25); }
.sidebar nav { margin-top: 36px; display: grid; gap: 5px; overflow-y: auto; }
.nav-link { padding: 12px 14px; color: #d9e0e6; border-radius: 10px; font-weight: 620; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.sidebar-foot { margin-top: auto; padding: 18px 14px 0; border-top: 1px solid rgba(255,255,255,.13); display: grid; gap: 6px; font-size: .9rem; }
.link-button { padding: 0; border: 0; background: none; color: #f2bd7d; cursor: pointer; }
.main { min-width: 0; padding: 48px clamp(24px, 5vw, 72px) 72px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 34px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1.08; font-weight: 600; }
h2 { margin-bottom: 6px; font-family: Georgia, "Times New Roman", serif; font-weight: 600; }
.page-head p { margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 8px !important; color: var(--saffron-dark) !important; font-size: .76rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 28px; }
.metric { position: relative; overflow: hidden; min-height: 170px; padding: 24px; border-radius: 18px; color: #fff; box-shadow: var(--shadow); }
.metric::after { content: ""; position: absolute; right: -30px; bottom: -46px; width: 135px; height: 135px; border: 24px solid rgba(255,255,255,.12); border-radius: 50%; }
.metric span, .metric small { position: relative; z-index: 1; display: block; }
.metric span { font-weight: 750; }
.metric strong { position: relative; z-index: 1; display: block; margin: 15px 0 8px; font-family: Georgia, serif; font-size: 2.7rem; }
.metric small { color: rgba(255,255,255,.8); }
.metric.saffron { background: linear-gradient(145deg, #e99a37, #c86518); }
.metric.blue { background: linear-gradient(145deg, #527b99, #294e6c); }
.metric.green { background: linear-gradient(145deg, #58917c, #2d6956); }
.metric.plum { background: linear-gradient(145deg, #926f8a, #69465f); }
.metric-link { color: #fff; }
.metric-grid-wide { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.panel { margin-bottom: 28px; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: 0 10px 35px rgba(65, 48, 26, .06); }
.panel-head { padding: 24px 26px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.panel-head h2, .panel-head p { margin-bottom: 0; }
.panel-head p { color: var(--muted); font-size: .9rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 20px; border-bottom: 1px solid #eee9e0; text-align: left; vertical-align: middle; }
th { color: #7b7265; background: #fcfaf6; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffcf6; }
.empty { padding: 42px; color: var(--muted); text-align: center; }
.status, .source { display: inline-block; padding: 5px 9px; border-radius: 999px; background: #e9f4ef; color: #27624e; font-size: .75rem; font-weight: 750; text-transform: capitalize; }
.source-admin { background: #edf3f7; color: #315b7d; }
.source-local { background: #fff1dc; color: #9e5418; }
.callout { padding: 26px 30px; border-radius: 18px; background: linear-gradient(100deg, #fff2d4, #fffbf1); border: 1px solid #f0d69b; display: flex; gap: 20px; align-items: center; }
.callout h2, .callout p { margin-bottom: 4px; }
.callout p { color: #76664e; }
.callout-icon { font-size: 2.2rem; color: var(--saffron-dark); }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 44px; padding: 10px 18px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 750; }
.button-primary { background: linear-gradient(135deg, var(--saffron), #d7721e); color: #fff; box-shadow: 0 8px 18px rgba(215, 114, 30, .22); }
.button-secondary { border-color: #d9d1c4; background: #fff; color: var(--ink); }
.button-wide { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.guest-shell { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: radial-gradient(circle at 20% 15%, #ffe9b0 0, transparent 27%), radial-gradient(circle at 85% 85%, #dfe9e2 0, transparent 25%), #f9f4e9; }
.guest-shell .main { width: 100%; max-width: 480px; padding: 0; }
.login-card, .error-card { padding: clamp(28px, 6vw, 48px); border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.login-brand { text-align: center; }
.login-brand .brand-mark { margin: 0 auto 14px; }
.login-brand p { margin-bottom: 2px; color: var(--saffron-dark); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.login-brand h1 { font-size: 2.2rem; }
.muted { color: var(--muted); text-align: center; }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #544f47; font-size: .85rem; font-weight: 750; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #d9d1c4; border-radius: 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(232,135,36,.18); border-color: var(--saffron); }
.divider { margin: 24px 0; display: flex; align-items: center; gap: 12px; color: #918779; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.flash { margin-bottom: 22px; padding: 14px 18px; border-radius: 10px; }
.flash-success { background: #e5f4ec; color: #245f48; }
.flash-error { background: #fce8e5; color: #8a342c; }
dialog { width: min(620px, calc(100% - 32px)); border: 0; border-radius: 18px; padding: 28px; box-shadow: 0 30px 90px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(23,30,38,.55); backdrop-filter: blur(3px); }
.dialog-title { display: flex; justify-content: space-between; align-items: center; }
.dialog-title button { border: 0; background: none; font-size: 2rem; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.unit-name { display: flex; align-items: center; }
.tree-line { width: 22px; height: 1px; margin-right: 2px; border-top: 1px solid #d9cdbb; }
.unit-dot { width: 8px; height: 8px; margin-right: 9px; border-radius: 50%; background: var(--saffron); }
.record-count { color: var(--muted); }
.filter-bar { padding: 20px 24px; display: flex; align-items: end; gap: 12px; border-bottom: 1px solid var(--line); }
.filter-bar label { min-width: min(420px, 70vw); }
.muted-line { display: block; margin-top: 4px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.role-pill { display: inline-block; padding: 5px 9px; border-radius: 999px; background: #fff1dc; color: #9e5418; font-size: .78rem; font-weight: 800; }
.select2-container { width: 100% !important; color: var(--ink); }
.select2-container .select2-selection--single { min-height: 43px; border: 1px solid #d9d1c4; border-radius: 9px; background: #fff; }
.select2-container--default .select2-selection--single .select2-selection__rendered { min-height: 41px; padding: 7px 38px 7px 12px; color: var(--ink); line-height: 27px; }
.select2-container--default .select2-selection--single .select2-selection__arrow { min-height: 41px; right: 8px; }
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single { border-color: var(--saffron); outline: 3px solid rgba(232,135,36,.18); }
.select2-dropdown { border-color: #d9d1c4; border-radius: 12px; overflow: hidden; box-shadow: 0 18px 45px rgba(31,39,51,.16); }
.select2-search--dropdown { padding: 8px; border-bottom: 1px solid var(--line); }
.select2-container--default .select2-search--dropdown .select2-search__field { border: 1px solid #d9d1c4; border-radius: 8px; padding: 9px 10px; }
.select2-results__option { padding: 10px 12px; }
.select2-container--default .select2-results__option--highlighted[aria-selected] { background: #fff1dc; color: #944d15; }
.select2-container--default .select2-results__option[aria-selected=true] { background: #edf3f7; color: #315b7d; }
.select2-container--default .select2-selection--single .select2-selection__placeholder { color: var(--muted); }
.form-pad { padding: 24px 26px; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form input, .inline-form select { min-width: 130px; }
.check-row { display: flex; grid-template-columns: none; align-items: center; gap: 10px; }
.check-row input { width: auto; }
.notes { display: grid; gap: 14px; padding: 0 26px 26px; }
.note { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fcfaf6; }
.note p:last-child { margin-bottom: 0; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.summary-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; }
.summary-card span, .summary-card strong { display: block; }
.summary-card span { color: var(--muted); font-size: .82rem; }
.summary-card strong { margin-top: 7px; font-family: Georgia, serif; font-size: 2rem; }
.progress-badge { display: grid; place-items: center; width: 74px; height: 74px; border-radius: 50%; background: var(--green); color: #fff; font-weight: 800; }
code { color: #445465; white-space: normal; }
.error-card { text-align: center; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 18px 22px; flex-direction: row; align-items: center; gap: 18px; }
  .sidebar nav { margin: 0; display: flex; overflow-x: auto; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .main { padding: 28px 16px 50px; }
  .sidebar { align-items: flex-start; flex-wrap: wrap; }
  .sidebar nav { order: 3; width: 100%; }
  .brand small, .sidebar-foot span { display: none; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .filter-bar label { min-width: 0; }
}
