:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-soft: #eef2ff;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active-bg: rgba(99, 102, 241, 0.18);
    --sidebar-active-text: #ffffff;
    --shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body.auth {
    background: #0b1220;
    color: #e5e7eb;
}

.layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: var(--sidebar-text);
    padding: 20px 16px;
    border-right: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #e2e8f0;
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 20px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.2);
    color: #e0e7ff;
    border: 1px solid rgba(99, 102, 241, 0.4);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-section {
    margin: 14px 8px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(148, 163, 184, 0.7);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: 0.2s ease;
}

.nav-item i {
    font-size: 18px;
}

.nav-item:hover {
    background: rgba(148, 163, 184, 0.14);
    color: #ffffff;
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.35);
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 5;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f1f5f9;
    min-width: 240px;
    color: var(--muted);
}

.topbar-search input {
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 13px;
    width: 100%;
    color: var(--text);
    border-radius: 0;
}

.topbar-search input:focus {
    outline: none;
    box-shadow: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border: 1px solid #dbeafe;
    font-size: 12px;
    font-weight: 600;
}

.topbar-title {
    font-weight: 600;
    color: var(--muted);
    font-size: 14px;
}

.sidebar-toggle {
    display: none;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
}

.sidebar-toggle i {
    font-size: 20px;
}

.content {
    padding: 24px;
}

.content h2 {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 700;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.page-subtitle {
    color: var(--muted);
    font-size: 13px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.summary-card {
    border: 0;
    border-radius: 14px;
    padding: 16px 18px;
    color: #ffffff;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.25);
}

.summary-card:nth-child(3n + 2) {
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.25);
}

.summary-card:nth-child(3n + 3) {
    background: linear-gradient(135deg, #10b981 0%, #22c55e 100%);
    box-shadow: 0 10px 24px rgba(16, 185, 129, 0.25);
}

.summary-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 10px;
    color: #ffffff;
}

.summary-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.summary-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #ffffff !important;
    margin-bottom: 4px;
    font-weight: 600;
}

.summary-number {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
}

.empty-state {
    font-size: 13px;
    color: var(--muted);
    padding: 12px 0;
}

.card {
    background: var(--card);
    border-radius: 14px;
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.card + .card {
    margin-top: 18px;
}

.card h3 {
    margin-top: 0;
}

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: var(--muted);
    margin-top: 12px;
    margin-bottom: 6px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text);
    margin-top: 12px;
    margin-bottom: 0;
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: #ffffff;
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="checkbox"] {
    width: auto;
    padding: 0;
    margin: 0 6px 0 0;
    box-shadow: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
    resize: vertical;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: 0.2s ease;
}

.btn:hover {
    background: #f8fafc;
}

.btn.primary {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.25);
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.btn.danger {
    border-color: #fca5a5;
    color: #ffffff;
    background: #ef4444;
    box-shadow: 0 6px 14px rgba(239, 68, 68, 0.2);
}

.btn.danger:hover {
    background: #dc2626;
}

.btn.warning {
    border-color: #fb923c;
    color: #ffffff;
    background: #f97316;
    box-shadow: 0 6px 14px rgba(249, 115, 22, 0.2);
}

.btn.warning:hover {
    background: #ea580c;
}

.alert {
    padding: 10px 12px;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: #0369a1;
    border-radius: 10px;
    margin-bottom: 10px;
}

.alert.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.table-wrap {
    overflow-x: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #ffffff;
}

.table-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 6px;
}

.table-title h3 {
    margin: 0;
}

.table-meta {
    font-size: 12px;
    color: var(--muted);
    background: #f8fafc;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

.page-info {
    font-size: 12px;
    color: var(--muted);
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 12px 0 6px;
    align-items: flex-end;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f9fafb;
}

.filter-form > div {
    flex: 1 1 180px;
    min-width: 160px;
}

.filter-form input,
.filter-form select {
    height: 38px;
    padding: 8px 12px;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.filter-actions .btn {
    height: 38px;
    padding: 0 14px;
}

.bulk-actions {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: #f8fafc;
    margin-bottom: 10px;
}

.bulk-actions.show {
    display: flex;
}

.bulk-info {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.table-check {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.accounts-table .col-check {
    width: 4%;
    text-align: center;
}

.table-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.table-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #f8fafc;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    border: 1px solid transparent;
    transition: 0.2s ease;
    cursor: pointer;
}

.table-tab:hover {
    color: var(--text);
    border-color: var(--border);
}

.table-tab.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-color: rgba(99, 102, 241, 0.35);
    font-weight: 600;
}

.tab-content {
    margin-top: 12px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.table-tab .tab-count {
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #ffffff;
    font-size: 11px;
    color: var(--muted);
}

.table-tab.active .tab-count {
    color: var(--primary-dark);
    border-color: rgba(99, 102, 241, 0.35);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0;
}

.table-fixed {
    table-layout: auto;
}

.table-fixed th,
.table-fixed td {
    white-space: nowrap;
}

.table-wrap table th[class*="col-"],
.table-wrap table td[class*="col-"] {
    width: auto;
}

.cell-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
}

th, td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    padding: 12px 14px;
    text-align: left;
    font-size: 13px;
    color: #111827;
    font-weight: 600;
}

th:last-child,
td:last-child {
    border-right: none;
}

tbody tr:last-child td {
    border-bottom: none;
}

th {
    background: #f9fafb;
    font-weight: 700;
    font-size: 12px;
    color: #111827;
    text-transform: none;
    letter-spacing: 0;
}

tbody tr:nth-child(even) {
    background: #fafafa;
}

tbody tr:hover {
    background: #f3f4f6;
}

.stock-table .col-id {
    width: 10%;
    text-align: center;
}

.stock-table .col-name {
    width: 70%;
}

.stock-table .col-stock {
    width: 20%;
    text-align: center;
}

.products-table .col-id {
    width: 6%;
    text-align: center;
}

.products-table .col-name {
    width: 40%;
}

.products-table .col-category {
    width: 12%;
}

.products-table .col-type {
    width: 8%;
    text-align: center;
}

.products-table .col-price {
    width: 10%;
    text-align: right;
}

.products-table .col-stock {
    width: 6%;
    text-align: center;
}

.products-table .col-status {
    width: 6%;
    text-align: center;
}

.products-table .col-actions {
    width: 12%;
    text-align: center;
}

.accounts-table .col-id {
    width: 8%;
    text-align: center;
}

.accounts-table .col-product {
    width: 50%;
}

.accounts-table .col-category {
    width: 16%;
}

.accounts-table .col-account {
    width: 8%;
}

.accounts-table .col-status {
    width: 10%;
    text-align: center;
}

.accounts-table .col-time {
    width: 14%;
}

.accounts-table .col-actions {
    width: 10%;
    text-align: center;
}

.orders-table .col-id {
    width: 6%;
    text-align: center;
}

.orders-table .col-telegram {
    width: 16%;
}

.orders-table .col-username {
    width: 14%;
}

.orders-table .col-total {
    width: 10%;
    text-align: right;
}

.orders-table .col-status {
    width: 10%;
    text-align: center;
}

.orders-table .col-time {
    width: 16%;
}

.orders-table .col-actions {
    width: 8%;
    text-align: center;
}

.users-table .col-telegram {
    width: 16%;
}

.users-table .col-username {
    width: 14%;
}

.users-table .col-name {
    width: 16%;
}

.users-table .col-balance {
    width: 10%;
    text-align: right;
}

.users-table .col-created {
    width: 20%;
}

.users-table .col-actions {
    width: 12%;
    text-align: left;
}

.sepay-table .col-sepay {
    width: 10%;
    text-align: center;
}

.sepay-table .col-telegram {
    width: 14%;
}

.sepay-table .col-amount {
    width: 10%;
    text-align: right;
}

.sepay-table .col-status {
    width: 12%;
    text-align: center;
}

.sepay-table .col-content {
    width: 22%;
}

.sepay-table .col-ref {
    width: 12%;
}

.sepay-table .col-time {
    width: 12%;
}

.sepay-table .col-actions {
    width: 8%;
    text-align: center;
}

.category-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border);
}

.status-available,
.status-on {
    color: #15803d;
    background: #dcfce7;
    border-color: #bbf7d0;
}

.status-disabled,
.status-off {
    color: #b45309;
    background: #fff7ed;
    border-color: #fed7aa;
}

.status-paid {
    color: #0f766e;
    background: #ecfeff;
    border-color: #a5f3fc;
}

.status-received {
    color: #1d4ed8;
    background: #eff6ff;
    border-color: #bfdbfe;
}

.status-credited {
    color: #047857;
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.status-unmatched,
.status-account_mismatch {
    color: #92400e;
    background: #fffbeb;
    border-color: #fed7aa;
}

.status-user_not_found {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.status-sold {
    color: #1d4ed8;
    background: #eff6ff;
    border-color: #bfdbfe;
}

.status-ignored {
    color: #64748b;
    background: #f8fafc;
    border-color: #e2e8f0;
}

.status-pending {
    color: #92400e;
    background: #fffbeb;
    border-color: #fed7aa;
}

.status-cancelled,
.status-canceled {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.order-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 14px;
}

.summary-label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.summary-value {
    font-weight: 600;
    color: var(--text);
}

.actions .btn {
    margin-right: 6px;
}

.account-text {
    display: block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
}

.wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.login-card {
    max-width: 420px;
    margin: 80px auto;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text);
}

.login-card .btn.primary {
    margin-top: 12px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.hint {
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
}

.list {
    padding-left: 18px;
}

pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 10px;
    overflow-x: auto;
}

.quill-container {
    display: none;
    background: #fff;
    border-radius: 0 0 10px 10px;
    border: none;
}

.quill-container .ql-toolbar.ql-snow {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    background: #f8fafc;
}

.quill-container .ql-container.ql-snow {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 10px 10px;
    min-height: 180px;
}

.quill-container .ql-editor {
    min-height: 160px;
    padding: 14px 16px;
}

.quill-textarea {
    font-family: inherit;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
}

.modal-card {
    position: relative;
    width: min(720px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
    z-index: 2;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.modal-actions .btn.primary {
    margin-top: 0;
}

.icon-btn {
    border: 1px solid var(--border);
    background: #ffffff;
    border-radius: 10px;
    padding: 6px 8px;
    cursor: pointer;
}

.modal-open {
    overflow: hidden;
}

.overlay {
    display: none;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 220px 1fr;
    }
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 260px;
        height: 100vh;
        z-index: 20;
        transition: 0.25s ease;
        box-shadow: 12px 0 24px rgba(15, 23, 42, 0.08);
    }

    body.sidebar-open .sidebar {
        left: 0;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .overlay {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.2);
        opacity: 0;
        pointer-events: none;
        transition: 0.2s ease;
        z-index: 10;
        display: block;
    }

    body.sidebar-open .overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .table-wrap table {
        min-width: 640px;
    }
}

@media (max-width: 600px) {
    .content {
        padding: 16px;
    }

    .wrap {
        padding: 16px;
    }

    .card {
        padding: 14px;
    }
}
