:root {
    --blue: #0B3D91;
    --blue-dark: #072A66;
    --blue-mid: #1A56B8;
    --blue-soft: #E8EEF8;
    --red: #D61F2A;
    --red-dark: #B0101A;
    --bg: #F3F5F9;
    --card: #ffffff;
    --text: #1C2331;
    --muted: #5C6B80;
    --line: #E2E8F0;
    --ok: #0F7B4A;
    --ok-bg: #E7F6EE;
    --warn: #9A6700;
    --warn-bg: #FFF4D6;
    --danger: #B42318;
    --danger-bg: #FEE4E2;
    --shadow: 0 10px 30px rgba(7, 42, 102, 0.08);
    --radius: 16px;
    --sidebar: 260px;
    font-family: "Segoe UI", "Avenir Next", Calibri, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { color: var(--text); background: var(--bg); min-height: 100vh; }

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--red); }

.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(214, 31, 42, 0.12), transparent 32%),
        linear-gradient(160deg, #061a44 0%, var(--blue) 48%, #0a2f73 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.auth-wrap, .gate-wrap {
    width: min(980px, 100%);
}

.gate-card, .login-card {
    background: #fff;
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
    overflow: hidden;
}

.gate-head, .login-head {
    padding: 28px 32px 12px;
    text-align: center;
}

.gate-head img, .login-head img {
    width: min(280px, 80%);
    height: auto;
}

.gate-head p, .login-head p {
    color: var(--muted);
    margin: 8px 0 0;
}

.gate-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    padding: 12px 28px 32px;
}

.portal-btn {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 28px 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--blue-soft);
    color: var(--text);
    transition: transform .15s ease, box-shadow .15s ease;
}

.portal-btn.sales { background: #FDECEC; }
.portal-btn strong { font-size: 1.2rem; color: var(--blue-dark); }
.portal-btn.sales strong { color: var(--red-dark); }
.portal-btn span { color: var(--muted); font-size: .92rem; }
.portal-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: var(--text); }

.login-grid {
    display: grid;
    grid-template-columns: 1.05fr .95fr;
}

.login-visual {
    background: linear-gradient(180deg, var(--blue-dark), var(--blue));
    color: #fff;
    padding: 40px 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 420px;
}

.login-visual h2 { margin: 0 0 8px; font-size: 1.8rem; }
.login-visual p { margin: 0; color: rgba(255,255,255,.8); line-height: 1.5; }
.login-form { padding: 36px 32px; }
.login-form h1 { margin: 0 0 6px; }
.login-form .hint { color: var(--muted); margin: 0 0 22px; }
.back-link { display: inline-block; margin-top: 14px; font-size: .9rem; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar);
    background: linear-gradient(180deg, var(--blue-dark) 0%, #0a2a6b 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 22px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand img { width: 92px; background: #fff; border-radius: 10px; padding: 6px; }
.brand strong { display: block; }
.brand span { color: rgba(255,255,255,.7); font-size: .8rem; }
.side-nav { display: flex; flex-direction: column; padding: 16px 12px; gap: 6px; flex: 1; }
.side-nav a {
    color: rgba(255,255,255,.82);
    padding: 11px 14px;
    border-radius: 10px;
    font-weight: 600;
}
.side-nav a:hover, .side-nav a.active {
    background: rgba(255,255,255,.12);
    color: #fff;
}
.side-user {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}
.side-user span { display: block; color: rgba(255,255,255,.65); font-size: .8rem; }
.side-user a { color: #ffd7da; font-size: .85rem; }
.app-main { flex: 1; min-width: 0; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 22px 28px 0;
}
.topbar h1 { margin: 0; font-size: 1.45rem; }
.topbar-meta { color: var(--muted); }
.page { padding: 18px 28px 40px; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 1.05rem; }
.toolbar {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.muted { color: var(--muted); }
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { display: block; font-size: 1.6rem; margin-top: 6px; color: var(--blue-dark); }

label { display: block; font-weight: 650; margin: 0 0 6px; font-size: .9rem; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { min-height: 88px; resize: vertical; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 16px;
}
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.help { color: var(--muted); font-size: .82rem; margin-top: 4px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    background: var(--blue);
    color: #fff;
}
.btn:hover { background: var(--blue-mid); color: #fff; }
.btn-red { background: var(--red); }
.btn-red:hover { background: var(--red-dark); color: #fff; }
.btn-outline {
    background: #fff;
    color: var(--blue);
    border: 1px solid var(--line);
}
.btn-outline:hover { background: var(--blue-soft); color: var(--blue-dark); }
.btn-sm { padding: 7px 10px; font-size: .85rem; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.table-wrap { overflow: auto; }

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-no { background: var(--danger-bg); color: var(--danger); }

.flash {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-weight: 600;
}
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

.price-box {
    background: var(--blue-soft);
    border-radius: 14px;
    padding: 14px;
}
.price-box.red { background: #FDECEC; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.radio-row label { font-weight: 600; display: flex; gap: 6px; align-items: center; margin: 0; }
.radio-row input { width: auto; }

.search-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.search-form input { width: auto; min-width: 180px; flex: 1 1 200px; }
.search-form select { width: auto; min-width: 140px; flex: 0 1 150px; }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 28px 8px;
}

.form-grid > * { margin: 0; }
.quote-builder td input, .quote-builder td select { min-width: 90px; }
.table-wrap.quote-builder { overflow: visible; }
.quote-builder .js-product-search { min-width: 220px; }
.split-field {
    display: flex;
    gap: 6px;
    align-items: center;
}
.split-field select { width: 64px; min-width: 64px; flex: 0 0 64px; }
.split-field input { min-width: 70px; }
.bill-totals .total-discount {
    align-items: center;
    gap: 10px;
}
.bill-totals .total-discount .split-field { width: 170px; }
.bill-totals .help { text-align: right; max-width: 360px; margin-left: auto; }
.grand-edit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 800;
}
.grand-edit input {
    width: 140px;
    font-weight: 800;
    text-align: right;
}
.totals {
    width: min(360px, 100%);
    margin-left: auto;
}
.totals div {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
}
.totals .grand { font-size: 1.15rem; font-weight: 800; color: var(--blue-dark); border-top: 2px solid var(--blue); margin-top: 6px; padding-top: 10px; }

.suggest {
    position: relative;
}
.suggest-list {
    position: absolute;
    left: 0; right: 0; top: 100%;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    max-height: 240px;
    overflow: auto;
    z-index: 40;
    display: none;
    box-shadow: var(--shadow);
}
.suggest-list button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: #fff;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
}
.suggest-list button:hover { background: var(--blue-soft); }
.suggest-list button:disabled { cursor: not-allowed; }
.stock-note.error { color: var(--danger); font-weight: 650; }
.keywords { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    background: var(--blue-soft);
    color: var(--blue-dark);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: .75rem;
    font-weight: 700;
}

@media (max-width: 1180px) {
    .form-grid, .form-grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
    .login-grid, .gate-grid, .grid-stats { grid-template-columns: 1fr; }
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; }
    .side-nav { flex-direction: row; overflow: auto; }
    .login-visual { min-height: 180px; }
}
