/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3a4555;
    --primary-hover: #252d3a;
    --secondary-color: #5a6878;
    --success-color: #2d7a50;
    --danger-color: #a53535;
    --warning-color: #b56620;
    --bg-color: #252d3a;
    --sidebar-bg: #1a1f2c;
    --sidebar-text: #b5bdc8;
    --card-bg: #2f3947;
    --text-color: #d2d8e0;
    --text-muted: #8a95a5;
    --border-color: #3a4555;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 12.8px; /* 16px * 0.8 */
}

/* Container Layout */
.container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 0.8rem;
    left: 0.8rem;
    z-index: 1001;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.6rem 0.8rem;
    border-radius: 0.4rem;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: background 0.3s;
}

.menu-toggle:hover {
    background: var(--primary-hover);
}

/* Sidebar */
.sidebar {
    width: 224px; /* 280px * 0.8 */
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.2rem;
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    margin-bottom: 1.6rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
    font-size: 1.2rem; /* 1.5rem * 0.8 */
    margin-bottom: 0.4rem;
    color: #fff;
}

.user-info {
    font-size: 0.7rem; /* 0.875rem * 0.8 */
    color: var(--sidebar-text);
    display: block;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.nav-item {
    display: block;
    padding: 0.4rem 0.6rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.3rem;
    transition: all 0.2s;
    font-size: 0.7rem; /* 0.875rem * 0.8 */
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-item.active {
    background: var(--primary-color);
    color: #fff;
}

.nav-item.nav-action {
    background: var(--success-color);
    color: #fff;
    margin-top: 0.8rem;
}

.nav-item.nav-action:hover {
    background: #2d7a50;
}

.nav-item.nav-logout {
    background: var(--danger-color);
    color: #fff;
    margin-top: auto;
}

.nav-item.nav-logout:hover {
    background: #a33535;
}

.nav-section {
    margin: 0.8rem 0;
}

.nav-section h3 {
    font-size: 0.7rem; /* 0.875rem * 0.8 */
    color: var(--sidebar-text);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    font-weight: 600;
    opacity: 0.7;
}

.pages-tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.pages-tree li {
    margin: 0;
}

.pages-tree .nav-item {
    padding-left: 0.8rem;
    font-size: 0.72rem; /* 0.9rem * 0.8 */
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 224px; /* 280px * 0.8 */
    padding: 1.6rem;
    min-height: 100vh;
}

.page-content {
    max-width: 960px; /* 1200px * 0.8 */
    margin: 0 auto;
    background: var(--card-bg);
    padding: 1.6rem;
    border-radius: 0.4rem;
    box-shadow: var(--shadow);
}

.page-header {
    margin-bottom: 1.6rem;
    padding-bottom: 0.8rem;
    border-bottom: 2px solid var(--border-color);
}

.page-header h1 {
    font-size: 1.6rem; /* 2rem * 0.8 */
    margin-bottom: 0.4rem;
    color: var(--text-color);
}

.page-meta {
    font-size: 0.7rem; /* 0.875rem * 0.8 */
    color: var(--text-muted);
}

.page-body {
    font-size: 0.8rem; /* 1rem * 0.8 */
    line-height: 1.8;
    margin-bottom: 1.6rem;
    color: var(--text-color);
}

.page-actions {
    display: flex;
    gap: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--border-color);
}

/* Welcome Page */
.welcome {
    text-align: center;
    padding: 2.4rem 0.8rem;
}

.welcome h1 {
    font-size: 2rem; /* 2.5rem * 0.8 */
    margin-bottom: 0.8rem;
    color: var(--text-color);
}

.welcome p {
    font-size: 0.9rem; /* 1.125rem * 0.8 */
    color: var(--text-muted);
    margin-bottom: 1.6rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); /* 200px * 0.8 */
    gap: 1.2rem;
    margin-top: 1.6rem;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    padding: 1.6rem;
    border-radius: 0.4rem;
    box-shadow: var(--shadow-lg);
}

.stat-card h3 {
    font-size: 2.4rem; /* 3rem * 0.8 */
    margin-bottom: 0.4rem;
}

.stat-card p {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 0.3rem;
    font-size: 0.8rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: #2f3947;
    color: #d2d8e0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 96px; /* 120px * 0.8 */
}

.form-help {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* 250px * 0.8 */
    gap: 1.2rem;
}

.form-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 1.6rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 0.4rem;
    font-size: 0.7rem; /* 0.875rem * 0.8 */
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-edit {
    background: #9d6020;
    color: white;
}

.btn-edit:hover {
    background: #8d5518;
}

.btn-delete {
    background: #8d3030;
    color: white;
}

.btn-delete:hover {
    background: #7d2828;
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.7rem;
}

/* Alerts */
.alert {
    padding: 0.8rem;
    border-radius: 0.3rem;
    margin-bottom: 1.2rem;
    font-weight: 500;
}

.alert-success {
    background: #1a3d2a;
    color: #8fdfb0;
    border: 1px solid #2d5a40;
}

.alert-error {
    background: #4a2020;
    color: #f0a0a0;
    border: 1px solid #702020;
}

/* Auth Page */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #556eaa 0%, #665a92 100%);
}

.auth-container {
    width: 100%;
    max-width: 320px; /* 400px * 0.8 */
    padding: 0.8rem;
}

.auth-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 0.8rem;
    box-shadow: var(--shadow-lg);
}

.auth-card h1 {
    font-size: 1.6rem; /* 2rem * 0.8 */
    margin-bottom: 0.4rem;
    text-align: center;
    color: var(--text-color);
}

.auth-card h2 {
    font-size: 1.2rem; /* 1.5rem * 0.8 */
    margin-bottom: 1.6rem;
    text-align: center;
    color: var(--text-muted);
}

.auth-footer {
    margin-top: 1.2rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Admin Section */
.admin-section {
    margin-bottom: 2.4rem;
    padding-bottom: 1.6rem;
    border-bottom: 1px solid var(--border-color);
}

.admin-section:last-child {
    border-bottom: none;
}

.admin-section h2 {
    font-size: 1.2rem; /* 1.5rem * 0.8 */
    margin-bottom: 1.2rem;
    color: var(--text-color);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.8rem;
}

.users-table th,
.users-table td {
    padding: 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.users-table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--text-color);
}

.users-table tr:hover {
    background: var(--bg-color);
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 0.8rem;
    font-size: 0.6rem; /* 0.75rem * 0.8 */
    font-weight: 600;
}

.badge-admin {
    background: #2a4a6a;
    color: #8fb8e0;
}

.badge-user {
    background: #3a4555;
    color: #b5bdc8;
}

.text-muted {
    color: var(--text-muted);
}

/* Responsive Design */
@media (max-width: 768px) {
    .menu-toggle {
        display: block;
        position: fixed;
        top: 0.5rem;
        left: 0.5rem;
        z-index: 1002;
        font-size: 1.2rem;
        padding: 0.5rem 0.7rem;
    }
    
    .sidebar {
        transform: translateX(-100%);
        width: 75%;
        max-width: 280px;
    }
    
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }
    
    .main-content {
        margin-left: 0;
        padding: 3.5rem 0.5rem 0.5rem;
    }
    
    .page-content {
        padding: 1rem;
    }
    
    .page-header h1 {
        font-size: 1.1rem;
    }
    
    .welcome h1 {
        font-size: 1.3rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        padding: 0.6rem 1rem;
        font-size: 0.75rem;
    }
    
    .page-actions {
        flex-direction: column;
    }
    
    .users-table {
        font-size: 0.65rem;
    }
    
    .users-table th,
    .users-table td {
        padding: 0.3rem;
    }
    
    /* Financial table mobile optimization */
    .table-container {
        padding: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .financial-table {
        width: 100%;
        font-size: 0.6rem;
        table-layout: auto;
    }
    
    .financial-table th,
    .financial-table td {
        padding: 0.3rem 0.2rem;
        font-size: 0.6rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 80px;
    }
    
    .financial-table td:first-child,
    .financial-table th:first-child {
        max-width: 60px;
    }
    
    .financial-table input[type="number"],
    .financial-table input[type="text"],
    .financial-table input[type="date"] {
        width: 100%;
        font-size: 0.6rem;
        padding: 0.2rem;
    }
    
    .table-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .table-actions .btn {
        width: 100%;
        font-size: 0.7rem;
        padding: 0.5rem;
    }
    
    .sheets-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }
    
    .sheet-tab {
        padding: 0.4rem 0.8rem;
        font-size: 0.7rem;
        min-width: fit-content;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card h3 {
        font-size: 1.5rem;
    }
    
    .sheet-table {
        font-size: 0.6rem;
    }
    
    .sheet-table th,
    .sheet-table td {
        padding: 0.4rem 0.3rem;
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 1rem;
        margin: 0.5rem;
    }
    
    .auth-card h1 {
        font-size: 1.8rem !important;
    }
    
    .stat-card h3 {
        font-size: 1.3rem;
    }
    
    .stat-card p {
        font-size: 0.7rem;
    }
    
    body {
        font-size: 10px;
    }
    
    .sidebar {
        width: 85%;
        max-width: 250px;
    }
    
    .sidebar-header h2 {
        font-size: 1rem;
    }
    
    .nav-item {
        padding: 0.4rem 0.5rem;
        font-size: 0.65rem;
    }
    
    .time-display {
        font-size: 0.55rem;
    }
    
    /* Hide less important columns on very small screens */
    .financial-table td:nth-last-child(2),
    .financial-table th:nth-last-child(2) {
        display: none;
    }
    
    /* Make scrollable area more obvious */
    .table-container {
        border: 1px solid #4a5568;
        position: relative;
    }
    
    .table-container::after {
        content: "← Scroll →";
        position: absolute;
        bottom: 0;
        right: 0;
        background: #4a5568;
        color: #8a95a5;
        padding: 0.2rem 0.5rem;
        font-size: 0.5rem;
        border-radius: 0.3rem 0 0 0;
    }
    
    /* Overlay for sidebar */
    .sidebar.active::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .btn, .nav-item, .sheet-tab {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .paid-checkbox {
        width: 20px;
        height: 20px;
    }
    
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    select {
        min-height: 40px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}
