/* ══════════════════════════════════════════════
   카메라 환율 - style.css
   모바일 우선 · 라이트/다크 자동 · safe-area
   ══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #eef6fd;
    --surface:   #ffffff;
    --surface-2: #f4f9ff;
    --border:    #daeaf8;
    --text-1:    #18222f;
    --text-2:    #5a6d82;
    --text-3:    #8b9bab;
    --primary:   #1a8fe8;
    --primary-2: #1478cc;
    --primary-soft: #e3f1fd;
    --success:   #0f9e6b;
    --warn:      #b86e00;
    --warn-soft: #fff3dc;
    --danger:    #d93636;
    --danger-soft: #fde8e8;
    --shadow:    0 4px 24px rgba(60, 120, 190, 0.12);
    --overlay:   rgba(10, 20, 35, 0.45);
    --r-lg: 18px; --r-md: 12px; --r-sm: 9px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:        #0f1722;
        --surface:   #18222f;
        --surface-2: #1f2b3a;
        --border:    #2b3a4d;
        --text-1:    #e8eef5;
        --text-2:    #a5b4c4;
        --text-3:    #75869a;
        --primary:   #4aa8f0;
        --primary-2: #6cb9f4;
        --primary-soft: #183650;
        --success:   #3ccf98;
        --warn:      #f0b44c;
        --warn-soft: #3a2d14;
        --danger:    #ff6b6b;
        --danger-soft: #3d1c1f;
        --shadow:    0 4px 24px rgba(0, 0, 0, 0.35);
        --overlay:   rgba(0, 0, 0, 0.6);
    }
}

html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    background: var(--bg);
    color: var(--text-1);
    line-height: 1.5;
    font-size: 15px;
    min-height: 100vh;
    overflow-x: hidden;
}
body.locked { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-b)); }

/* ── Header ── */
.header {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 8px;
    padding: calc(10px + var(--safe-t)) 0 10px;
    background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-icon { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.title { font-size: 17px; font-weight: 700; white-space: nowrap; }
@media (max-width: 440px) { .title { display: none; } }
.rate-badge {
    margin-left: auto; min-width: 0; flex: 0 1 auto;
    padding: 5px 10px; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary);
    font-size: 12px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rate-badge.warn { background: var(--warn-soft); color: var(--warn); }
.header-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
    width: 36px; height: 36px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.lang-btn { font-size: 13px; font-weight: 700; }

/* ── Banner ── */
.banner {
    display: flex; flex-direction: column; gap: 8px;
    margin-bottom: 10px; padding: 12px 14px;
    background: var(--warn-soft); color: var(--warn);
    border-radius: var(--r-md); font-size: 13.5px;
}
.banner-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Tabs ── */
.tabs {
    display: grid; grid-template-columns: repeat(3, 1fr);
    background: var(--surface); border-radius: var(--r-md);
    padding: 4px; gap: 4px; box-shadow: var(--shadow);
}
.tab {
    padding: 9px 4px; border-radius: 9px;
    font-weight: 600; font-size: 14px; color: var(--text-2);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab.active { background: var(--primary); color: #fff; }
.tab-count {
    min-width: 20px; padding: 0 6px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: 11.5px; line-height: 20px;
}

.main { padding-top: 12px; }

/* ── Camera ── */
.camera {
    position: relative; overflow: hidden;
    height: min(58vh, 520px); min-height: 300px;
    border-radius: var(--r-lg);
    background: #0b1119;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide {
    position: absolute; left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 82%; height: 30%;
    border: 3px solid rgba(255, 255, 255, 0.95);
    border-radius: 14px;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.38);
    transition: width .2s, height .2s;
    pointer-events: none;
}
.camera[data-mode="cash"] .guide { width: 90%; height: 62%; }
.guide-hint {
    position: absolute; left: 0; right: 0; bottom: calc(100% + 8px);
    text-align: center; color: #fff; font-size: 13px; font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.camera.auto-armed .guide { border-color: #6fe3b4; }
.camera-cover {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: 24px; text-align: center;
    background: #0b1119; color: #d5dfea;
}
.camera-cover-text { font-size: 14px; max-width: 300px; }
.busy {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    background: rgba(5, 10, 18, 0.55); color: #fff; font-weight: 600;
}
.spinner {
    width: 22px; height: 22px; border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
    margin-top: 10px; padding: 10px 12px; border-radius: var(--r-sm);
    background: var(--warn-soft); color: var(--warn); font-size: 13.5px;
}
.notice-soft { background: var(--surface-2); color: var(--text-2); margin: 0 0 10px; }

.controls {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    padding: 16px 4px 8px;
}
.ctrl {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    color: var(--text-2); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.ctrl-icon {
    width: 46px; height: 46px; border-radius: 50%;
    background: var(--surface); box-shadow: var(--shadow);
    display: inline-flex; align-items: center; justify-content: center;
}
.ctrl-icon svg { width: 22px; height: 22px; }
.shutter {
    width: 74px; height: 74px; border-radius: 50%;
    background: var(--surface); box-shadow: var(--shadow);
    display: inline-flex; align-items: center; justify-content: center;
    border: 4px solid var(--primary);
}
.shutter span { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); transition: transform .1s; }
.shutter:active span { transform: scale(.9); }
.shutter:disabled { opacity: .45; cursor: default; }

.switch-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 14px; margin-top: 8px;
    background: var(--surface); border-radius: var(--r-md);
}
.switch-title { display: block; font-weight: 600; font-size: 14.5px; }
.switch-desc { display: block; font-size: 12.5px; color: var(--text-3); }
.switch {
    appearance: none; -webkit-appearance: none; flex: none;
    width: 46px; height: 28px; border-radius: 999px;
    background: var(--border); position: relative; cursor: pointer; transition: background .15s;
}
.switch::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }
.usage { margin-top: 8px; font-size: 12px; color: var(--text-3); text-align: center; }

/* ── Cards / Cart ── */
.card {
    background: var(--surface); border-radius: var(--r-lg);
    padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-title { font-size: 15px; font-weight: 700; }
.empty { color: var(--text-3); font-size: 13.5px; text-align: center; padding: 16px 4px; }

.totals-card .t-label { font-size: 13px; color: var(--text-2); }
.t-main { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; word-break: break-all; }
.t-sec { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; color: var(--text-2); font-size: 14px; }
.t-sub { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 13px; color: var(--text-2); }
.t-sub li { display: flex; justify-content: space-between; list-style: none; }
.t-excluded { margin-top: 8px; font-size: 12.5px; color: var(--warn); }

.cart-list { list-style: none; }
.cart-item {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
    padding: 12px 0; border-top: 1px solid var(--border);
}
.cart-item:first-child { border-top: none; }
.ci-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-orig { font-size: 12.5px; color: var(--text-3); }
.ci-conv { font-weight: 700; text-align: right; }
.ci-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 11px 16px; border-radius: var(--r-sm);
    background: var(--surface-2); color: var(--text-1);
    border: 1px solid var(--border); font-weight: 600; font-size: 14.5px; cursor: pointer;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.danger { color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Stepper ── */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.stepper button { width: 34px; height: 32px; font-size: 18px; color: var(--primary); }
.stepper button:disabled { color: var(--text-3); }
.stepper output { min-width: 28px; text-align: center; font-weight: 600; font-size: 14px; }
.del-btn { width: 34px; height: 34px; border-radius: 9px; color: var(--text-3); display: inline-flex; align-items: center; justify-content: center; }
.del-btn svg { width: 18px; height: 18px; }
.del-btn:active { background: var(--danger-soft); color: var(--danger); }

/* ── Sheets ── */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 40; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    max-width: 560px; margin: 0 auto;
    max-height: 88vh; display: flex; flex-direction: column;
    background: var(--surface); border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 40px rgba(0,0,0,.2);
    animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-full { top: 0; max-height: none; border-radius: 0; padding-top: var(--safe-t); }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 6px; }
.sheet-head h2 { font-size: 17px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 16px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); }

/* ── Result rows ── */
.rows { list-style: none; }
.row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.row-main { display: grid; grid-template-columns: 92px 1fr auto auto; gap: 6px; align-items: center; }
.row-label {
    width: 100%; margin-bottom: 6px; padding: 4px 0;
    border: none; border-bottom: 1px dashed transparent; background: transparent;
    font-size: 13.5px; color: var(--text-2);
}
.row-label:focus { outline: none; border-bottom-color: var(--border); }
.row-conv { margin-top: 6px; font-size: 16px; font-weight: 700; }
.row-conv.muted { color: var(--text-3); font-weight: 500; font-size: 13.5px; }
.row-unit { margin-top: 2px; font-size: 12.5px; color: var(--text-2); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.badge {
    font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.totals { margin-top: 14px; padding: 14px; border-radius: var(--r-md); background: var(--surface-2); }

/* ── Form fields ── */
.select, .input {
    width: 100%; min-width: 0;
    padding: 9px 10px; border-radius: var(--r-sm);
    border: 1px solid var(--border); background: var(--surface-2);
    font-size: 15px;
}
.select:focus, .input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.input { font-variant-numeric: tabular-nums; }
.select-sm { width: auto; padding: 7px 6px; }

.group { padding: 14px 0; border-bottom: 1px solid var(--border); }
.group:last-child { border-bottom: none; }
.group-title { font-size: 13px; color: var(--primary); font-weight: 700; margin-bottom: 10px; text-transform: uppercase; letter-spacing: .02em; }
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.field-desc { display: block; font-size: 12.5px; color: var(--text-3); margin-bottom: 6px; }
.sec-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fee-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: var(--r-md); background: var(--surface-2); margin-bottom: 8px; }
.seg-item { position: relative; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span { display: block; text-align: center; padding: 8px 4px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg-item input:checked + span { background: var(--surface); color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.seg-item input:focus-visible + span { outline: 2px solid var(--primary); }
.seg-sm .seg-item span { padding: 6px 4px; }
.mode-panel { margin-top: 10px; padding: 12px; border-radius: var(--r-md); border: 1px solid var(--border); }

.manual-line { display: grid; grid-template-columns: auto auto auto 1fr auto; gap: 6px; align-items: center; font-weight: 600; }
.deviation { min-height: 20px; margin: 8px 0; font-size: 13px; color: var(--text-2); }
.deviation.warn { color: var(--danger); font-weight: 600; }
.manual-actions { display: flex; justify-content: flex-end; gap: 8px; }
.manual-list { list-style: none; margin-top: 12px; }
.manual-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.manual-list .m-meta { font-size: 12px; color: var(--text-3); }
.manual-list .m-meta.warn { color: var(--warn); }

/* ── Onboarding ── */
.onboarding .sheet-body { padding-top: 32px; }
.ob-step { font-size: 13px; font-weight: 700; color: var(--primary); }
.ob-title { font-size: 24px; margin: 6px 0 8px; line-height: 1.3; }
.ob-desc { color: var(--text-2); margin-bottom: 20px; font-size: 14.5px; }
.ob-guess { margin-top: 8px; font-size: 12.5px; color: var(--text-3); }
.ob-options { display: grid; gap: 8px; }
.ob-option { display: block; padding: 14px; border-radius: var(--r-md); border: 2px solid var(--border); cursor: pointer; }
.ob-option input { margin-right: 8px; accent-color: var(--primary); }
.ob-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.ob-option-title { font-weight: 700; }
.ob-option-desc { display: block; margin-top: 2px; padding-left: 24px; font-size: 13px; color: var(--text-2); }
.ob-foot { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

/* ── Footer / Toast ── */
.footer { margin-top: 20px; padding: 12px 4px; font-size: 12px; color: var(--text-3); text-align: center; }
.footer p + p { margin-top: 4px; }
.foot-src { opacity: .8; }
.toast {
    position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
    z-index: 70; max-width: calc(100% - 32px);
    padding: 10px 16px; border-radius: 999px;
    background: #18222f; color: #fff; font-size: 13.5px; box-shadow: var(--shadow);
}

@media (min-width: 600px) {
    .sheet { border-radius: 20px; bottom: 16px; }
    .sheet-full { top: 16px; bottom: 16px; }
}
