:root {
    --navy: #071d36;
    --navy-2: #0d2d4f;
    --blue: #1678c2;
    --blue-soft: #eaf4fb;
    --gold: #c9a35c;
    --ink: #172536;
    --muted: #6c7885;
    --line: #dce4eb;
    --surface: #ffffff;
    --background: #f4f7f9;
    --success: #12734d;
    --warning: #9a6300;
    --danger: #a63a3a;
    --radius: 14px;
    --shadow: 0 10px 32px rgba(7, 29, 54, .07);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--background);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--background); }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.75rem, 4vw, 2.5rem); line-height: 1.1; color: var(--navy); letter-spacing: -.035em; }
h2 { margin-bottom: 8px; font-size: 1.2rem; color: var(--navy); }
.muted { color: var(--muted); }
.eyebrow { display: block; margin-bottom: 9px; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
.brand { display: flex; align-items: center; gap: 11px; color: white; font-weight: 800; letter-spacing: .16em; }
.brand small { display: block; margin-top: 3px; font-size: .55rem; font-weight: 500; letter-spacing: .18em; opacity: .7; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid rgba(255,255,255,.4); font-family: Georgia, serif; font-size: 1.65rem; font-weight: 400; }
.brand-dark { color: var(--navy); }
.brand-dark .brand-mark { border-color: var(--navy); }

.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 29px 22px; display: flex; flex-direction: column; background: var(--navy); color: white; z-index: 20; }
.sidebar nav { display: grid; gap: 5px; margin-top: 55px; }
.sidebar nav a { padding: 12px 14px; border-radius: 8px; color: #c8d5e1; font-size: .94rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: white; }
.sidebar-user { margin-top: auto; padding: 16px 13px 0; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-user small, .sidebar-user strong { display: block; }
.sidebar-user small { margin-bottom: 4px; color: #8fa5b9; font-size: .7rem; text-transform: uppercase; }
.sidebar-user strong { font-size: .88rem; }
.link-button { margin-top: 8px; padding: 0; border: 0; background: none; color: #9fc9e8; cursor: pointer; }
.app-main { min-width: 0; }
.topbar { height: 66px; padding: 0 32px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(10px); }
.topbar > span { font-weight: 700; color: var(--navy); }
.topbar .button { margin-left: auto; }
.menu-button { display: none; border: 0; background: transparent; font-size: 1.4rem; color: var(--navy); }
.content { width: min(1320px, 100%); margin: 0 auto; padding: 38px 42px 64px; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.page-heading p { margin-bottom: 0; }
.heading-actions { display: flex; gap: 10px; }
.button { display: inline-flex; min-height: 42px; padding: 9px 16px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--navy); font-weight: 700; cursor: pointer; }
.button:hover { border-color: #afbdc9; }
.button-primary { border-color: var(--blue); background: var(--blue); color: white; }
.button-primary:hover { border-color: #0d609d; background: #0d609d; }
.button-danger { border-color: #e4bcbc; background: #fff4f4; color: var(--danger); }
.button-danger:hover { border-color: var(--danger); }
.button-small { min-height: 36px; padding: 6px 12px; font-size: .86rem; }
.button-quiet { background: transparent; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card, .panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stat-card { padding: 21px; border-top: 3px solid var(--blue); }
.stat-card span, .stat-card small, table small { display: block; color: var(--muted); }
.stat-card span { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat-card strong { display: block; margin: 12px 0 7px; color: var(--navy); font-size: 1.9rem; }
.stat-card small { font-size: .78rem; }
.stat-card.accent { border-top-color: var(--gold); }
.panel { margin-bottom: 22px; padding: 24px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-heading h2, .section-heading .eyebrow { margin-bottom: 0; }
.section-heading .eyebrow { margin-bottom: 6px; }

.table-wrap { overflow-x: auto; margin: 0 -24px -24px; }
table { width: 100%; border-collapse: collapse; font-size: .89rem; }
th { padding: 12px 18px; background: #f7f9fb; color: var(--muted); text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 15px 18px; border-top: 1px solid var(--line); vertical-align: middle; }
td strong { color: var(--navy); }
td small { margin-top: 4px; font-size: .76rem; }
.asset-code { font-weight: 800; white-space: nowrap; }
.badge { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.badge-success { color: var(--success); background: #e8f6f0; }
.badge-warning { color: var(--warning); background: #fff5dd; }
.badge-danger { color: var(--danger); background: #fcecec; }
.badge-neutral { color: var(--navy); background: #edf1f5; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

.filter-panel { padding: 18px 20px; }
.filters { display: grid; grid-template-columns: minmax(230px, 2fr) repeat(3, minmax(130px, 1fr)) auto auto; gap: 12px; align-items: end; }
label { display: grid; gap: 7px; color: #3e4b58; font-size: .82rem; font-weight: 700; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #cbd6df; border-radius: 7px; outline: none; background: white; color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(22,120,194,.12); }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid h2 { grid-column: 1 / -1; margin-top: 12px; }
.span-2 { grid-column: 1 / -1; }
.form-section { padding: 25px; }
.check-label { display: flex; align-items: center; align-self: end; min-height: 42px; }
.check-label input { width: auto; }
.form-actions { position: sticky; bottom: 15px; padding: 13px; display: flex; justify-content: flex-end; gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.inline-actions { position: static; margin-top: 22px; padding: 0; border: 0; box-shadow: none; }
.user-form { max-width: 850px; }
.role-guide { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 22px; }
.role-guide article { padding: 18px; border: 1px solid var(--line); border-radius: 11px; background: white; }
.role-guide strong, .role-guide span { display: block; }
.role-guide strong { margin-bottom: 5px; color: var(--navy); }
.role-guide span { color: var(--muted); font-size: .82rem; }
.row-actions { display: flex; gap: 7px; align-items: center; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
.detail-status { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .78rem; }
.details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.details div { padding: 16px 16px 16px 0; border-bottom: 1px solid var(--line); }
.details dt { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.details dd { margin: 6px 0 0; color: var(--navy); overflow-wrap: anywhere; }
.asset-photo { margin: 20px 0 4px; }
.asset-photo img { display: block; width: 100%; max-height: 460px; border-radius: 10px; object-fit: contain; background: #eef2f5; }
.asset-photo figcaption { margin-top: 7px; color: var(--muted); font-size: .75rem; text-align: center; }
.photo-upload-field { padding: 16px; border: 1px dashed #b8c7d3; border-radius: 10px; background: #f8fafc; }
.photo-upload-field small { color: var(--muted); font-weight: 500; }
.photo-preview { display: block; width: min(320px, 100%); max-height: 220px; border-radius: 8px; object-fit: contain; background: #e9eef2; }
.qr-card { position: sticky; top: 88px; display: grid; justify-items: center; text-align: center; }
.qr-card .eyebrow { justify-self: start; }
.qr-card h2 { justify-self: start; }
.qr-box { min-height: 212px; margin: 10px 0 14px; padding: 8px; background: white; }
.qr-box img, .qr-box canvas { max-width: 100%; height: auto !important; }
.qr-card small { margin: 4px 0 18px; color: var(--muted); }
.back-link { display: block; margin-bottom: 20px; font-size: .83rem; font-weight: 700; }
.history { margin-top: 0; }
.timeline-item { position: relative; display: grid; grid-template-columns: 18px 1fr; gap: 14px; padding-bottom: 22px; }
.timeline-item > span { width: 12px; height: 12px; margin-top: 4px; border: 3px solid var(--blue); border-radius: 50%; background: white; }
.timeline-item:not(:last-child)::before { content: ''; position: absolute; top: 15px; bottom: 0; left: 5px; width: 2px; background: var(--line); }
.timeline-item small { display: block; margin-top: 4px; color: var(--muted); }
.timeline-item p { margin: 7px 0 0; }

.scan-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 22px; align-items: start; }
.scanner-card { display: flex; flex-wrap: wrap; gap: 10px; }
.scanner-placeholder, #scanner-video { width: 100%; min-height: 390px; border-radius: 10px; background: var(--navy); color: white; object-fit: cover; }
.scanner-placeholder { display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center; }
.scanner-placeholder span { font-size: 3rem; color: var(--gold); }
.scanner-placeholder small { color: #9eb0c0; }
.manual-scan form { display: grid; gap: 14px; }

.alert { margin-bottom: 18px; padding: 13px 16px; border-radius: 8px; font-size: .9rem; }
.alert-success { border: 1px solid #b7dfce; background: #ebf8f2; color: var(--success); }
.alert-error { border: 1px solid #efc4c4; background: #fff0f0; color: var(--danger); }
.login-page { display: grid; grid-template-columns: minmax(360px, .8fr) 1.2fr; min-height: 100vh; }
.login-visual { padding: 45px 55px; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(145deg, rgba(7,29,54,.96), rgba(10,61,96,.94)), radial-gradient(circle at top right, #1f85c8, transparent 50%); color: white; }
.login-visual h1 { color: white; font-size: clamp(2.8rem, 6vw, 5.4rem); }
.login-visual p { max-width: 510px; color: #bacbd9; font-size: 1.05rem; line-height: 1.6; }
.login-form-wrap { display: grid; place-items: center; padding: 30px; background: white; }
.login-form { width: min(390px, 100%); display: grid; gap: 18px; }
.login-form .button { width: 100%; margin-top: 5px; }
.installer-body { padding: 38px 18px; background: linear-gradient(135deg, #edf4f8, white); }
.installer-card { width: min(790px, 100%); margin: 0 auto; padding: 38px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: var(--shadow); }
.installer-card > .brand { margin-bottom: 35px; }
.installer-note { margin: 20px 0 0; color: var(--muted); font-size: .83rem; }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 40px rgba(0,0,0,.2); }
    .sidebar.open { transform: translateX(0); }
    .menu-button { display: block; }
    .topbar { padding: 0 18px; }
    .content { padding: 28px 17px 55px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .page-heading .button { width: 100%; }
    .heading-actions { width: 100%; flex-direction: column; }
    .stats-grid, .detail-grid, .scan-layout, .form-grid, .role-guide { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .filters { grid-template-columns: 1fr; }
    .details { grid-template-columns: 1fr; }
    .detail-status { align-items: flex-start; flex-direction: column; }
    .qr-card { position: static; }
    .login-page { grid-template-columns: 1fr; }
    .login-visual { min-height: 42vh; padding: 30px; }
    .login-visual h1 { font-size: 2.75rem; }
    .login-visual > small { display: none; }
    .login-form-wrap { padding: 42px 22px; }
    .installer-card { padding: 28px 20px; }
}

@media print {
    .sidebar, .topbar, .page-heading .button, .history, .form-actions { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    .detail-grid { grid-template-columns: 1fr 260px; }
    .panel { box-shadow: none; break-inside: avoid; }
}
