:root {
    --color-primary: #2e7d32;
    --color-primary-dark: #1b5e20;
    --color-bg: #f5f6f4;
    --color-card: #ffffff;
    --color-border: #dcdfd9;
    --color-text: #1f2a1f;
    --color-muted: #6b756a;
    --color-danger: #c62828;
    --radius: 10px;
    font-size: 16px;
}

* { box-sizing: border-box; }

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

button {
    font: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    padding: 0.6em 1em;
    background: var(--color-primary);
    color: #fff;
}
button:hover { background: var(--color-primary-dark); }
button.secondary { background: #e6e9e4; color: var(--color-text); }
button.secondary:hover { background: #d6dad1; }
button.danger { background: var(--color-danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select {
    font: inherit;
    padding: 0.5em 0.6em;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    width: 100%;
}

label { display: block; margin-bottom: 0.9em; font-size: 0.9em; color: var(--color-muted); }
label input, label select { margin-top: 0.3em; color: var(--color-text); }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
    background: var(--color-card);
    padding: 2em;
    border-radius: var(--radius);
    width: 90%;
    max-width: 360px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.login-card h1 { color: var(--color-primary); margin-top: 0; }
.error { color: var(--color-danger); }

.app-shell { max-width: 900px; margin: 0 auto; padding-bottom: 3em; }

.app-header {
    background: var(--color-primary);
    color: #fff;
    padding: 0.8em 1em;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6em 1em;
    position: sticky;
    top: 0;
    z-index: 10;
}
.app-header h1 { font-size: 1.2em; margin: 0; margin-right: auto; }
.app-nav { display: flex; gap: 0.8em; flex-wrap: wrap; }
.app-nav a { color: #eaf3ea; text-decoration: none; font-size: 0.95em; padding: 0.3em 0.1em; }
.app-nav a.active { color: #fff; font-weight: 600; border-bottom: 2px solid #fff; }
.app-header-right { display: flex; align-items: center; gap: 0.7em; margin-left: auto; }
.app-header-right button { background: rgba(255,255,255,0.15); }
.app-header-right button:hover { background: rgba(255,255,255,0.3); }

.sync-status { font-size: 0.85em; padding: 0.2em 0.6em; border-radius: 12px; background: rgba(255,255,255,0.15); }
.sync-status.offline { background: #c62828; }
.sync-status.pending { background: #f9a825; color: #3a2b00; }

#view { padding: 1em; }

.card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: 1em;
    margin-bottom: 1em;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1em; margin-bottom: 1em; flex-wrap: wrap; }
.toolbar h2 { margin: 0; }

.article-list, .market-list, .history-list { list-style: none; margin: 0; padding: 0; }
.article-list li, .market-list li, .history-list li {
    display: flex; align-items: center; gap: 0.8em;
    padding: 0.6em 0.3em; border-bottom: 1px solid var(--color-border);
}
.article-list li:last-child, .market-list li:last-child, .history-list li:last-child { border-bottom: none; }

.article-thumb { width: 44px; height: 44px; min-width: 44px; min-height: 44px; max-width: 44px; max-height: 44px; border-radius: 8px; object-fit: cover; background: #eef0ec; flex-shrink: 0; }
.article-name { flex: 1; min-width: 0; }
.article-name strong { display: block; overflow-wrap: anywhere; }
.article-name small { display: block; color: var(--color-muted); }
.article-name .article-ean { font-size: 0.8em; }

.article-actions { display: flex; gap: 0.3em; flex-shrink: 0; }
.icon-btn {
    background: #e6e9e4;
    color: var(--color-text);
    padding: 0.4em 0.55em;
    font-size: 1.05em;
    line-height: 1;
    border-radius: 8px;
}
.icon-btn:hover { background: #d6dad1; }
.icon-btn.danger { background: var(--color-danger); color: #fff; }
.icon-btn.danger:hover { background: #a52121; }

.line-price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; flex-shrink: 0; }

.drag-handle { cursor: grab; color: var(--color-muted); padding: 0 0.4em; }
.sortable-ghost { opacity: 0.4; }

.cart-list { list-style: none; margin: 0; padding: 0; }
.cart-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6em;
    padding: 0.7em 0.2em;
    border-bottom: 1px solid var(--color-border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item.in-cart { opacity: 0.5; }
.cart-item.in-cart .cart-name { text-decoration: line-through; }

.cart-check {
    width: 1.3em;
    height: 1.3em;
    margin: 0.15em 0 0;
    flex-shrink: 0;
    accent-color: var(--color-primary);
}

.cart-thumb {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    max-width: 44px;
    max-height: 44px;
    border-radius: 8px;
    object-fit: cover;
    background: #eef0ec;
    flex-shrink: 0;
}
.cart-thumb-empty { background: #eef0ec; }

.cart-main { flex: 1; min-width: 0; }

.cart-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.6em;
}
.cart-name { font-weight: 600; overflow-wrap: anywhere; }
.cart-total {
    font-weight: 700;
    font-size: 1.05em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
}

.cart-sub {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-top: 0.3em;
    color: var(--color-muted);
    font-size: 0.85em;
    flex-wrap: wrap;
}
.cart-unit-price { margin-right: auto; }

.qty-input { width: 5em; min-width: 5em; text-align: center; padding: 0.3em 0.2em; flex-shrink: 0; }

.remove-btn, .note-btn {
    background: none;
    padding: 0.2em 0.3em;
    font-size: 1.1em;
    line-height: 1;
    flex-shrink: 0;
}
.remove-btn { color: var(--color-danger); }
.remove-btn:hover { background: rgba(198,40,40,0.1); }
.note-btn:hover { background: rgba(0,0,0,0.06); }

.cart-note {
    display: inline-block;
    margin-top: 0.35em;
    padding: 0.15em 0.6em;
    background: #fff3cd;
    color: #6b5300;
    border-radius: 6px;
    font-size: 0.85em;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.summary-bar {
    position: sticky; bottom: 0;
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
    padding: 0.9em 1em;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 1.1em; font-weight: 600;
}

.empty-state { color: var(--color-muted); text-align: center; padding: 2em 1em; }

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center; padding: 1em; z-index: 50;
}
.modal { background: #fff; border-radius: var(--radius); padding: 1.2em; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6em; margin-top: 1em; }

.image-preview { width: 100px; height: 100px; object-fit: cover; border-radius: 8px; background: #eef0ec; margin-bottom: 0.5em; }
.scan-video { width: 100%; border-radius: 8px; margin-bottom: 0.5em; }

.badge { display: inline-block; padding: 0.15em 0.6em; border-radius: 10px; font-size: 0.8em; background: #e6e9e4; }
.badge.completed { background: #dcefdc; color: var(--color-primary-dark); }

@media (max-width: 480px) {
    .app-header { flex-direction: column; align-items: stretch; }
    .app-header h1 { margin: 0 0 0.2em; }
}
