:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --border: #dfe5ee;
    --primary: #116466;
    --primary-dark: #0a4d4e;
    --primary-soft: #e4f4f2;
    --success: #16794d;
    --success-soft: #e6f5ed;
    --warning: #8a5a00;
    --warning-soft: #fff4d6;
    --danger: #b42318;
    --danger-soft: #feeceb;
    --info: #175cd3;
    --info-soft: #eaf2ff;
    --shadow: 0 10px 30px rgba(25, 42, 70, .08);
    --radius: 14px;
    --sidebar: 248px;
    --focus: 0 0 0 3px rgba(17, 100, 102, .22);
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, .btn { touch-action: manipulation; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.skip-link { position: fixed; top: -60px; left: 12px; z-index: 999; padding: 10px 14px; background: #fff; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar);
    padding: 20px 14px;
    overflow-y: auto;
    background: #102f38;
    color: #e7f4f2;
    transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; color: #fff; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: #69d0c5; color: #102f38; font-size: 18px; }
.brand small { display: block; color: #a8cbc7; font-weight: 500; font-size: 11px; }
.nav-label { margin: 14px 10px 7px; color: #8cb3af; font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.nav-list { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px; color: #d6e9e7; font-weight: 600; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-link.is-active { background: #e7f7f4; color: #0b5254; }
.nav-icon { width: 22px; text-align: center; font-size: 16px; }
.sidebar-footer { margin-top: 24px; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.12); color: #a8cbc7; font-size: 12px; }

.app-main { min-height: 100vh; margin-left: var(--sidebar); }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; min-height: 64px; padding: 10px clamp(16px, 3vw, 34px); background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); }
.topbar-left, .topbar-actions, .user-menu { display: flex; align-items: center; gap: 10px; }
.topbar-title { margin: 0; font-size: 18px; }
.user-copy { text-align: right; }
.user-copy strong { display: block; font-size: 13px; }
.user-copy span { display: block; color: var(--muted); font-size: 11px; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; }
.nav-toggle { display: none; border: 0; background: transparent; color: var(--text); font-size: 24px; cursor: pointer; }

.safety-banner { position: sticky; top: 64px; z-index: 25; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 7px 18px; background: var(--warning-soft); border-bottom: 1px solid #edcf7a; color: #6d4700; font-size: 13px; font-weight: 700; text-align: center; }
.safety-banner.is-live { background: var(--danger-soft); border-color: #f3b2ac; color: var(--danger); }
.content { width: min(1440px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 34px); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-title { margin: 0 0 4px; font-size: clamp(23px, 3vw, 31px); line-height: 1.18; }
.page-description { max-width: 760px; margin: 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.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)); }
.span-2 { grid-column: span 2; }
.card { min-width: 0; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title { margin: 0; font-size: 17px; }
.card-subtitle { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.stat-card { position: relative; overflow: hidden; }
.stat-label { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-value { display: block; margin-top: 6px; font-size: 31px; font-weight: 800; line-height: 1; }
.stat-note { display: block; margin-top: 9px; color: var(--muted); font-size: 12px; }
.stat-accent { position: absolute; top: 0; right: 0; width: 6px; height: 100%; background: var(--primary); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 14px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 750; line-height: 1.2; text-decoration: none; transition: .15s ease; }
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-soft); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-sm { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

.badge { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 4px 8px; border-radius: 999px; background: #eef2f6; color: #465367; font-size: 11px; font-weight: 800; line-height: 1.2; white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.priority-high { color: var(--danger); font-weight: 800; }

.alert { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.alert-success { background: var(--success-soft); border-color: #a9dec3; color: #105c3a; }
.alert-error { background: var(--danger-soft); border-color: #f3b2ac; color: #8f1b13; }
.alert-warning { background: var(--warning-soft); border-color: #edcf7a; color: #6d4700; }
.alert-info { background: var(--info-soft); border-color: #b5cef6; color: #174eaa; }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 18px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-grow { flex: 1 1 260px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label, .field-label { color: #344054; font-size: 13px; font-weight: 750; }
.field-hint { color: var(--muted); font-size: 12px; }
.required::after { content: " *"; color: var(--danger); }
.input, .select, .textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cfd7e3; border-radius: 9px; background: #fff; color: var(--text); }
.textarea { min-height: 120px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: var(--focus); outline: none; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; }
.checkbox { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.checkbox input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--primary); }
.form-section { margin-bottom: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.form-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 13px 15px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { background: var(--surface-soft); color: #475467; font-size: 11px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfcfd; }
.table-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.entity-name { display: block; color: var(--text); font-weight: 800; }
.entity-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.empty-state { padding: 44px 20px; text-align: center; }
.empty-state-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 13px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 23px; }
.empty-state h2, .empty-state h3 { margin: 0 0 6px; }
.empty-state p { max-width: 480px; margin: 0 auto 16px; color: var(--muted); }

.list { margin: 0; padding: 0; list-style: none; }
.list-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:first-child { padding-top: 0; }
.list-item:last-child { padding-bottom: 0; border-bottom: 0; }
.timeline { margin: 0; padding: 0 0 0 22px; list-style: none; border-left: 2px solid var(--border); }
.timeline-item { position: relative; padding: 0 0 20px 15px; }
.timeline-item::before { content: ""; position: absolute; top: 5px; left: -29px; width: 10px; height: 10px; border: 3px solid #fff; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-time { display: block; color: var(--muted); font-size: 11px; }
.detail-list { display: grid; grid-template-columns: minmax(130px, .5fr) 1.5fr; gap: 9px 16px; margin: 0; }
.detail-list dt { color: var(--muted); font-size: 13px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; font-weight: 650; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; padding-bottom: 1px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 13px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 750; white-space: nowrap; }
.tab:hover { color: var(--primary); text-decoration: none; }
.tab.is-active { border-color: var(--primary); color: var(--primary); }
.message-preview { padding: 18px; border: 1px solid var(--border); border-radius: 10px; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-layout { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(420px, 1.25fr); gap: 18px; }
.approval-item { display: block; padding: 13px; border: 1px solid var(--border); border-radius: 9px; color: var(--text); }
.approval-item + .approval-item { margin-top: 8px; }
.approval-item:hover, .approval-item.is-selected { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }

.progress { height: 8px; overflow: hidden; border-radius: 99px; background: #e8edf3; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.metric-row { display: flex; align-items: center; gap: 12px; }
.metric-row .progress { flex: 1; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pagination-links { display: flex; gap: 5px; }
.code-box { padding: 12px; overflow-x: auto; border-radius: 8px; background: #172033; color: #edf4ff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dff4f0, transparent 42%), #f6f8fb; }
.auth-card { width: min(440px, 100%); padding: 30px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: 0 24px 70px rgba(17, 57, 67, .14); }
.auth-brand { justify-content: center; color: var(--text); padding-bottom: 24px; }
.auth-brand:hover { color: var(--text); }
.auth-card h1 { margin: 0 0 7px; text-align: center; }
.auth-intro { margin: 0 0 24px; color: var(--muted); text-align: center; }
.auth-card .btn-primary { width: 100%; margin-top: 8px; }
.auth-safety { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; text-align: center; }

.mobile-overlay { display: none; }
@media (max-width: 1080px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .approval-layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .nav-toggle { display: inline-flex; }
    .mobile-overlay { position: fixed; inset: 0; z-index: 35; display: block; border: 0; background: rgba(13, 25, 35, .48); opacity: 0; pointer-events: none; transition: opacity .2s; }
    .mobile-overlay.is-visible { opacity: 1; pointer-events: auto; }
    .user-copy { display: none; }
    .safety-banner { top: 64px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}
@media (max-width: 620px) {
    body { font-size: 14px; }
    .content { padding: 18px 14px 28px; }
    .page-header { display: grid; }
    .page-actions, .page-actions .btn { width: 100%; }
    .grid-4 { grid-template-columns: 1fr; }
    .filters > .field, .filters > .btn { width: 100%; flex-basis: 100%; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .table-responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
    .table-responsive tr { padding: 13px; border-bottom: 1px solid var(--border); }
    .table-responsive tr:last-child { border-bottom: 0; }
    .table-responsive td { display: grid; grid-template-columns: minmax(90px, .45fr) 1fr; gap: 10px; padding: 5px 0; border: 0; }
    .table-responsive td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
    .table-actions { justify-content: flex-start; }
    .detail-list { grid-template-columns: 1fr; gap: 3px; }
    .detail-list dd { margin-bottom: 10px; }
    .pagination { align-items: stretch; flex-direction: column; }
    .pagination-links .btn { flex: 1; }
    .auth-card { padding: 24px 19px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
