:root {
    --bg: #eef4fb;
    --card: rgba(255, 255, 255, 0.96);
    --text: #102033;
    --muted: #65758b;
    --line: #e3eaf3;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --shadow: 0 18px 45px rgba(15, 35, 65, 0.10);
    --radius: 22px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 32%),
        linear-gradient(135deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 265px;
    background: linear-gradient(180deg, #0f172a 0%, #172554 100%);
    color: white;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: 12px 0 35px rgba(15, 23, 42, 0.18);
}

.logo {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 28px;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    color: #dbeafe;
    text-decoration: none;
    padding: 13px 14px;
    border-radius: 15px;
    margin-bottom: 9px;
    font-weight: 650;
    transition: 0.18s ease;
}

.nav-link:hover, .nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateX(3px);
}

.nav-link.active {
    background: linear-gradient(135deg, #2563eb, #60a5fa);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.35);
}

.content {
    flex: 1;
    padding: 28px;
    max-width: 1700px;
    margin: 0 auto;
    width: 100%;
}

.page-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-bottom: 22px;
}

h1, h2 { letter-spacing: -0.5px; }
h1 { font-size: clamp(29px, 4vw, 45px); margin: 0; }
h2 { font-size: clamp(22px, 2.6vw, 31px); margin: 0 0 20px; }

.card {
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    backdrop-filter: blur(8px);
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 4px;
}

.stat {
    background: linear-gradient(145deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid #e9eff7;
    border-radius: 20px;
    padding: 21px;
    box-shadow: 0 14px 35px rgba(15, 35, 65, 0.08);
    min-height: 105px;
}

.stat .num {
    font-size: clamp(26px, 3vw, 34px);
    font-weight: 850;
    color: #0f172a;
    line-height: 1;
}
.stat .label { color: var(--muted); margin-top: 10px; font-weight: 600; }

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.form-group { margin-bottom: 15px; }
label {
    display: block;
    margin-bottom: 8px;
    font-weight: 800;
    color: #132238;
}

input, select, textarea {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid #cfd9e6;
    border-radius: 14px;
    font-size: 16px;
    background: white;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
textarea { min-height: 105px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: none;
    border-radius: 14px;
    padding: 13px 18px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    text-decoration: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 800;
    min-height: 47px;
    box-shadow: 0 12px 26px rgba(37, 99, 235, 0.24);
    transition: 0.18s ease;
}
.btn:hover { background: linear-gradient(135deg, var(--primary-dark), #2563eb); transform: translateY(-1px); }
.btn-danger { background: linear-gradient(135deg, var(--danger), #ef4444); box-shadow: 0 12px 24px rgba(220, 38, 38, 0.20); }
.btn-danger:hover { background: linear-gradient(135deg, #b91c1c, #dc2626); }
.btn-success { background: linear-gradient(135deg, var(--success), #22c55e); box-shadow: 0 12px 24px rgba(22, 163, 74, 0.20); }
.btn-success:hover { background: linear-gradient(135deg, #15803d, #16a34a); }
.btn-muted { background: linear-gradient(135deg, #64748b, #7b8798); box-shadow: 0 12px 24px rgba(100, 116, 139, 0.18); }
.btn-small { padding: 8px 12px; font-size: 14px; min-height: 36px; border-radius: 11px; }

.table-wrap { width: 100%; overflow-x: auto; border-radius: 18px; }
.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 850px;
}
.table th, .table td {
    padding: 15px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}
.table th {
    background: #f4f7fb;
    color: #334155;
    font-weight: 850;
    white-space: nowrap;
}
.table tr:hover td { background: #fbfdff; }
.table tfoot th {
    background: #eef4fb;
    font-weight: 900;
}
.actions { white-space: nowrap; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    margin-left: 6px;
}
.badge-on { background: #dcfce7; color: #166534; }
.badge-off { background: #fee2e2; color: #991b1b; }
.alert {
    padding: 14px 16px;
    border-radius: 15px;
    margin-bottom: 18px;
    background: #dcfce7;
    color: #166534;
    font-weight: 700;
}
.alert-error { background: #fee2e2; color: #991b1b; }

.filter {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 14px;
    align-items: end;
}
.filter .form-group { margin-bottom: 0; }
.filter .btn { width: 100%; }
.filter-info { margin-top: 14px; }
.hint { color: var(--muted); line-height: 1.5; }
.small-date { max-width: 290px; }

.product-row {
    display: grid;
    grid-template-columns: 1.15fr 1.5fr 0.7fr 0.7fr 0.8fr 1.2fr;
    gap: 13px;
    align-items: end;
    padding: 16px;
    margin-bottom: 14px;
    border: 1px solid #dde7f3;
    border-radius: 20px;
    background: linear-gradient(145deg, #fbfdff, #f4f8fd);
}

@media (max-width: 1250px) {
    .grid { grid-template-columns: repeat(2, 1fr); }
    .filter { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .product-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    .app { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        z-index: 20;
        padding: 13px 12px;
        border-radius: 0 0 22px 22px;
    }
    .logo { margin-bottom: 12px; font-size: 21px; }
    .sidebar .nav-link {
        display: inline-flex;
        margin: 0 6px 0 0;
        padding: 11px 13px;
        white-space: nowrap;
    }
    .sidebar { overflow-x: auto; }
    .content { padding: 18px 14px 28px; }
    .page-title { flex-direction: column; align-items: stretch; }
    .page-title .btn { width: 100%; }
    .form-row, .filter { grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .card { padding: 18px; border-radius: 19px; }
}

@media (max-width: 650px) {
    body { background: #f3f7fc; }
    .content { padding: 15px 10px 24px; }
    h1 { font-size: 31px; }
    h2 { font-size: 24px; }
    .grid { grid-template-columns: 1fr; }
    .stat { padding: 18px; min-height: auto; }
    .btn { width: 100%; }
    .card { padding: 15px; }
    .product-row { grid-template-columns: 1fr; padding: 13px; }
    .small-date { max-width: none; }

    .table-wrap { overflow: visible; }
    .table { min-width: 0; border-collapse: separate; border-spacing: 0 12px; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td, .table tfoot, .table th { display: block; width: 100%; }
    .table tr {
        background: #fff;
        border: 1px solid #e1e9f3;
        border-radius: 18px;
        padding: 8px 0;
        box-shadow: 0 10px 25px rgba(15, 35, 65, 0.07);
        overflow: hidden;
    }
    .table td {
        border-bottom: 1px solid #edf2f7;
        padding: 11px 13px;
        display: flex;
        justify-content: space-between;
        gap: 14px;
        text-align: right;
    }
    .table td:last-child { border-bottom: none; }
    .table td::before {
        content: attr(data-label);
        font-weight: 900;
        color: #475569;
        text-align: left;
        flex: 0 0 42%;
    }
    .table tfoot tr { background: #eef4fb; }
    .table tfoot th {
        padding: 12px 13px;
        border-bottom: 1px solid #dce6f2;
    }
    .actions { justify-content: flex-end; }
    .actions .btn, .actions button { width: auto; }
    input, select, textarea { font-size: 16px; min-height: 48px; }
}

.ajax-loader {
    position: sticky;
    top: 12px;
    z-index: 30;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 999px;
    background: #1d4ed8;
    color: #fff;
    font-weight: 800;
    box-shadow: 0 12px 30px rgba(37, 99, 235, 0.25);
}

.ajax-loader::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.45);
    border-top-color: #fff;
    animation: ajaxSpin .7s linear infinite;
}

@keyframes ajaxSpin {
    to { transform: rotate(360deg); }
}

#ajaxResults {
    transition: opacity .18s ease, transform .18s ease;
}

#ajaxResults.is-loading {
    opacity: .55;
    transform: translateY(2px);
    pointer-events: none;
}

.small-card {
    padding-top: 14px;
    padding-bottom: 14px;
}

@media (max-width: 650px) {
    .ajax-loader {
        width: 100%;
        justify-content: center;
        top: 8px;
    }
}

.sale-row {
    display: grid;
    grid-template-columns: 1.4fr 0.7fr 0.9fr 1.2fr;
    gap: 13px;
    align-items: end;
    padding: 16px;
    margin-bottom: 14px;
    border: 1px solid #dde7f3;
    border-radius: 20px;
    background: linear-gradient(145deg, #fbfdff, #f4f8fd);
}

.form-actions {
    margin-top: 6px;
}

@media (max-width: 1250px) {
    .sale-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 650px) {
    .sale-row { grid-template-columns: 1fr; padding: 13px; }
    .form-actions .btn { width: 100%; }
}

.stat-good {
    border-color: rgba(22, 163, 74, 0.28);
    background: linear-gradient(145deg, #f0fdf4, #ffffff);
}

.stat-bad {
    border-color: rgba(220, 38, 38, 0.28);
    background: linear-gradient(145deg, #fef2f2, #ffffff);
}

.summary-card {
    margin-top: 18px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 0;
    border-bottom: 1px solid #e5eaf2;
    font-size: 16px;
}

.summary-row:last-child {
    border-bottom: 0;
}

.summary-row strong {
    white-space: nowrap;
}

.summary-total {
    font-size: 20px;
    font-weight: 900;
}

@media (max-width: 650px) {
    .summary-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 5px;
    }
}
