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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1a252f 0%, #2c3e50 100%);
    color: white;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    box-shadow: 4px 0 15px rgba(0,0,0,0.3);
    flex-shrink: 0;
    position: relative;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 8px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: #34495e;
    border-radius: 4px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background: #3498db;
}

.sidebar-header {
    background: #1a252f;
    padding: 20px 15px;
    border-bottom: 3px solid #3498db;
    flex-shrink: 0;
}

.sidebar-header .logo {
    text-align: center;
}

.sidebar-header .logo h2 {
    font-size: 18px;
    color: #ecf0f1;
    line-height: 1.3;
    margin: 0;
    font-weight: 700;
    letter-spacing: 1px;
}

.sidebar-header .logo p {
    font-size: 11px;
    color: #7f8c8d;
    margin: 5px 0 0 0;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: #34495e;
    border-radius: 3px;
}

.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: 15px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
    z-index: 101;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,0.2);
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.menu-category {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #7f8c8d;
    padding: 15px 20px 10px 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.menu-category:hover {
    color: #ecf0f1;
    background: rgba(52, 152, 219, 0.1);
    border-left-color: #3498db;
}

.menu-group {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.1);
    margin: 0 10px;
    border-radius: 6px;
    overflow: hidden;
}

.menu-group .menu-item {
    padding: 10px 15px 10px 35px;
    font-size: 13px;
    border-left: none;
}

.menu-group .menu-item:hover {
    background: rgba(255,255,255,0.05);
    padding-left: 40px;
}

.sidebar-footer {
    background: #1a252f;
    padding: 15px;
    border-top: 1px solid #34495e;
    flex-shrink: 0;
    text-align: center;
}

.sidebar-footer p {
    font-size: 11px;
    color: #7f8c8d;
    margin: 0;
}

.sidebar-footer .version {
    font-size: 10px;
    color: #95a5a6;
    margin-top: 5px;
}

/* Collapsed Sidebar State */
body.sidebar-collapsed .sidebar {
    width: 60px;
}

body.sidebar-collapsed .sidebar-header .logo h2,
body.sidebar-collapsed .sidebar-header .logo p {
    display: none;
}

body.sidebar-collapsed .menu-category {
    font-size: 9px;
    padding: 12px 5px;
    justify-content: center;
}

body.sidebar-collapsed .menu-category span:first-child {
    display: none;
}

body.sidebar-collapsed .menu-group {
    display: none !important;
}

body.sidebar-collapsed .menu-item {
    padding: 10px 5px;
    font-size: 10px;
    text-align: center;
}

body.sidebar-collapsed .sidebar-footer {
    display: none;
}

.menu-item {
    display: block;
    padding: 10px 15px;
    color: #bdc3c7;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-item:hover {
    color: #ecf0f1;
    background: rgba(255,255,255,0.05);
    border-left-color: #3498db;
}

.menu-item.active {
    color: #ecf0f1;
    background: rgba(255,255,255,0.1);
    border-left-color: #3498db;
}

.page-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.main-content {
    flex: 1;
    padding: 20px;
    background: #f5f6fa;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.main-content::-webkit-scrollbar {
    width: 10px;
}

.main-content::-webkit-scrollbar-track {
    background: #ecf0f1;
}

.main-content::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 5px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

.topbar {
    background-color: white;
    padding: 15px 25px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar h1 {
    font-size: 1.5rem;
    color: #2c3e50;
}

.user-info {
    color: #7f8c8d;
}

.content {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
}

.card {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.3s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

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

.form-group label {
    display: block;
    margin-bottom: 3px;
    font-weight: 500;
    color: #2c3e50;
    font-size: 13px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    white-space: nowrap;
}

th.sortable:hover {
    background-color: #e9ecef;
}

.sort-icon {
    font-size: 12px;
    margin-left: 5px;
    color: #7f8c8d;
    display: inline;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.stat-card h4 {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.stat-card .number {
    font-size: 2rem;
    font-weight: bold;
    color: #2c3e50;
}

/* ===============================
   RESPONSIVE / MOBILE FRIENDLY
   =============================== */

/* Allow body to scroll naturally on mobile only (desktop keeps overflow:hidden) */
html, body {
    height: 100%;
    overflow-x: hidden;
}

.page-container {
    min-height: 100vh;
}

/* Mobile overlay backdrop */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 998;
}

body.sidebar-open .mobile-overlay {
    display: block;
}

/* Mobile hamburger in topbar */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: #2c3e50;
    cursor: pointer;
    padding: 4px 10px;
    margin-right: 10px;
    border-radius: 4px;
}

.mobile-menu-btn:hover {
    background: #ecf0f1;
}

/* ---------- Tablet (max-width: 1024px) ---------- */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    .main-content {
        padding: 15px;
    }
    .content {
        padding: 15px;
    }
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }
}

/* ---------- Mobile (max-width: 768px) ---------- */
@media (max-width: 768px) {
    body {
        overflow: visible;
        overflow-x: hidden;
    }

    .mobile-menu-btn {
        display: inline-block;
    }

    /* Sidebar becomes slide-out overlay */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 260px;
        height: 100vh;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.4);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-collapsed .sidebar {
        width: 260px;
        transform: translateX(-100%);
    }

    body.sidebar-collapsed.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-collapsed .menu-category span:first-child,
    body.sidebar-collapsed .menu-group,
    body.sidebar-collapsed .sidebar-footer,
    body.sidebar-collapsed .sidebar-header .logo h2,
    body.sidebar-collapsed .sidebar-header .logo p {
        display: initial !important;
    }

    body.sidebar-collapsed .menu-group {
        display: flex !important;
    }

    body.sidebar-collapsed .menu-item {
        padding: 10px 15px !important;
        font-size: 14px !important;
        text-align: left !important;
    }

    body.sidebar-collapsed .menu-category {
        font-size: 12px !important;
        padding: 15px 20px 10px 20px !important;
        justify-content: flex-start !important;
    }

    .page-container {
        display: block;
        height: auto;
        overflow: visible;
    }

    .main-content {
        padding: 10px;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .topbar {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .topbar h1 {
        font-size: 1.1rem;
    }

    .content {
        padding: 10px 0;
    }

    .card {
        padding: 12px;
        margin-bottom: 12px;
        border-radius: 6px;
    }

    .card h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    /* Forms: single column (catches 1fr 1fr and 1fr 1fr 1fr layouts) */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* prevent iOS zoom */
        padding: 8px 10px;
    }

    /* ========== TABLES: VERTICAL CARDS (no horizontal scroll) ========== */
    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        margin-bottom: 10px;
        padding: 10px;
        background: #fff;
    }

    td {
        border: none;
        border-bottom: 1px solid #f0f0f0;
        position: relative;
        padding: 8px 0 8px 40%;
        text-align: right !important;
        min-height: 36px;
    }

    td:last-child {
        border-bottom: none;
    }

    td::before {
        position: absolute;
        top: 8px;
        left: 8px;
        width: 35%;
        text-align: left;
        font-weight: 600;
        color: #2c3e50;
        content: attr(data-label);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Buttons: bigger tap targets */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 15px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card h4 {
        font-size: 0.75rem;
    }

    .stat-card .number {
        font-size: 1.4rem;
    }
}

/* ---------- Small Mobile (max-width: 480px) ---------- */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: 8px 10px;
    }

    .topbar h1 {
        font-size: 1rem;
    }

    .card {
        padding: 10px;
        margin-bottom: 10px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Tighter table cards on small screens */
    tr {
        padding: 8px;
        margin-bottom: 8px;
    }

    td {
        padding: 6px 0 6px 40%;
        font-size: 13px;
    }

    td::before {
        top: 6px;
        left: 6px;
        font-size: 12px;
    }
}

/* Touch-friendly general improvements */
input, select, textarea, button, a {
    touch-action: manipulation;
}

a, button {
    -webkit-tap-highlight-color: transparent;
}
