:root {
  --ink: #14221c;
  --muted: #617069;
  --deep: #173128;
  --deep-2: #214437;
  --paper: #f7f7f2;
  --panel: #ffffff;
  --line: #dfe5df;
  --soft: #edf2ee;
  --accent: #b08b45;
  --danger: #a53b32;
  --warn: #9d6b17;
  --ok: #2f6b4f;
  --shadow: 0 18px 50px rgba(20, 34, 28, .09);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(176, 139, 69, .32); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: radial-gradient(circle at 50% 20%, #315b49 0, var(--deep) 42%, #0d1d17 100%); }
.login-card { width: min(100%, 470px); padding: 36px; border-radius: 26px; background: rgba(255,255,255,.98); box-shadow: 0 30px 80px rgba(0,0,0,.27); }
.brand-mark { width: 62px; height: 62px; border-radius: 18px; display: grid; place-items: center; background: var(--deep); color: #fff; font-weight: 900; letter-spacing: .08em; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: .82rem; flex: 0 0 auto; }
.brand-logo-cpanel { object-fit: cover; }
.eyebrow { margin: 0 0 6px; text-transform: uppercase; letter-spacing: .13em; font-weight: 800; font-size: .72rem; color: #7b6a42; }
.login-card h1 { margin: 4px 0 10px; font-size: clamp(1.8rem, 6vw, 2.5rem); line-height: 1.05; }
.login-copy { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.login-card label, .filter-grid label, .single-search label, .case-update label { display: grid; gap: 7px; font-size: .82rem; font-weight: 750; color: #3f4e47; }
input, select, textarea { width: 100%; border: 1px solid #ccd6cf; border-radius: 11px; padding: 11px 12px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
.primary { border: 0; border-radius: 11px; padding: 12px 17px; background: var(--deep); color: #fff; font-weight: 800; cursor: pointer; }
.login-card .primary { width: 100%; margin-top: 12px; }
.primary:hover { background: var(--deep-2); }
.primary:disabled { opacity: .55; cursor: wait; }
.status { margin: 10px 0 0; color: var(--muted); font-size: .86rem; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }
.public-link { display: inline-block; margin-top: 18px; color: var(--deep); font-weight: 750; }

.cpanel-app { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 16px; background: linear-gradient(180deg, #163027 0%, #10251d 100%); color: #fff; display: flex; flex-direction: column; z-index: 20; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 4px 7px 22px; }
.sidebar-brand strong { display: block; font-size: 1.12rem; }
.sidebar-brand span { display: block; margin-top: 2px; color: #adc1b7; font-size: .73rem; }
.side-nav { display: grid; gap: 5px; }
.nav-item { appearance: none; border: 0; border-radius: 10px; padding: 11px 12px; background: transparent; color: #c8d8d0; text-align: left; font-weight: 700; cursor: pointer; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-footer { margin-top: auto; display: grid; gap: 7px; padding: 16px 7px 2px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer a, .signout { color: #c8d8d0; font-size: .84rem; }
.signout { border: 0; background: transparent; padding: 6px 0; text-align: left; cursor: pointer; }
.sidebar-footer a:hover, .signout:hover { color: #fff; }

.workspace { min-width: 0; }
.topbar { min-height: 86px; padding: 17px clamp(18px, 4vw, 42px); display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); background: rgba(247,247,242,.92); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.topbar .eyebrow { margin-bottom: 2px; }
.role-badge { margin-left: auto; padding: 7px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; min-width: 92px; text-align: right; }
.role-badge span { display: block; text-transform: capitalize; font-weight: 850; }
.role-badge small { color: var(--muted); font-size: .67rem; }
.mobile-nav { display: none; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px; }
.global-status { margin: 14px clamp(18px, 4vw, 42px) 0; border-radius: 12px; padding: 11px 14px; border: 1px solid #ead4d1; background: #fff1ef; color: var(--danger); }
.main-content { padding: 26px clamp(18px, 4vw, 42px) 50px; }
.view { animation: viewIn .18s ease-out; }
@keyframes viewIn { from { opacity: .35; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card { min-height: 108px; padding: 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 7px 24px rgba(20,34,28,.035); display: flex; flex-direction: column; justify-content: center; }
.metric-card span { font-size: clamp(1.7rem, 3vw, 2.35rem); font-weight: 900; line-height: 1; }
.metric-card small { margin-top: 8px; color: var(--muted); font-weight: 650; }
.metric-card.urgent { border-color: #ead2cf; background: #fff8f7; }
.metric-card.urgent span { color: var(--danger); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, .7fr); gap: 18px; }
.panel { padding: 22px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); min-width: 0; }
.panel.wide { grid-row: span 2; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading.wrap { flex-wrap: wrap; }
.panel-heading h2, .module-placeholder h2 { margin: 0; font-size: 1.25rem; }
.panel-copy { color: var(--muted); line-height: 1.55; }
.text-button { border: 0; background: transparent; padding: 5px 0; color: var(--deep); font-weight: 800; cursor: pointer; text-decoration: none; white-space: nowrap; }
.count-badge, .restricted-badge { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border-radius: 999px; background: var(--soft); color: #506159; font-size: .76rem; font-weight: 800; }
.restricted-badge { background: #fff0ee; color: var(--danger); }

.request-list { display: grid; gap: 9px; }
.request-card { width: 100%; border: 1px solid var(--line); border-radius: 13px; background: #fff; padding: 13px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; text-align: left; cursor: pointer; }
.request-card:hover { border-color: #bccac1; background: #fbfcfa; }
.request-title { font-weight: 850; overflow-wrap: anywhere; }
.request-meta, .request-services { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.request-services { color: #4f6158; }
.urgency-chip, .status-chip, .priority-chip { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: .69rem; font-weight: 850; text-transform: capitalize; background: var(--soft); color: #4d5e56; }
.urgency-chip.urgent { background: #ffe7e4; color: var(--danger); }
.urgency-chip.soon { background: #fff1d7; color: var(--warn); }
.status-chip.security_review { background: #ffe7e4; color: var(--danger); }
.priority-chip.high { background: #ffe7e4; color: var(--danger); }
.rank-list { display: grid; gap: 9px; }
.rank-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding-bottom: 9px; border-bottom: 1px solid #edf0ed; }
.rank-row:last-child { border-bottom: 0; padding-bottom: 0; }
.rank-row strong { font-size: .9rem; text-transform: capitalize; }
.rank-row span { color: var(--muted); font-weight: 800; }
.empty-state { margin: 18px 0; color: var(--muted); }

.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.filter-grid.three { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
.single-search { max-width: 440px; margin: 0 0 18px; }
.data-table { overflow-x: auto; }
.data-table table { width: 100%; border-collapse: collapse; min-width: 840px; }
.data-table th { text-align: left; padding: 10px 11px; font-size: .71rem; text-transform: uppercase; letter-spacing: .06em; color: #68776f; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 12px 11px; border-bottom: 1px solid #edf0ed; vertical-align: top; font-size: .86rem; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f8faf8; }
.cell-title { font-weight: 850; }
.cell-muted { color: var(--muted); font-size: .75rem; margin-top: 3px; }
.service-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.service-tag { padding: 3px 6px; border-radius: 6px; background: var(--soft); color: #4e6057; font-size: .67rem; font-weight: 750; text-transform: capitalize; }
.contact-stop { color: var(--danger); font-weight: 800; }
.contact-ok { color: var(--ok); font-weight: 800; }

.map-panel, .resource-panel { padding-bottom: 14px; }
#needs-map-frame, #resource-directory-frame { width: 100%; border: 1px solid var(--line); border-radius: 15px; background: #edf2ee; }
#needs-map-frame { height: min(72vh, 760px); min-height: 520px; }
#resource-directory-frame { height: min(78vh, 860px); min-height: 620px; }
.restricted-panel { border-color: #ead2cf; }
.module-placeholder { min-height: 360px; display: flex; flex-direction: column; justify-content: center; }
.module-placeholder > p { max-width: 720px; color: var(--muted); line-height: 1.6; }
.module-grid { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); gap: 12px; margin-top: 18px; }
.module-grid div { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fbfcfa; }
.module-grid strong { display: block; color: var(--deep); }
.module-grid span { display: block; margin-top: 6px; color: var(--muted); font-size: .84rem; }

.detail-dialog { width: min(900px, calc(100vw - 30px)); max-height: min(88vh, 900px); padding: 0; border: 0; border-radius: 20px; box-shadow: 0 30px 100px rgba(0,0,0,.28); }
.detail-dialog::backdrop { background: rgba(8, 19, 15, .58); backdrop-filter: blur(3px); }
.dialog-shell { margin: 0; }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 19px 22px; border-bottom: 1px solid var(--line); background: #fff; }
.dialog-header h2 { margin: 0; }
.dialog-close { border: 0; background: var(--soft); width: 38px; height: 38px; border-radius: 50%; font-size: 1.5rem; cursor: pointer; }
.detail-body { padding: 22px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.detail-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.detail-item small { display: block; color: var(--muted); font-size: .69rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 800; }
.detail-item strong, .detail-item span { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.detail-section { margin-top: 20px; }
.detail-section h3, .case-update h3 { margin: 0 0 10px; font-size: 1rem; }
.detail-section p { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.58; background: #f9faf8; border: 1px solid var(--line); border-radius: 11px; padding: 13px; }
.event-list { display: grid; gap: 7px; }
.event-row { padding: 10px 12px; border-left: 3px solid #cbd6cf; background: #f9faf8; border-radius: 0 9px 9px 0; }
.event-row strong { display: block; text-transform: capitalize; font-size: .82rem; }
.event-row small { color: var(--muted); }
.case-update { border-top: 1px solid var(--line); padding: 20px 22px 24px; background: #fbfcfa; }
.dialog-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .panel.wide { grid-column: 1 / -1; grid-row: auto; }
}

@media (max-width: 820px) {
  .cpanel-app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(82vw, 280px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 14px 0 50px rgba(0,0,0,.25); }
  body.nav-open .sidebar { transform: translateX(0); }
  .mobile-nav { display: inline-flex; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid, .filter-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .module-grid { grid-template-columns: 1fr; }
  #needs-map-frame { min-height: 480px; }
  #resource-directory-frame { min-height: 580px; }
}

@media (max-width: 520px) {
  .login-card { padding: 28px 20px; border-radius: 20px; }
  .topbar { padding: 14px 16px; }
  .main-content { padding: 18px 12px 36px; }
  .global-status { margin-left: 12px; margin-right: 12px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 92px; padding: 13px; }
  .panel { padding: 16px; border-radius: 15px; }
  .filter-grid, .filter-grid.three { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-dialog { width: calc(100vw - 14px); max-height: 94vh; border-radius: 15px; }
  .dialog-header, .detail-body, .case-update { padding-left: 15px; padding-right: 15px; }
  .role-badge { min-width: 0; padding: 6px 8px; }
  .role-badge small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
