:root {
    --navy: #10243e;
    --navy-deep: #0a182b;
    --navy-soft: #1c3656;
    --red: #e64545;
    --red-dark: #c93636;
    --blue: #2b6fe8;
    --ink: #162033;
    --muted: #69768a;
    --line: #dfe5ed;
    --surface: #ffffff;
    --background: #f3f6f9;
    --success: #147a54;
    --warning: #8a5d12;
    --shadow: 0 12px 30px rgba(13, 31, 53, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--background); font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; color: #eef5ff; background: linear-gradient(180deg, var(--navy-deep), var(--navy)); display: flex; flex-direction: column; padding: 25px 18px 18px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; color: #fff; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 22px; letter-spacing: .05em; }
.brand small { margin-top: 4px; color: #9db0c9; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
.brand-mark { width: 40px; height: 40px; position: relative; display: grid; place-items: center; border-radius: 11px; background: var(--red); box-shadow: 0 8px 20px rgba(230, 69, 69, .28); }
.brand-mark i { position: absolute; width: 5px; background: #fff; border-radius: 4px; transform-origin: 50% 27px; }
.brand-mark i:nth-child(1) { height: 14px; transform: translateY(-7px) rotate(-38deg); }
.brand-mark i:nth-child(2) { height: 18px; transform: translateY(-8px); }
.brand-mark i:nth-child(3) { height: 14px; transform: translateY(-7px) rotate(38deg); }
.main-nav { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; }
.nav-label { margin: 19px 12px 7px; color: #6f86a2; font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.main-nav a { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 0 13px; border-radius: 9px; color: #bccce0; font-weight: 650; transition: .15s ease; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.main-nav a.active { color: #fff; background: var(--navy-soft); box-shadow: inset 3px 0 var(--red); }
.nav-icon { width: 22px; color: #8fa8c5; font-size: 21px; text-align: center; }
.sidebar-user { margin-top: auto; display: grid; grid-template-columns: 37px 1fr auto; align-items: center; gap: 10px; padding: 16px 8px 2px; border-top: 1px solid rgba(255,255,255,.09); }
.sidebar-user > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; }
.sidebar-user strong { overflow: hidden; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-user small { color: #8097b3; font-size: 11px; }
.avatar { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 10px; color: #fff; background: #274667; font-weight: 800; }
.logout-button { border: 0; padding: 7px; color: #8299b4; background: transparent; cursor: pointer; font-size: 19px; }
.logout-button:hover { color: #fff; }

.main-area { min-width: 0; }
.topbar { min-height: 96px; display: flex; align-items: center; gap: 18px; padding: 20px clamp(24px, 4vw, 54px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.9); }
.topbar h1 { margin: 1px 0 0; font-size: clamp(23px, 3vw, 30px); line-height: 1.15; }
.eyebrow { margin: 0; color: var(--red); font-size: 10px; font-weight: 850; letter-spacing: .15em; text-transform: uppercase; }
.site-link { margin-left: auto; padding: 9px 13px; border: 1px solid var(--line); border-radius: 8px; color: #546276; background: #fff; font-size: 13px; font-weight: 700; }
.site-link:hover { border-color: #aeb9c8; color: var(--ink); }
.menu-button { display: none; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.page-content { width: min(1380px, 100%); margin: 0 auto; padding: 32px clamp(24px, 4vw, 54px) 60px; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border: 1px solid transparent; border-radius: 8px; font-weight: 750; cursor: pointer; transition: .15s ease; }
.button-primary { color: #fff; background: var(--red); box-shadow: 0 7px 16px rgba(230,69,69,.17); }
.button-primary:hover { background: var(--red-dark); transform: translateY(-1px); }
.button-secondary { color: var(--ink); border-color: var(--line); background: #fff; }
.button-secondary:hover { border-color: #acb8c8; }
.button-light { color: var(--navy); background: #fff; }
.button-light:hover { box-shadow: 0 8px 18px rgba(0,0,0,.12); transform: translateY(-1px); }
.button-wide { width: 100%; }
.text-link { color: var(--muted); font-weight: 700; }
.text-link:hover { color: var(--red); }

.alert { margin-bottom: 18px; padding: 12px 15px; border: 1px solid; border-radius: 9px; font-weight: 650; }
.alert-success { color: #0c6846; border-color: #a8dec9; background: #eaf8f2; }
.alert-warning { color: #80540d; border-color: #ecd19d; background: #fff8e8; }
.alert-error { color: #a52c2c; border-color: #f0b4b4; background: #fff0f0; }

.welcome-panel { min-height: 194px; position: relative; overflow: hidden; display: flex; align-items: center; gap: 32px; justify-content: space-between; padding: clamp(27px, 4vw, 42px); border-radius: var(--radius); color: #fff; background: linear-gradient(120deg, var(--navy) 0%, #18385c 68%, #24486e 100%); box-shadow: var(--shadow); }
.welcome-panel::after { content: ""; position: absolute; right: 9%; top: -95px; width: 250px; height: 250px; border: 34px solid rgba(255,255,255,.035); border-radius: 50%; }
.welcome-panel > * { position: relative; z-index: 1; }
.welcome-panel h2 { max-width: 650px; margin: 9px 0 8px; font-size: clamp(24px, 3.2vw, 36px); line-height: 1.17; letter-spacing: -.02em; }
.welcome-panel p:last-child { max-width: 700px; margin: 0; color: #afc1d7; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 20px 0; }
.metric-card { min-height: 140px; display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 18px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 6px 20px rgba(13,31,53,.04); }
.metric-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 12px; color: var(--navy); background: #eaf0f6; font-size: 25px; font-weight: 850; }
.metric-icon-red { color: var(--red); background: #fff0f0; }
.metric-card div { display: flex; flex-direction: column; }
.metric-card p { margin: 0; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.metric-card strong { margin: 3px 0; font-size: 28px; }
.metric-card small { color: #8995a6; }
.metric-card > a { color: var(--red); font-weight: 800; }
.metric-card-muted { background: #f8fafc; box-shadow: none; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .7fr); gap: 20px; }
.dashboard-log { max-width: 100%; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 7px 23px rgba(13,31,53,.045); }
.panel-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 23px 25px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 3px 0 0; font-size: 20px; }
.panel-header span { color: var(--muted); font-size: 13px; }
.activity-list { list-style: none; margin: 0; padding: 4px 25px 10px; }
.activity-list li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 13px; min-height: 65px; border-bottom: 1px solid #edf0f4; }
.activity-list li:last-child { border-bottom: 0; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.activity-list div { color: var(--muted); }
.activity-list strong { color: var(--ink); }
.activity-list small { display: block; color: #99a2af; }
.activity-list time { color: #8793a3; font-size: 12px; }
.help-panel { padding: 29px; background: linear-gradient(150deg, #fff, #f4f7fb); }
.help-panel h2 { margin: 8px 0 10px; font-size: 22px; }
.help-panel > p:not(.eyebrow) { margin: 0 0 22px; color: var(--muted); }
.empty-state { min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-state strong { margin-bottom: 5px; color: var(--ink); font-size: 17px; }

.page-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.search-form { display: flex; align-items: center; gap: 9px; flex: 1; }
.search-box { width: min(450px, 100%); position: relative; }
.search-box span { position: absolute; left: 13px; top: 7px; color: #8a97a8; font-size: 22px; }
.search-box input { width: 100%; height: 42px; padding: 0 14px 0 40px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
.search-box input:focus { border-color: #739ae0; box-shadow: 0 0 0 3px rgba(43,111,232,.1); }
.table-heading > span { padding: 5px 9px; border-radius: 6px; background: #f3f6f9; font-weight: 700; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 22px; border-bottom: 1px solid #e9edf2; text-align: left; vertical-align: middle; }
th { color: #768397; background: #f9fafc; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; }
th a:hover { color: var(--red); }
tbody tr:hover { background: #fbfcfe; }
tbody tr:last-child td { border-bottom: 0; }
.capcode-number { color: var(--navy); font: 750 14px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .045em; }
.capcode-number:hover { color: var(--red); }
.type-badge { display: inline-flex; min-width: 55px; justify-content: center; padding: 4px 8px; border-radius: 99px; color: #415067; background: #eaf0f6; font-size: 10px; font-weight: 850; }
.type-brw { color: #ad2b2b; background: #ffeaea; }
.type-ambu { color: #765600; background: #fff3c7; }
.type-pol { color: #2456a7; background: #e6efff; }
.type-mmt { color: #70408d; background: #f3e9fa; }
.type-knrm { color: #087361; background: #dff5f0; }
.actions-column { width: 190px; }
.row-actions { display: flex; align-items: center; gap: 13px; }
.row-actions a, .row-actions button { color: #52647b; font-size: 12px; font-weight: 750; }
.row-actions a:hover { color: var(--blue); }
.row-actions form { margin: 0; }
.row-actions button { border: 0; padding: 0; background: none; cursor: pointer; }
.row-actions button:hover { color: var(--red); }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 17px 22px; border-top: 1px solid var(--line); }
.pagination a { color: var(--navy); font-weight: 750; }
.pagination a:hover { color: var(--red); }
.pagination span { color: #adb6c2; }
.pagination strong { color: var(--muted); font-size: 12px; }

.breadcrumb { display: flex; gap: 9px; align-items: center; margin: 0 0 17px; color: var(--muted); font-size: 13px; }
.breadcrumb a:hover { color: var(--red); }
.breadcrumb strong { color: var(--ink); }
.form-panel { max-width: 820px; }
.record-form { display: grid; gap: 23px; padding: 27px; }
.record-form label, .stack-form label { display: flex; flex-direction: column; gap: 7px; color: #354256; font-size: 13px; font-weight: 750; }
.record-form input, .record-form select, .stack-form input { width: 100%; min-height: 45px; padding: 10px 12px; border: 1px solid #ced6e1; border-radius: 8px; color: var(--ink); background: #fff; outline: none; }
.record-form input:focus, .record-form select:focus, .stack-form input:focus { border-color: #739ae0; box-shadow: 0 0 0 3px rgba(43,111,232,.1); }
.record-form label > small { color: #8995a5; font-weight: 450; }
.mono-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; letter-spacing: .08em; }
.field-error { color: #b92d2d !important; font-size: 12px; font-weight: 700 !important; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 5px; }

.auth-body { display: grid; place-items: center; padding: 30px 20px; color: var(--ink); background: radial-gradient(circle at 70% 20%, #1e4167 0, transparent 28%), linear-gradient(135deg, #081729, #102c4b); }
.auth-shell { width: min(520px, 100%); }
.auth-shell:has(.auth-card-wide) { width: min(720px, 100%); }
.auth-brand { width: max-content; margin: 0 auto 24px; padding: 0; }
.auth-card { padding: 34px; border: 1px solid rgba(255,255,255,.25); border-radius: 18px; background: #fff; box-shadow: 0 25px 60px rgba(0,0,0,.28); }
.auth-heading { margin-bottom: 25px; text-align: center; }
.auth-heading > p { display: inline; margin: 0; color: var(--red); font-size: 10px; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.auth-heading h1 { margin: 10px 0 5px; font-size: 28px; }
.auth-heading > span:last-child { color: var(--muted); }
.status-dot { width: 7px; height: 7px; display: inline-block; margin-right: 6px; border-radius: 50%; background: #35b87f; box-shadow: 0 0 0 4px #e5f7ef; }
.stack-form { display: grid; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.auth-footer { margin: 19px 0 0; color: #8fa3ba; text-align: center; font-size: 11px; letter-spacing: .06em; }
.auth-text-link { text-align: center; font-size: 13px; }

@media (max-width: 950px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; width: 250px; transform: translateX(-102%); box-shadow: 14px 0 35px rgba(0,0,0,.22); transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }
    .menu-button { display: grid; place-items: center; }
    .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .topbar { min-height: 80px; padding: 16px 18px; }
    .topbar .eyebrow, .site-link { display: none; }
    .topbar h1 { font-size: 22px; }
    .page-content { padding: 20px 15px 40px; }
    .welcome-panel { align-items: flex-start; flex-direction: column; }
    .metric-grid { grid-template-columns: 1fr; }
    .metric-card { grid-template-columns: 50px 1fr; }
    .metric-card > a { grid-column: 2; }
    .page-actions { align-items: stretch; flex-direction: column; }
    .search-form { flex-wrap: wrap; }
    .search-box { flex: 1 1 100%; }
    .page-actions > .button { width: 100%; }
    th, td { padding: 13px 15px; }
    .actions-column, .row-actions { min-width: 170px; }
    .form-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 26px 20px; }
}

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