/* ============================================
   ScanManager v2 — Design System
   Мобильный-first, профессиональный UI
   ============================================ */

/* ========== CSS Variables ========== */
:root {
    --c-bg: #f0f2f5;
    --c-surface: #ffffff;
    --c-surface-alt: #f7f8fa;
    --c-text: #1a1a2e;
    --c-text-secondary: #6b7280;
    --c-text-muted: #9ca3af;
    --c-border: #e5e7eb;
    --c-border-light: #f3f4f6;

    --c-accent: #2563eb;
    --c-accent-light: #dbeafe;
    --c-accent-hover: #1d4ed8;

    --c-success: #059669;
    --c-success-light: #d1fae5;
    --c-warning: #d97706;
    --c-warning-light: #fef3c7;
    --c-danger: #dc2626;
    --c-danger-light: #fee2e2;
    --c-info: #0891b2;

    /* Mode colors */
    --c-out: #7c3aed;      /* Расход – фиолетовый */
    --c-out-light: #ede9fe;
    --c-in: #059669;       /* Приход – зелёный */
    --c-in-light: #d1fae5;
    --c-inv: #d97706;      /* Инвентаризация – оранжевый */
    --c-inv-light: #fef3c7;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,.05), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.08);

    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    --nav-w: 260px;
    --bottom-h: 64px;
    --header-h: 56px;
}

/* ========== Reset ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--c-accent); text-decoration: none; }
a:hover { color: var(--c-accent-hover); }
img, svg { max-width: 100%; display: block; }

/* ========== Typography ========== */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.35rem; font-weight: 650; }
h3 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

/* ========== Layout ========== */
.app-shell {
    display: flex;
    min-height: 100vh;
}
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.app-content {
    flex: 1;
    padding: 20px 16px 100px;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

/* ========== Desktop Sidebar ========== */
.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--nav-w);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    display: flex; flex-direction: column;
    z-index: 100;
    box-shadow: 2px 0 20px rgba(0,0,0,.15);
}
.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: 12px;
}
.sidebar-brand-icon {
    width: 38px; height: 38px;
    background: var(--c-accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: #fff;
}
.sidebar-brand-text { font-weight: 700; font-size: 1.05rem; color: #fff; letter-spacing: -.01em; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.sidebar-section { padding: 16px 12px 6px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #64748b; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 8px;
    color: #94a3b8; font-weight: 500; font-size: .9rem;
    transition: all .15s;
}
.sidebar-link:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.sidebar-link.active { background: rgba(37,99,235,.25); color: #60a5fa; font-weight: 600; }
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar-footer {
    padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.08);
    display: flex; flex-direction: column; gap: 2px;
}

/* ========== Mobile Bottom Menu ========== */
.bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-h);
    background: #fff;
    border-top: 1px solid var(--c-border);
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.bottom-nav-inner {
    display: flex; height: 100%;
    max-width: 500px; margin: 0 auto;
}
.bottom-nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 4px;
    color: var(--c-text-muted); font-size: .65rem; font-weight: 500;
    transition: color .15s;
}
.bottom-nav-item i { font-size: 1.2rem; }
.bottom-nav-item.active { color: var(--c-accent); font-weight: 700; }

/* ========== Cards ========== */
.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--c-border-light);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 12px;
    border-bottom: 1px solid var(--c-border-light);
}
.card-header h3 { margin: 0; display: flex; align-items: center; gap: 8px; }

/* ========== Stats Grid ========== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--c-border-light);
    display: flex; align-items: center; gap: 14px;
}
.stat-icon-box {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.stat-info { min-width: 0; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--c-text-secondary); margin-top: 2px; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-xs); font-weight: 600; font-size: .9rem;
    border: none; cursor: pointer; transition: all .15s; line-height: 1.4;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover { background: var(--c-accent-hover); }
.btn-success { background: var(--c-success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; border: 1.5px solid var(--c-border); color: var(--c-text); }
.btn-outline:hover { border-color: var(--c-accent); color: var(--c-accent); background: var(--c-accent-light); }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: 10px; }
.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 8px; }
.btn-block { width: 100%; }

/* ========== Forms ========== */
.form-control {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid var(--c-border); border-radius: var(--radius-xs);
    font-size: .95rem; font-family: var(--font);
    background: var(--c-surface); color: var(--c-text);
    transition: border-color .15s; outline: none;
}
.form-control:focus { border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-control::placeholder { color: var(--c-text-muted); }

/* Scan input — крупное поле */
.scan-input-lg {
    width: 100%; padding: 16px 20px;
    font-size: 1.15rem; font-family: var(--font-mono);
    border: 2px solid var(--c-border); border-radius: 12px;
    background: var(--c-surface); text-align: center;
    letter-spacing: .03em; outline: none; transition: all .2s;
}
.scan-input-lg:focus { border-color: var(--c-accent); box-shadow: 0 0 0 4px rgba(37,99,235,.08); }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; padding: 10px 12px; font-weight: 650; color: var(--c-text-secondary); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid var(--c-border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--c-border-light); }
tr:last-child td { border-bottom: none; }
tr.completed { background: var(--c-success-light); }
tr.completed td { color: var(--c-success); }

/* ========== Badges ========== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge-success { background: var(--c-success-light); color: var(--c-success); }
.badge-warning { background: var(--c-warning-light); color: var(--c-warning); }
.badge-danger { background: var(--c-danger-light); color: var(--c-danger); }
.badge-info { background: var(--c-accent-light); color: var(--c-accent); }
.badge-out { background: var(--c-out-light); color: var(--c-out); }
.badge-in { background: var(--c-in-light); color: var(--c-in); }
.badge-inv { background: var(--c-inv-light); color: var(--c-inv); }

/* ========== Progress ========== */
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-bar {
    flex: 1; height: 6px; background: var(--c-border-light);
    border-radius: 6px; overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 6px; transition: width .3s; }
.progress-fill.green { background: var(--c-success); }
.progress-fill.blue { background: var(--c-accent); }
.progress-fill.yellow { background: var(--c-warning); }
.progress-percent { font-size: .75rem; font-weight: 700; color: var(--c-text-secondary); min-width: 36px; text-align: right; }

/* ========== Alerts ========== */
.alert {
    padding: 12px 16px; border-radius: var(--radius-xs);
    font-size: .88rem; font-weight: 500; margin-bottom: 12px;
}
.alert-error { background: var(--c-danger-light); color: var(--c-danger); }
.alert-success { background: var(--c-success-light); color: var(--c-success); }
.alert-info { background: var(--c-accent-light); color: var(--c-accent); }

/* ========== Hero (scan pages) ========== */
.scan-hero {
    text-align: center; padding: 16px 16px 8px;
}
.scan-hero-icon {
    width: 64px; height: 64px; border-radius: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 2rem; margin-bottom: 12px;
}
.scan-hero h2 { margin-bottom: 4px; }
.scan-hero p { color: var(--c-text-secondary); font-size: .9rem; }

/* ========== Mode Cards (выбор режима) ========== */
.mode-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.mode-card {
    background: var(--c-surface); border-radius: var(--radius);
    padding: 24px; box-shadow: var(--shadow);
    border: 1.5px solid var(--c-border-light);
    display: flex; flex-direction: column; gap: 12px;
    cursor: pointer; transition: all .2s; text-decoration: none; color: inherit;
}
.mode-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.mode-card-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
}
.mode-card h3 { margin: 0; font-size: 1.05rem; }
.mode-card p { color: var(--c-text-secondary); font-size: .85rem; margin: 0; }

/* ========== Empty State ========== */
.empty-state {
    text-align: center; padding: 40px 20px; color: var(--c-text-muted);
}
.empty-state i { font-size: 3rem; display: block; margin-bottom: 12px; opacity: .4; }

/* ========== Toast ========== */
.toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    padding: 12px 20px; border-radius: 10px;
    font-weight: 600; font-size: .88rem; z-index: 200;
    box-shadow: var(--shadow-lg); animation: toastIn .3s ease;
    max-width: 90vw; text-align: center;
}
.toast-success { background: var(--c-success); color: #fff; }
.toast-error { background: var(--c-danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ========== Status dot ========== */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.ok { background: var(--c-success); }
.status-dot.pending { background: var(--c-warning); }
.status-dot.error { background: var(--c-danger); }

/* ========== Dropdown ========== */
.dropdown.show { display: block !important; }

/* ========== Responsive ========== */
@media (min-width: 768px) {
    .app-content { padding: 24px 24px 40px; }
    .sidebar { display: flex; }
    .bottom-nav { display: none !important; }
    body { padding-left: var(--nav-w); }
    .scan-input-lg { font-size: 1.3rem; padding: 18px 24px; }
}
@media (max-width: 767px) {
    .sidebar { display: none !important; }
    .bottom-nav { display: block; }
    body { padding-left: 0; padding-bottom: var(--bottom-h); }
    .app-content { padding: 12px 10px 80px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 1.25rem; }
    .mode-grid { grid-template-columns: 1fr; gap: 8px; }
    .mode-card { padding: 16px; }
    h1 { font-size: 1.4rem; }
    .hide-mobile { display: none !important; }
    .scan-hero { display: none !important; }
    /* Table → block cards on mobile */
    .card-table thead { display: none; }
    .card-table tr { display: block; margin-bottom: 8px; background: var(--c-surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 10px 12px; border: 1px solid var(--c-border-light); }
    .card-table td { display: block; padding: 2px 0; border: none; font-size: .85rem; }
    .card-table td.card-status,
    .card-table td.card-progress { display: none; }
    .card-table td.card-name { font-weight: 600; font-size: .9rem; padding-bottom: 4px; }
    .card-table td.card-qty { display: inline; font-size: .82rem; color: var(--c-text-secondary); }
    .card-table td.card-scanned { display: inline; font-size: .82rem; color: var(--c-text-secondary); margin-left: 8px; padding-left: 8px; border-left: 1px solid var(--c-border); }
    .card-table tr.completed { border-left: 3px solid var(--c-success); }
}
@media (max-width: 380px) {
    .stats-row { grid-template-columns: 1fr; }
}
