:root {
    --navy: #17324d;
    --navy-deep: #0e2238;
    --blue: #0066cc;
    --blue-dark: #004d99;
    --text: #1a1a1a;
    --muted: #5c6f82;
    --line: #d5dde6;
    --paper: #ffffff;
    --canvas: #eef2f6;
    --success: #008758;
    --success-bg: #e6f4ee;
    --gold: #c5a46e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--canvas);
    color: var(--text);
    font-family: "Titillium Web", "Segoe UI", sans-serif;
    line-height: 1.45;
}

.tricolor {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    height: 4px;
    background: linear-gradient(90deg, #009246 33.33%, #fff 33.33% 66.66%, #ce2b37 66.66%);
}

.masthead {
    background: var(--navy);
    color: #fff;
    border-bottom: 3px solid var(--gold);
}

.masthead-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.emblem {
    width: 48px;
    height: 48px;
    border: 1px solid var(--gold);
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--gold);
}

.brand-kicker {
    margin: 0 0 2px;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #c5d0db;
}

.masthead h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.masthead-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 13px;
    color: #c5d0db;
    text-align: right;
}

.app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 20px;
}

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 24px;
}

.panel-head {
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.panel-head h2,
h3 {
    margin: 0 0 6px;
    color: var(--navy);
    font-size: 20px;
    font-weight: 700;
}

h3 { margin-top: 28px; }

.panel-head p {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}

.color-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.color-swatch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    text-align: left;
}

.color-swatch .chip {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border: 1px solid rgba(23, 50, 77, 0.35);
}

.color-swatch.active {
    background: var(--navy);
    color: #fff;
}

.color-swatch.active .chip {
    border-color: #fff;
}

.field-block {
    margin-bottom: 18px;
}

.field-block label,
.debug label {
    display: block;
    margin-bottom: 8px;
    color: var(--navy);
    font-weight: 600;
    font-size: 14px;
}

.price-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

button {
    border: 1px solid var(--navy);
    background: #fff;
    color: var(--navy);
    border-radius: 0;
    padding: 12px 16px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    background: #f4f7fa;
}

.quick-price {
    flex: 1;
}

.quick-price.active {
    background: var(--navy);
    color: #fff;
}

#basePrice,
#cameraSelect {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 0;
    padding: 12px 14px;
    font-family: inherit;
    color: var(--navy);
    background: #f8fafc;
}

#basePrice {
    font-size: 22px;
}

#cameraSelect {
    font-size: 16px;
}

#basePrice:focus,
#cameraSelect:focus {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

.camera-wrap {
    position: relative;
    overflow: hidden;
    background: #0b1220;
    aspect-ratio: 16/10;
    border: 1px solid var(--navy);
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.guide {
    position: absolute;
    left: 24%;
    right: 24%;
    top: 6%;
    bottom: 6%;
    border: 1px dashed rgba(255, 255, 255, 0.8);
    display: grid;
    place-items: center;
    padding: 12px;
    text-align: center;
    color: rgba(255, 255, 255, 0.88);
    font-size: 13px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    pointer-events: none;
}

.camera-wrap.card-ok .guide {
    border-style: solid;
    border-color: #3dd68c;
    color: #3dd68c;
}

.camera-wrap.card-missing .guide {
    border-color: #ffb4b4;
    color: #ffd4d4;
}

.status {
    margin: 12px 0 0;
    min-height: 22px;
    color: var(--muted);
    font-size: 14px;
}

.controls {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

#scanBtn {
    flex: 1;
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#scanBtn:hover {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
}

.secondary {
    background: #fff;
}

.ledger {
    margin: 0;
}

.ledger-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.ledger-row dt {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.ledger-row dd {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    color: var(--navy);
}

.ledger-row.total {
    margin-top: 6px;
    padding: 16px;
    background: var(--navy);
    border-bottom: 0;
}

.ledger-row.total dt,
.ledger-row.total dd {
    color: #fff;
}

.ledger-row.total dd {
    font-size: 36px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.cell {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: #f8fafc;
    font-size: 14px;
}

.cell.marked {
    border-color: var(--success);
    background: var(--success-bg);
}

.cell small {
    color: var(--muted);
}

.debug {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.debug-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.debug input {
    flex: 1;
}

#thresholdValue {
    min-width: 36px;
    color: var(--navy);
    font-weight: 600;
}

.site-footer {
    max-width: 1180px;
    margin: 0 auto 28px;
    padding: 0 24px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .masthead-inner { flex-direction: column; align-items: flex-start; }
    .masthead-meta { align-items: flex-start; text-align: left; }
    .controls { flex-direction: column; }
    .color-row { grid-template-columns: repeat(2, 1fr); }
}
