:root {
  --bg: #f4f5ef;
  --surface: #ffffff;
  --surface-2: #eef1e8;
  --ink: #1b211c;
  --muted: #657067;
  --line: #dce1d8;
  --brand: #314f3d;
  --brand-2: #d9b56d;
  --danger: #a43f3f;
  --warning: #9a6615;
  --success: #26724b;
  --info: #326c8a;
  --radius: 16px;
  --shadow: 0 16px 40px rgba(31, 48, 38, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { background: #14251b; color: #eff5ef; padding: 22px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-bottom: 24px; }
.sidebar-logo img { width: 168px; height: auto; }
.nav-group { margin: 22px 0; }
.nav-label { color: #94a89a; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; padding: 0 12px 8px; }
.nav-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 10px; color: #dfe9e1; text-decoration: none; margin: 3px 0; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.1); color: white; }
.nav-count { min-width: 22px; padding: 1px 6px; border-radius: 999px; background: rgba(255,255,255,.12); font-size: 12px; text-align: center; }
.sidebar-footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.12); }
.user-name { font-weight: 700; }
.user-role { color: #a9bbb0; font-size: 12px; text-transform: capitalize; }

.main-wrap { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; height: 64px; background: rgba(244,245,239,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.topbar-title { font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { padding: 28px; max-width: 1600px; margin: 0 auto; }
.page-header { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.page-header h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.03em; }
.page-header p { margin: 5px 0 0; color: var(--muted); max-width: 760px; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; background: var(--brand); color: white; font-weight: 700; text-decoration: none; }
.button:hover { filter: brightness(.96); }
.button.secondary { background: white; color: var(--ink); border-color: var(--line); }
.button.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.button.danger { background: var(--danger); }
.button.small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.button.full { width: 100%; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: white; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(31,48,38,.025); }
.card-header { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 17px; }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--line); background: #fbfcf9; border-radius: 0 0 var(--radius) var(--radius); }

.metric { padding: 20px; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { font-size: 30px; font-weight: 850; letter-spacing: -.04em; margin-top: 6px; }
.metric-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.metric.good .metric-value { color: var(--success); }
.metric.warn .metric-value { color: var(--warning); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; background: #fafbf8; white-space: nowrap; }
tbody tr:hover { background: #fbfcf9; }
.table-link { font-weight: 750; text-decoration: none; }
.table-link:hover { text-decoration: underline; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 750; background: var(--surface-2); color: var(--ink); white-space: nowrap; }
.badge.green { background: #ddf3e5; color: #1e623f; }
.badge.red { background: #f6dddd; color: #883737; }
.badge.amber { background: #f6ead0; color: #83590d; }
.badge.blue { background: #dcecf4; color: #285e78; }
.badge.gray { background: #eceeea; color: #5f675f; }
.badge.purple { background: #e9e0f4; color: #65468a; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 730; font-size: 13px; }
.field small { color: var(--muted); }
input[type="text"], input[type="email"], input[type="tel"], input[type="url"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="password"], select, textarea, .input {
  width: 100%; border: 1px solid #cfd6ce; background: white; color: var(--ink); border-radius: 10px; padding: 10px 11px; outline: none; min-height: 42px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(49,79,61,.11); }
.checkbox-list { display: flex; flex-wrap: wrap; gap: 9px 15px; }
.checkbox-item { display: flex; gap: 7px; align-items: flex-start; font-weight: 500; }
.checkbox-item input { margin-top: 3px; }
.form-section { border-top: 1px solid var(--line); padding-top: 22px; margin-top: 22px; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-section h3 { margin: 0 0 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.flash { padding: 12px 15px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; }
.flash.success { background: #e0f3e6; border-color: #bddfc8; color: #1e623f; }
.flash.error { background: #f7e0e0; border-color: #e7bcbc; color: #873838; }
.flash.info { background: #e4f0f6; border-color: #c2dce8; color: #285e78; }

.filters { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: 2fr repeat(3, minmax(130px,1fr)) auto; gap: 10px; align-items: end; margin-bottom: 18px; }
.empty { padding: 42px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 5px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; }
.definition-list { display: grid; gap: 11px; }
.definition { display: grid; grid-template-columns: 145px 1fr; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.definition:last-child { border-bottom: 0; }
.definition dt { color: var(--muted); }
.definition dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }

.timeline { display: grid; gap: 14px; }
.timeline-item { display: grid; grid-template-columns: 12px 1fr; gap: 12px; }
.timeline-dot { width: 10px; height: 10px; background: var(--brand-2); border-radius: 50%; margin-top: 6px; box-shadow: 0 0 0 4px #f5ecd8; }
.timeline-content { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.timeline-meta { color: var(--muted); font-size: 12px; }

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 300px); gap: 14px; overflow-x: auto; padding-bottom: 16px; }
.kanban-column { background: #e9ede5; border: 1px solid var(--line); border-radius: 14px; min-height: 360px; }
.kanban-column-header { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; font-weight: 800; }
.kanban-list { min-height: 300px; padding: 0 9px 12px; }
.kanban-card { background: white; border: 1px solid var(--line); border-radius: 11px; padding: 12px; margin: 8px 0; box-shadow: 0 3px 8px rgba(31,48,38,.04); }
.kanban-card[draggable="true"] { cursor: grab; }
.kanban-card.dragging { opacity: .45; }
.kanban-column.drag-over { outline: 3px solid rgba(49,79,61,.2); }
.kanban-title { font-weight: 800; text-decoration: none; }
.kanban-meta { color: var(--muted); font-size: 12px; margin-top: 5px; }

.progress { height: 9px; background: #e4e8e2; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.checklist { display: grid; gap: 8px; }
.check-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.check-item:last-child { border-bottom: 0; }
.check-item.done .check-label { text-decoration: line-through; color: var(--muted); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { padding: 9px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 800; }

.chart { display: grid; gap: 10px; }
.chart-row { display: grid; grid-template-columns: 130px minmax(0,1fr) 50px; gap: 10px; align-items: center; }
.chart-bar { background: #e5e9e3; height: 18px; border-radius: 999px; overflow: hidden; }
.chart-bar span { height: 100%; display: block; background: var(--brand); }

.public-body { min-height: 100vh; padding: 30px 16px; background: linear-gradient(145deg, #edf1e8, #f8f4e9); }
.public-shell { max-width: 900px; margin: auto; }
.public-header { text-align: center; margin: 20px 0 24px; }
.public-header img { width: 230px; }
.public-card { background: white; border: 1px solid var(--line); border-radius: 22px; padding: clamp(22px, 5vw, 46px); box-shadow: var(--shadow); max-width: 900px; margin: 5vh auto; }
.public-card h1 { font-size: clamp(28px, 5vw, 46px); line-height: 1.1; letter-spacing: -.04em; margin-top: 0; }
.public-card h2 { margin-top: 28px; }
.public-note { background: #f8f1df; padding: 12px 14px; border-radius: 10px; color: #725413; }
.portal-status { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin: 18px 0; }
.portal-status .step { background: #f0f3ed; padding: 12px; border-radius: 10px; font-size: 12px; }
.portal-status .step.current { background: var(--brand); color: white; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #10251a, #35533f); }
.login-card { width: min(430px, 100%); background: white; padding: 34px; border-radius: 22px; box-shadow: 0 28px 70px rgba(0,0,0,.26); }
.login-card img { width: 230px; display: block; margin: 0 auto 26px; }
.login-card h1 { margin: 0 0 5px; }
.login-card p { color: var(--muted); margin-top: 0; }

.preview-frame { width: 100%; height: 700px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.code-box { background: #15241b; color: #dceadf; padding: 14px; border-radius: 10px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 265px; transform: translateX(-100%); transition: transform .2s ease; z-index: 50; }
  body.nav-open .sidebar { transform: translateX(0); }
  .topbar { padding: 0 15px; }
  .content { padding: 18px 14px 40px; }
  .page-header { flex-direction: column; }
  .grid-2, .grid-3, .grid-4, .form-grid, .portal-status { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .definition { grid-template-columns: 1fr; gap: 2px; }
  .desktop-only { display: none !important; }
}

@media print {
  .sidebar, .topbar, .actions, .button, .no-print { display: none !important; }
  .app-shell { display: block; }
  .content { max-width: none; padding: 0; }
  body { background: white; }
  .card { box-shadow: none; break-inside: avoid; }
}
