/* ================================================================
   Design Tokens
   ================================================================ */
:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-text: #1a1d26;
    --color-text-secondary: #5c6070;
    --color-text-muted: #8c92a4;
    --color-text-faint: #b4b9c8;

    --color-accent: #5469d4;
    --color-accent-hover: #4558b8;
    --color-accent-focus: rgba(84, 105, 212, 0.16);

    --color-border: #e4e6ec;
    --color-border-subtle: #eceef2;

    --color-success: #2d9d78;
    --color-success-border: rgba(45, 157, 120, 0.25);
    --color-success-bg: #f0faf6;
    --color-error: #d94052;
    --color-error-border: rgba(217, 64, 82, 0.25);
    --color-error-bg: #fdf2f3;
    --color-warning-text: #8a6d00;
    --color-warning-bg: #fefaed;
    --color-warning-border: #ecdba0;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm:
        0 1px 3px rgba(0, 0, 0, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md:
        0 4px 12px rgba(0, 0, 0, 0.06),
        0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-lg:
        0 8px 24px rgba(0, 0, 0, 0.08),
        0 2px 4px rgba(0, 0, 0, 0.04);
}

/* ================================================================
   Reset & Base
   ================================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ================================================================
   Utility
   ================================================================ */
.hidden {
    display: none !important;
}

/* ================================================================
   Layout
   ================================================================ */
.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 40px;
    min-height: 100dvh;
}

/* ================================================================
   App Header
   ================================================================ */
.app-header {
    padding: 20px 0 28px;
}

.app-header__title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
    margin-bottom: 2px;
}

.app-header__subtitle {
    font-size: 13px;
    font-weight: 400;
    color: var(--color-text-muted);
}

/* ================================================================
   Scanner Section
   ================================================================ */
.scanner-section {
    margin-bottom: 24px;
}

.scanner-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #1a1d26;
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: none;
    box-shadow: var(--shadow-md);
    margin-bottom: 12px;
}

.scanner-container.active {
    display: block;
}

.scanner-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ================================================================
   Scanner Overlay
   ================================================================ */
.scanner-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.scanner-overlay::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 72%;
    height: 48%;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-radius: var(--radius-md);
    animation: frameBreathe 4s ease-in-out infinite;
}

@keyframes frameBreathe {
    0%, 100% { border-color: rgba(255, 255, 255, 0.4); }
    50% { border-color: rgba(255, 255, 255, 0.65); }
}

/* ================================================================
   Scanner Status Bar
   ================================================================ */
.scanner-status {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: rgba(255, 255, 255, 0.9);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    padding: 8px 16px;
    text-align: center;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    z-index: 2;
}

/* ================================================================
   Controls
   ================================================================ */
.controls {
    display: flex;
    gap: 8px;
}

/* ================================================================
   Buttons
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    flex: 1;
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
}

.btn:hover {
    background: #f8f9fb;
    border-color: #d4d7de;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn--primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

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

.btn--primary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-sm), 0 0 0 3px var(--color-accent-focus);
}

.btn--stop {
    background: var(--color-error-bg);
    border-color: var(--color-error-border);
    color: var(--color-error);
    box-shadow: none;
}

.btn--stop:hover {
    background: #fbe8ea;
    border-color: rgba(217, 64, 82, 0.35);
}

.btn__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn__icon svg {
    width: 18px;
    height: 18px;
}

/* ================================================================
   Divider
   ================================================================ */
.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 500;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

/* ================================================================
   Manual Input
   ================================================================ */
.manual-input {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
}

.manual-input__field {
    flex: 1;
    padding: 12px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1.5px;
    outline: none;
    box-shadow: var(--shadow-xs);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.manual-input__field::placeholder {
    color: var(--color-text-faint);
    letter-spacing: 0.5px;
    font-weight: 400;
}

.manual-input__field:focus {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-xs), 0 0 0 3px var(--color-accent-focus);
}

.manual-input .btn {
    flex: 0 0 auto;
    padding: 12px 14px;
}

/* ================================================================
   Result
   ================================================================ */
.result {
    display: none;
    margin-top: 24px;
    animation: slideUp 0.3s ease;
}

.result.visible {
    display: block;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================================================================
   Result Card
   ================================================================ */
.result-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.result-card--success {
    border-color: var(--color-success-border);
}

.result-card--error {
    border-color: var(--color-error-border);
}

.result-card__header {
    padding: 16px 20px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.result-card--success .result-card__header {
    color: var(--color-success);
}

.result-card--error .result-card__header {
    color: var(--color-error);
}

.result-card__header-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.result-card--success .result-card__header-dot {
    background: var(--color-success);
}

.result-card--error .result-card__header-dot {
    background: var(--color-error);
}

.result-card__body {
    padding: 20px;
}

/* ================================================================
   Result Content
   ================================================================ */
.result-country {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.result-country__flag {
    font-size: 48px;
    line-height: 1;
}

.result-country__info {
    flex: 1;
    min-width: 0;
}

.result-country__name {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
    margin-bottom: 2px;
}

.result-country__region {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.result-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.result-detail {
    background: var(--color-bg);
    border-radius: var(--radius-xs);
    padding: 12px 14px;
}

.result-detail__label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.result-detail__value {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.result-note {
    font-size: 12px;
    line-height: 1.6;
    padding: 12px 14px;
    background: var(--color-warning-bg);
    border-radius: var(--radius-xs);
    border-left: 3px solid var(--color-warning-border);
    color: var(--color-warning-text);
}

.result-error-message {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.6;
    padding: 4px 0;
}

/* ================================================================
   History
   ================================================================ */
.history {
    margin-top: 32px;
    display: none;
}

.history.visible {
    display: block;
}

.history__title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--color-text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history__clear {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    font-family: var(--font-sans);
    transition: color 0.15s ease, background 0.15s ease;
}

.history__clear:hover {
    color: var(--color-error);
    background: var(--color-error-bg);
}

.history__list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.history-item:hover {
    border-color: #d4d7de;
    box-shadow: var(--shadow-sm);
}

.history-item__flag {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}

.history-item__barcode {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
}

.history-item__country {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

.history-item__time {
    font-size: 11px;
    color: var(--color-text-faint);
    font-family: var(--font-mono);
    flex-shrink: 0;
}

/* ================================================================
   Toast
   ================================================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: transform 0.25s ease;
    pointer-events: none;
    white-space: nowrap;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
}

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 400px) {
    .app {
        padding: 0 12px 32px;
    }

    .result-country__flag {
        font-size: 40px;
    }

    .result-country__name {
        font-size: 18px;
    }

    .controls {
        flex-direction: column;
    }
}
