* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f5f7fa;
    color: #2c3e50;
}

.page {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* Login */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #2c3e50;
}

#loginForm {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

input, select {
    padding: 12px;
    border: 2px solid #e0e6ed;
    border-radius: 8px;
    font-size: 14px;
}

input:focus, select:focus {
    outline: none;
    border-color: #3498db;
}

button {
    padding: 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
}

button:hover {
    background: #2980b9;
}

.error {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
}

/* Dashboard */
nav {
    background: white;
    padding: 20px 40px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav h1 {
    font-size: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.container {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 40px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.stat-card h3 {
    font-size: 14px;
    color: #7f8c8d;
    margin-bottom: 10px;
    font-weight: 500;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: #2c3e50;
}

/* Prices */
.price-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.price-box {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}

.price-label {
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 8px;
    text-transform: uppercase;
    font-weight: 600;
}

.price-value {
    font-size: 28px;
    font-weight: 700;
    color: #2c3e50;
}

.price-value.green {
    color: #27ae60;
}

.price-value.red {
    color: #e74c3c;
}

.chart-container {
    position: relative;
    height: 300px;
    margin-top: 20px;
}

/* Control Panel */
.control-panel {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 40px;
}

.control-panel h2 {
    font-size: 18px;
    margin-bottom: 20px;
}

.control-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.btn-success {
    background: #27ae60;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-warning {
    background: #f39c12;
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
}

.btn-primary {
    background: #3498db;
}

.btn-primary:hover {
    background: #2980b9;
}

.status-message {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    font-size: 14px;
}

.status-message.success {
    background: #d4edda;
    color: #155724;
}

.status-message.error {
    background: #f8d7da;
    color: #721c24;
}

/* Filters */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.filter-grid input[type="text"] {
    grid-column: 1 / -1;
}

.filter-grid input,
.filter-grid select,
.filter-grid button {
    width: 100%;
}

/* Table */
.table-container {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    overflow-x: auto;
}

.table-container h2 {
    font-size: 18px;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #f8f9fa;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: #7f8c8d;
}

td {
    padding: 15px;
    border-top: 1px solid #e0e6ed;
    font-size: 14px;
}

tr:hover {
    background: #f8f9fa;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active {
    background: #d4edda;
    color: #155724;
}

.badge-inactive {
    background: #f8d7da;
    color: #721c24;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.action-buttons {
    display: flex;
    gap: 5px;
}

/* Form Container */
.form-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.form-header h2 {
    margin: 0;
}

.btn-close {
    background: #e74c3c;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    padding: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
    color: #2c3e50;
}

.form-group input,
.form-group select {
    width: 100%;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.form-actions button {
    flex: 1;
}

.price-value.small {
    font-size: 18px;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* Modal - Fixed positioning */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 1px solid #e0e6ed;
    background: #f8f9fa;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #2c3e50;
}

.modal-header .close {
    font-size: 28px;
    font-weight: 700;
    color: #7f8c8d;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-header .close:hover {
    background: #e74c3c;
    color: white;
}

.modal-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Relay Card */
.relay-card {
    background: #f8f9fa;
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.relay-card h4 {
    margin: 0 0 10px 0;
    color: #2c3e50;
}

/* Status badges */
.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status.active {
    background: #d4edda;
    color: #155724;
}

.status.inactive {
    background: #f8d7da;
    color: #721c24;
}
/* Navigation Links */
.nav-links {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.nav-links a {
    color: #666;
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.nav-links a:hover {
    color: #2563eb;
    background: #f0f7ff;
}

.nav-links a.active {
    color: #2563eb;
    background: #e0f0ff;
    font-weight: 600;
}

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

/* Tablet (768px and below) */
@media (max-width: 768px) {
    nav {
        flex-direction: column;
        padding: 15px;
        gap: 10px;
    }
    
    nav h1 {
        font-size: 16px;
    }
    
    .nav-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
        max-width: 100%;
        overflow: hidden;
    }
    
    .nav-links a {
        font-size: 11px;
        padding: 6px 8px;
        white-space: nowrap;
    }
    
    .user-info {
        flex-direction: row;
        gap: 10px;
    }
    
    .container {
        padding: 0 10px;
        margin: 15px auto;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .price-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .price-value {
        font-size: 18px;
    }
    
    .control-panel {
        padding: 15px;
    }
    
    .control-buttons {
        flex-direction: column;
    }
    
    .filter-grid {
        grid-template-columns: 1fr;
    }
    
    .table-container {
        padding: 10px;
        overflow-x: auto;
    }
    
    th, td {
        padding: 8px 5px;
        font-size: 11px;
    }
    
    .form-container {
        width: 95%;
        padding: 15px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .chart-container {
        height: 220px;
    }
}

/* Phone (480px and below) */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    
    .login-container {
        margin: 30px 10px;
        padding: 20px;
    }
    
    .login-container h1 {
        font-size: 16px;
    }
    
    nav {
        padding: 10px;
    }
    
    nav h1 {
        font-size: 14px;
        text-align: center;
    }
    
    .nav-links {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
        width: 100%;
    }
    
    .nav-links a {
        font-size: 10px;
        padding: 8px 4px;
        text-align: center;
        border-radius: 4px;
        background: #f0f7ff;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-card h3 {
        font-size: 12px;
    }
    
    .price-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .price-value {
        font-size: 16px;
    }
    
    .user-info {
        width: 100%;
        justify-content: center;
    }
    
    #logoutBtn, #currentUser {
        font-size: 12px;
    }
    
    th, td {
        padding: 6px 3px;
        font-size: 10px;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 3px;
    }
    
    .btn-small {
        padding: 6px;
        font-size: 10px;
    }
    
    .chart-container {
        height: 180px;
    }
    
    .control-panel h2, .table-container h2, .section-header h2 {
        font-size: 16px;
    }
}

/* Touch-friendly buttons for mobile */
@media (hover: none) and (pointer: coarse) {
    button, .btn-small, .nav-links a {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Prevent horizontal scroll */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
