:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #142033;
    --muted: #667085;
    --border: #d8dee9;
    --primary: #2563eb;
    --primary-text: #ffffff;
    --danger: #dc2626;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.10);
    --radius: 18px;
}

html[data-theme="dark"] {
    --bg: #0b1120;
    --panel: #121a2b;
    --text: #f8fafc;
    --muted: #9ca3af;
    --border: #253047;
    --primary: #60a5fa;
    --primary-text: #07111f;
    --danger: #f87171;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.brand {
    font-weight: 800;
    letter-spacing: 0.02em;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.nav a,
.theme-toggle,
.btn {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.nav a:hover,
.btn:hover,
.theme-toggle:hover { border-color: var(--primary); }

.theme-toggle {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
}

.page {
    width: min(1180px, calc(100% - 24px));
    margin: 0 auto;
    padding: 24px 0 48px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.login-card { width: min(430px, 100%); }

.section-head {
    text-align: center;
    margin: 16px 0 22px;
}

h1, h2 { margin: 0 0 12px; }

.muted { color: var(--muted); margin-top: 0; }

.form-grid {
    display: grid;
    gap: 10px;
    width: fit-content;
    max-width: 100%;
    min-width: min(100%, 390px);
    margin: 0 auto 22px;
}

label {
    font-weight: 800;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

textarea { min-height: 110px; resize: vertical; }

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input { width: auto; }

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 42px;
}

.btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
}

.btn.small { padding: 8px 12px; min-height: 36px; }

.stat-grid,
.action-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 22px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card span { font-size: clamp(2rem, 8vw, 3.5rem); font-weight: 900; }
.stat-card small { color: var(--muted); font-weight: 800; }
.stat-card.danger span { color: var(--danger); }

.table-card,
.asset-list { margin-top: 18px; }
.table-scroll { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 11px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th { color: var(--muted); font-size: 0.9rem; }

.filter-bar {
    display: flex;
    justify-content: center;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.asset-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: 14px;
}

.asset-card h2 { text-align: center; }

.detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 9px 14px;
}

.detail-grid span { color: var(--muted); font-weight: 800; }
.detail-grid strong { overflow-wrap: anywhere; }

.flash-wrap { display: grid; gap: 10px; margin-bottom: 16px; }
.flash {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--panel);
    font-weight: 700;
}
.flash.success { border-color: #22c55e; }
.flash.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 760px) {
    .topbar {
        grid-template-columns: 1fr auto;
    }
    .brand { grid-column: 1 / 2; }
    .theme-toggle { grid-column: 2 / 3; grid-row: 1; justify-self: end; }
    .nav {
        grid-column: 1 / -1;
        justify-content: center;
    }
    .nav a { padding: 9px 11px; font-size: 0.92rem; }
    .stat-grid,
    .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-bar { align-items: stretch; }
    .filter-bar > * { width: 100%; }
}

@media (max-width: 430px) {
    .page { width: min(100% - 16px, 1180px); padding-top: 16px; }
    .stat-grid,
    .action-grid { grid-template-columns: 1fr; }
    .card { padding: 14px; }
    .detail-grid { grid-template-columns: 1fr; }
}

.hidden {
    display: none !important;
}

.quick-add-card {
    grid-column: 1 / -1;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--panel) 86%, var(--accent));
}

.quick-add-card h3 {
    margin: 0 0 12px;
    text-align: center;
}

.quick-add-message {
    min-height: 1.4em;
    margin-bottom: 10px;
    color: var(--muted);
    text-align: center;
    font-weight: 700;
}

.compact-grid {
    margin-top: 0;
}

.btn.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

/* --- master page pattern patch --- */

.form-grid{
    width:100%;
    max-width:760px;
    min-width:unset;
    margin:0 auto 18px;
    gap:18px;
}

.form-section{
    width:100%;
}

.form-section h3{
    margin:0 0 10px;
}

.form-section label{
    display:block;
    margin:10px 0 6px;
}

.form-actions{
    text-align:center;
    margin-top:10px;
}

/* stacked record cards */
.record-grid{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(320px,1fr));
    gap:16px;
    margin-top:12px;
}

.record-card{
    background:var(--bg);
    border:1px solid var(--border);
    border-radius:16px;
    padding:16px;
}

.record-header{
    margin-bottom:10px;
    padding-bottom:8px;
    border-bottom:1px solid var(--border);
}

.record-header h3{
    margin:0;
    text-align:center;
}

.record-section{
    margin-top:14px;
}

.record-section h4{
    margin:0 0 6px;
}

.record-section p{
    margin:4px 0;
}

.record-section a{
    color:var(--primary);
    font-weight:700;
}

/* mobile tighten */
@media (max-width:760px){

    .form-grid{
        max-width:100%;
        gap:14px;
    }

    .record-grid{
        grid-template-columns:1fr;
    }

}

/* --- customer form compact desktop layout --- */

@media (min-width: 761px){

    .form-grid{
        max-width: 980px;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .form-section:first-child,
    .form-section:last-of-type,
    .form-actions{
        grid-column: 1 / -1;
    }

    .form-section:first-child{
        max-width: 760px;
        margin: 0 auto;
        width: 100%;
    }

    .form-actions{
        text-align: center;
    }

}

/* --- desktop density tighten --- */

@media (min-width: 761px){

    .page{
        width:min(1380px, calc(100% - 32px));
        padding:18px 0 32px;
    }

    .page-header,
    .section-head{
        margin:8px 0 14px;
    }

    .page-header h1,
    .section-head h1{
        margin-bottom:6px;
    }

    .card{
        padding:16px 18px;
    }

    h1{
        font-size:1.8rem;
    }

    h2{
        font-size:1.35rem;
        margin-bottom:10px;
    }

    h3{
        font-size:1.05rem;
        margin-bottom:8px;
    }

    label{
        font-size:0.9rem;
    }

    input,
    select,
    textarea{
        padding:9px 12px;
        border-radius:12px;
        min-height:38px;
    }

    textarea{
        min-height:82px;
    }

    .form-grid{
        max-width:1120px;
        gap:12px 18px;
        margin-bottom:12px;
    }

    .form-section label{
        margin:6px 0 4px;
    }

    .form-section h3{
        margin:0 0 6px;
    }

    .form-actions{
        margin-top:4px;
    }

    .btn{
        min-height:38px;
        padding:9px 14px;
    }

    .record-grid{
        gap:12px;
    }

    .record-card{
        padding:12px;
    }

    .record-section{
        margin-top:10px;
    }
}

/* --- final density trim --- */

@media (min-width:761px){

    .page{
        width:min(1460px, calc(100% - 24px));
    }

    .card{
        padding:14px 16px;
    }

    .form-grid{
        max-width:1180px;
        gap:10px 14px;
    }

    input,
    select,
    textarea{
        min-height:34px;
        padding:7px 10px;
        font-size:0.95rem;
    }

    textarea{
        min-height:72px;
    }

    label{
        margin-bottom:2px;
        font-size:0.88rem;
    }

    h1{
        font-size:1.65rem;
    }

    h2{
        font-size:1.25rem;
    }

    h3{
        font-size:1rem;
    }

    .btn{
        min-height:34px;
        padding:7px 12px;
        font-size:0.92rem;
    }

}