/* =========================================================
   proITservice CRM — Design System v2 (Glassmorphism)
   ========================================================= */

:root {
    /* Brand */
    --primary: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-dark: #4338CA;
    --primary-50: #EEF2FF;
    --primary-100: #E0E7FF;
    --primary-500: #6366F1;
    --primary-600: #4F46E5;
    --primary-700: #4338CA;

    /* Sidebar (dark) */
    --sidebar-bg: #0F172A;
    --sidebar-text: #94A3B8;
    --sidebar-text-hover: #F1F5F9;
    --sidebar-icon: #64748B;
    --sidebar-icon-hover: #CBD5E1;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-active: #4F46E5;
    --sidebar-active-fg: #FFFFFF;
    --sidebar-hover-glass: rgba(255, 255, 255, 0.05);

    /* Neutral palette */
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-400: #94A3B8;
    --gray-500: #64748B;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1E293B;
    --gray-900: #0F172A;

    /* Status */
    --success: #10B981;
    --success-light: #D1FAE5;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --info: #0EA5E9;
    --info-light: #E0F2FE;

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 20px -5px rgba(15,23,42,0.08), 0 4px 8px -2px rgba(15,23,42,0.04);
    --shadow-glass: 0 1px 3px rgba(15, 23, 42, 0.05), 0 4px 12px rgba(15, 23, 42, 0.04);
    --shadow-glass-lg: 0 4px 16px rgba(15, 23, 42, 0.06), 0 8px 28px rgba(15, 23, 42, 0.05);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Solid surface tokens */
    --surface-card: #FFFFFF;
    --surface-card-border: #E2E8F0;
    --surface-topbar: #FFFFFF;
    --surface-row-alt: #F8FAFC;
    --surface-row-hover: #EEF2FF;

    /* Status badges (CRM) */
    --status-inwork-bg: #FEF3C7;
    --status-inwork-fg: #92400E;
    --status-ready-bg: #D1FAE5;
    --status-ready-fg: #065F46;
    --status-issued-bg: #F3F4F6;
    --status-issued-fg: #374151;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    animation: pageFadeIn 0.35s ease-out;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* =========================================================
   Sidebar — dark glass
   ========================================================= */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 256px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.25s ease, width 0.25s ease;
    border-right: 1px solid var(--sidebar-border);
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.sidebar-brand {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar-brand img {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    object-fit: cover;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sidebar-brand span {
    font-size: 16px;
    font-weight: 700;
    color: #F8FAFC;
    letter-spacing: -0.3px;
    transition: opacity 0.2s ease;
}

.sidebar-nav {
    padding: 14px 12px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    margin-bottom: 2px;
    position: relative;
    white-space: nowrap;
}

.sidebar-nav a > span:not(.icon) {
    transition: opacity 0.2s ease;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover-glass);
    color: var(--sidebar-text-hover);
}

.sidebar-nav a:hover .icon svg {
    color: var(--sidebar-icon-hover);
}

.sidebar-nav a.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-fg);
    font-weight: 600;
    box-shadow:
        0 4px 14px rgba(79, 70, 229, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav a.active .icon svg {
    color: var(--sidebar-active-fg);
}

.sidebar-nav a .icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-nav a .icon svg {
    width: 20px;
    height: 20px;
    color: var(--sidebar-icon);
    transition: color 0.15s;
}

.sidebar-nav hr {
    border: none;
    border-top: 1px solid var(--sidebar-border);
    margin: 12px 8px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.2s;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* Tooltips for collapsed sidebar */
.sidebar-nav a[data-tooltip] {
    position: relative;
}

.sidebar-nav a[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(15, 23, 42, 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #F1F5F9;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    z-index: 200;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: tooltipFade 0.15s ease-out;
}

@keyframes tooltipFade {
    from { opacity: 0; transform: translate(-4px, -50%); }
    to   { opacity: 1; transform: translate(0, -50%); }
}

/* =========================================================
   Topbar — white glass
   ========================================================= */

.main {
    margin-left: 256px;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--surface-topbar);
    border-bottom: 1px solid var(--surface-card-border);
    padding: 14px 32px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.sidebar-toggle {
    display: none;
    background: #FFFFFF;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 6px;
    cursor: pointer;
    color: var(--gray-700);
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.sidebar-toggle:active {
    transform: scale(0.96);
}

.sidebar-toggle svg {
    width: 22px;
    height: 22px;
}

.sidebar-collapse-toggle {
    display: inline-flex;
    background: #FFFFFF;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 6px;
    cursor: pointer;
    color: var(--gray-700);
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.sidebar-collapse-toggle:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.sidebar-collapse-toggle:active {
    transform: scale(0.96);
}

.sidebar-collapse-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform 0.25s ease;
}

.topbar h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
    flex: 1;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    padding: 28px 32px;
    flex: 1;
}

/* =========================================================
   Cards — white glass
   ========================================================= */

.card {
    background: var(--surface-card);
    border: 1px solid var(--surface-card-border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
    box-shadow: var(--shadow-glass);
}

.card:hover {
    box-shadow: var(--shadow-glass-lg);
    border-color: #CBD5E1;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--gray-100);
    flex-wrap: wrap;
    gap: 8px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
}

/* =========================================================
   Dashboard stat cards with gradient + glass overlay
   ========================================================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface-card);
    border: 1px solid var(--surface-card-border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: var(--shadow-glass);
    color: #fff;
    cursor: default;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.stat-card::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(120% 80% at 100% 0%, rgba(255, 255, 255, 0.22) 0%, transparent 55%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 100%);
    border-radius: inherit;
}

.stat-card > * {
    position: relative;
    z-index: 1;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-glass-lg);
    border-color: rgba(255, 255, 255, 0.55);
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.stat-card .stat-icon {
    position: absolute;
    top: 18px;
    right: 18px;
    font-size: 24px;
    opacity: 0.4;
    line-height: 1;
    z-index: 1;
}

.stat-card .stat-icon svg {
    width: 28px;
    height: 28px;
    color: #fff;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.2));
}

.stat-card.gradient-primary::before { background: linear-gradient(135deg, #4F46E5 0%, #6366F1 50%, #818CF8 100%); }
.stat-card.gradient-orange::before { background: linear-gradient(135deg, #F59E0B 0%, #F97316 50%, #FB923C 100%); }
.stat-card.gradient-green::before  { background: linear-gradient(135deg, #10B981 0%, #059669 50%, #34D399 100%); }
.stat-card.gradient-blue::before   { background: linear-gradient(135deg, #0EA5E9 0%, #2563EB 50%, #3B82F6 100%); }

.stat-card.gradient-primary:hover { box-shadow: 0 16px 40px rgba(79, 70, 229, 0.32), 0 4px 12px rgba(79, 70, 229, 0.2); }
.stat-card.gradient-orange:hover { box-shadow: 0 16px 40px rgba(245, 158, 11, 0.32), 0 4px 12px rgba(245, 158, 11, 0.2); }
.stat-card.gradient-green:hover  { box-shadow: 0 16px 40px rgba(16, 185, 129, 0.32), 0 4px 12px rgba(16, 185, 129, 0.2); }
.stat-card.gradient-blue:hover   { box-shadow: 0 16px 40px rgba(14, 165, 233, 0.32), 0 4px 12px rgba(14, 165, 233, 0.2); }

/* =========================================================
   Buttons — semi-transparent with glass hover
   ========================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s, color 0.15s;
    text-decoration: none;
    background: #FFFFFF;
    color: var(--gray-700);
    line-height: 1.2;
    white-space: nowrap;
}

.btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #3730A3 100%);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-success { background: linear-gradient(135deg, var(--success) 0%, #059669 100%); border-color: rgba(255,255,255,0.2); color: #fff; box-shadow: 0 2px 6px rgba(16,185,129,0.3); }
.btn-warning { background: linear-gradient(135deg, var(--warning) 0%, #D97706 100%); border-color: rgba(255,255,255,0.2); color: #fff; box-shadow: 0 2px 6px rgba(245,158,11,0.3); }
.btn-danger  { background: linear-gradient(135deg, var(--danger) 0%, #DC2626 100%); border-color: rgba(255,255,255,0.2); color: #fff; box-shadow: 0 2px 6px rgba(239,68,68,0.3); }
.btn-info    { background: linear-gradient(135deg, var(--info) 0%, #0284C7 100%); border-color: rgba(255,255,255,0.2); color: #fff; box-shadow: 0 2px 6px rgba(14,165,233,0.3); }

.btn-success:hover { background: linear-gradient(135deg, #059669 0%, #047857 100%); color: #fff; }
.btn-warning:hover { background: linear-gradient(135deg, #D97706 0%, #B45309 100%); color: #fff; }
.btn-danger:hover  { background: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%); color: #fff; }
.btn-info:hover    { background: linear-gradient(135deg, #0284C7 0%, #0369A1 100%); color: #fff; }

/* =========================================================
   Tables — semi-transparent rows inside glass cards
   ========================================================= */

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

table th {
    text-align: left;
    padding: 12px 14px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-600);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 14px;
    color: var(--gray-700);
}

table tbody tr {
    transition: background 0.15s ease;
}

table tbody tr:hover td {
    background: var(--surface-row-hover);
}

table tbody tr:nth-child(even) td {
    background: var(--surface-row-alt);
}

table tbody tr:nth-child(even):hover td {
    background: var(--surface-row-hover);
}

table tbody tr:last-child td {
    border-bottom: none;
}

.card table {
    border-radius: var(--radius);
    overflow: hidden;
}

/* =========================================================
   Search & Forms
   ========================================================= */

.search-box {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-box input {
    padding: 9px 14px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    width: 260px;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    background: #FFFFFF;
    color: var(--gray-800);
}

.search-box input:focus {
    border-color: var(--primary);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    background: #FFFFFF;
    color: var(--gray-800);
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.form-group textarea {
    min-height: 90px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* =========================================================
   Badges & Status pills — glass
   ========================================================= */

.badge {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-primary { background: #EEF2FF; color: #4338CA; border-color: #E0E7FF; }
.badge-success { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }
.badge-warning { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }
.badge-danger  { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
.badge-info    { background: #E0F2FE; color: #075985; border-color: #BAE6FD; }
.badge-gray    { background: #F1F5F9; color: #475569; border-color: #E2E8F0; }

/* CRM-specific status pills */
.badge-inwork, .status-inwork { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }
.badge-ready,  .status-ready  { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }
.badge-issued, .status-issued { background: #F1F5F9; color: #475569; border-color: #E2E8F0; }

/* =========================================================
   Pagination
   ========================================================= */

.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.pagination a {
    padding: 7px 13px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--gray-600);
    font-size: 14px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    background: #FFFFFF;
}

.pagination a:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
    color: var(--gray-800);
}

.pagination a.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

/* =========================================================
   Alerts
   ========================================================= */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}

.alert-success { background: #D1FAE5; color: #166534; border-color: #A7F3D0; }
.alert-danger  { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
.alert-info    { background: #E0F2FE; color: #075985; border-color: #BAE6FD; }

/* =========================================================
   Utility
   ========================================================= */

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.font-semibold { font-weight: 600; }
.text-sm { font-size: 13px; }

.order-services-list { list-style: none; }

.order-services-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.cat-tree-wrapper { position: relative; }
.cat-tree-dropdown {
    position: absolute; top: 100%; left: 0; z-index: 200;
    background: #FFFFFF;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-glass-lg);
    min-width: 320px;
    max-width: 480px;
}
.cat-tree-search { padding: 8px; border-bottom: 1px solid var(--gray-100); }
.cat-tree-search input { width: 100%; padding: 6px 8px; border: 1px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 13px; outline: none; background: #FFFFFF; }
.cat-tree-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.12); }
.cat-tree-scroll { max-height: 400px; overflow-y: auto; padding: 4px 0; }
.cat-tree-item {
    display: block; padding: 4px 8px 4px 4px; font-size: 13px; color: var(--gray-700);
    text-decoration: none; border-radius: 4px; white-space: nowrap;
}
.cat-tree-item:hover { background: var(--gray-50); }
.cat-tree-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.cat-tree-root { padding: 6px 12px; margin: 0 4px 4px; font-weight: 600; font-size: 13px; }
.cat-tree-row { display: flex; align-items: center; gap: 2px; padding: 1px 12px 1px 4px; }
.cat-tree-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; font-size: 8px; cursor: pointer; color: var(--gray-400);
    transition: transform 0.15s; flex-shrink: 0;
}
.cat-tree-toggle:hover { color: var(--gray-600); }
.cat-tree-toggle.collapsed { transform: rotate(-90deg); }
.cat-tree-toggle-empty { visibility: hidden; }
.cat-tree-label {
    display: inline-block; padding: 4px 8px; font-size: 13px; font-weight: 600; color: var(--gray-500);
}
.cat-tree-children { padding-left: 16px; }
.cat-tree-children.collapsed { display: none; }

/* =========================================================
   Sidebar collapsed state (tablet)
   ========================================================= */

body.sidebar-collapsed .sidebar {
    width: 64px;
}
body.sidebar-collapsed .main {
    margin-left: 64px;
}
body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .sidebar-nav a > span:not(.icon) {
    opacity: 0;
    width: 0;
    pointer-events: none;
}
body.sidebar-collapsed .sidebar-nav {
    padding: 14px 8px;
}
body.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    padding: 10px;
    gap: 0;
}
body.sidebar-collapsed .sidebar-nav hr {
    margin: 8px 4px;
}
body.sidebar-collapsed .sidebar-collapse-toggle svg {
    transform: rotate(180deg);
}

/* =========================================================
   Print
   ========================================================= */


/* =========================================================
   Mobile Stats Dashboard (<=768px)
   ========================================================= */

.mobile-stats {
    display: none;
}

.mobile-stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.mobile-stat-card {
    background: var(--surface-card);
    border: 1px solid var(--surface-card-border);
    border-radius: var(--radius);
    padding: 10px 8px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.mobile-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.mobile-stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

.desktop-stats {
    /* always visible on desktop */
}

.hide-mobile {
    /* hidden on mobile via media query below */
}

@media print {
    body {
        background: #fff !important;
    }
    .sidebar, .topbar, .sidebar-collapse-toggle, .no-print { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    .card { background: #fff !important; border: 1px solid #ccc !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
    .stat-card { background: #f5f5f5 !important; color: #000 !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
    .stat-card::before, .stat-card::after { display: none !important; }
    .stat-card .stat-value, .stat-card .stat-label { color: #000 !important; text-shadow: none !important; }
    .btn, .badge, .alert { background: #fff !important; color: #000 !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
    .btn-primary { color: #fff !important; background: #4F46E5 !important; }
    table th, table td { background: transparent !important; }
}

/* =========================================================
   Responsive — Tablet (768–1024): collapsed icon-only sidebar
   ========================================================= */

@media (max-width: 1024px) and (min-width: 769px) {
    body:not(.sidebar-mobile-open) .sidebar {
        width: 64px;
    }
    body:not(.sidebar-mobile-open) .main {
        margin-left: 64px;
    }
    body:not(.sidebar-mobile-open) .sidebar-brand span,
    body:not(.sidebar-mobile-open) .sidebar-nav a > span:not(.icon) {
        opacity: 0;
        width: 0;
        pointer-events: none;
    }
    body:not(.sidebar-mobile-open) .sidebar-nav {
        padding: 14px 8px;
    }
    body:not(.sidebar-mobile-open) .sidebar-nav a {
        justify-content: center;
        padding: 10px;
        gap: 0;
    }
    body:not(.sidebar-mobile-open) .sidebar-nav hr {
        margin: 8px 4px;
    }
}

/* =========================================================
   Responsive — Mobile (<=768px): off-canvas sidebar
   ========================================================= */

@media (max-width: 768px) {
    /* Mobile stats: show compact block, hide desktop grid */
    .mobile-stats { display: block; margin-bottom: 16px; }
    .desktop-stats { display: none; }
    .hide-mobile { display: none !important; }

    /* Table: horizontal scroll with touch, no overflow hidden.
       Keep table-scroll flush to card padding so its scrollbar reaches the edge. */
    .table-scroll {
        margin: 0 -16px;
        padding: 0 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    .card {
        overflow-x: hidden;
    }
    .card > .table-scroll {
        margin: 0;
        padding: 0;
    }
    table {
        min-width: 700px;
    }
    table th, table td {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 7px 5px;
    }
    table th:last-child, table td:last-child {
        padding-right: 16px;
    }

    body, .main { margin-left: 0; }
    .sidebar {
        transform: translateX(-100%);
        width: 256px;
    }
    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }
    body.sidebar-mobile-open .sidebar-brand span,
    body.sidebar-mobile-open .sidebar-nav a > span:not(.icon) {
        opacity: 1;
        width: auto;
        pointer-events: auto;
    }
    body.sidebar-mobile-open .sidebar-nav {
        padding: 14px 12px;
    }
    body.sidebar-mobile-open .sidebar-nav a {
        justify-content: flex-start;
        padding: 10px 12px;
        gap: 12px;
    }
    body.sidebar-mobile-open .sidebar-nav hr {
        margin: 12px 8px;
    }
    .sidebar-toggle { display: inline-flex; }
    .sidebar-collapse-toggle { display: none; }
    .content { padding: 20px 16px; }
    .topbar { padding: 12px 16px; }
    .topbar h1 { font-size: 16px; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }

    /* Search box: wrap vertically on mobile */
    .flex-between {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    .flex-between > * {
        min-width: 0;
        max-width: 100%;
    }
    .flex-between .search-box {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }
    .flex-between .search-box > * {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
    }
    .flex-between .search-box input[type="text"] {
        width: 100%;
        min-width: 0;
        flex: 1 1 100%;
    }
    .flex-between .search-box select {
        max-width: 100%;
        flex: 1 1 100%;
    }
    .flex-between .search-box .cat-tree-wrapper {
        flex: 1 1 100%;
        max-width: 100%;
    }
    .flex-between .search-box .cat-tree-wrapper > button {
        width: 100%;
        max-width: 100%;
    }
    .flex-between > .flex {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }
    .flex-between > .flex .btn {
        flex: 1 1 auto;
        text-align: center;
        min-width: calc(50% - 4px);
    }
    .search-box input { width: 100%; min-width: 0; }
    .search-box { flex: 1; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .card { padding: 18px 16px; }
    .card-header { margin-bottom: 14px; padding-bottom: 12px; }

    /* Dashboard action buttons row should wrap and breathe */
    .flex.gap-4.mb-6 {
        flex-wrap: wrap;
        gap: 8px;
    }
    .flex.gap-4.mb-6 > .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 4px);
        text-align: center;
        justify-content: center;
    }

/* JS-injected dashboard status card — desktop default (overridden on mobile below) */
.stats-status-card {
    margin-top: 8px;
}

    /* JS-injected status card on dashboard: clear top margin */
    .stats-status-card {
        margin-top: 16px;
    }

    /* Direct button child of .flex-between (e.g. "Add new" link with no flex wrapper)
       should be a normal-sized button, not stretched full-width. */
    .flex-between > a.btn,
    .flex-between > .btn {
        align-self: flex-start;
        flex: 0 0 auto;
        max-width: 100%;
    }
    /* But on very small screens, make it full-width for easy tapping. */
    /* (handled in 480 breakpoint) */

    /* Cat-tree dropdown: shrink to viewport on small screens. */
    .cat-tree-dropdown {
        min-width: 0;
        max-width: calc(100vw - 32px);
    }
}

@media (max-width: 768px) {
    /* Analytics: grid-2 becomes single column */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* Analytics: stat cards grid — already auto-fit, just reduce min */
    [style*="grid-template-columns:repeat(auto-fit"],
    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr 1fr !important;
    }
    /* Analytics: date filter form */
    form.flex.gap-2.mb-4 {
        flex-wrap: wrap;
        gap: 8px;
    }
    form.flex.gap-2.mb-4 > div {
        flex: 1 1 calc(50% - 4px);
        min-width: 140px;
    }
    form.flex.gap-2.mb-4 > div input,
    form.flex.gap-2.mb-4 > div label {
        width: 100%;
    }
    form.flex.gap-2.mb-4 button {
        flex: 1 1 100%;
    }
}

@media (max-width: 480px) {
    .mobile-stat-value { font-size: 18px; }
    .mobile-stat-label { font-size: 10px; }

    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 18px 20px; }
    .stat-card .stat-value { font-size: 24px; }
    .content { padding: 16px 12px; }
    .topbar { padding: 10px 12px; gap: 10px; }
    .topbar h1 { font-size: 15px; }
    .topbar-actions .text-sm { font-size: 12px; }
    .card { padding: 16px 14px; border-radius: var(--radius); }
    table { min-width: 600px; }
    table th, table td { font-size: 0.75rem; padding: 6px 4px; }
    /* Analytics: stat cards 1 column on very small screens */
    [style*="grid-template-columns:repeat(auto-fit"],
    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }
    /* Analytics: date filter full width */
    form.flex.gap-2.mb-4 > div {
        flex: 1 1 100%;
        min-width: 0;
    }

    /* Dashboard action buttons: stack vertically on very small screens */
    .flex.gap-4.mb-6 > .btn {
        flex: 1 1 100%;
        min-width: 0;
    }
    /* Stats-status card (JS-injected) tighter on small screens */
    .stats-status-card {
        margin-top: 12px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
