:root {
    --bg-color: #f1f5f9;
    --sidebar-bg: #fff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --primary: #166534;
    --primary-hover: #15803d;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --border: #e2e8f0;
    --card-bg: #ffffff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

img { max-width: 100%; }
button, input, textarea { font: inherit; }

.section { display: none; min-height: 100vh; }
.active-section { display: flex; }

/* Login */
#loginSection {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
}

.login-card {
    background: white;
    padding: 3rem;
    border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 1rem;
}

input:focus { outline: none; border-color: var(--primary); }

.btn {
    padding: 0.8rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.btn:hover { background: var(--primary-hover); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }

.outline-btn { background: transparent; color: var(--text-color); border: 1px solid var(--border); }
.outline-btn:hover { background: #f8fafc; }

/* Layout */
.layout { display: flex; width: 100%; }

.sidebar {
    width: 250px;
    flex: 0 0 250px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.logo {
    padding: 2rem 1.5rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.nav-links {
    list-style: none;
    padding: 1.5rem 0;
    flex: 1;
}

.nav-links li {
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.nav-links li:hover { background: #f8fafc; color: var(--text-color); }

.nav-links li.active {
    background: #eef2ff;
    color: var(--primary);
    border-left-color: var(--primary);
}

.bottom-nav {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
}

.user-info { font-size: 0.9rem; margin-bottom: 1rem; font-weight: 600; display:flex; justify-content:space-between; align-items:center}
.link-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; text-decoration: underline; }

.content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    height: 100dvh;
}

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.active-tab { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* Dashboard */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
}

.stat-card h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 600;}
.stat-value { font-size: 2.5rem; font-weight: 800; color: var(--primary); }

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 1000px) {
    .charts-container { grid-template-columns: 1fr; }
}

.chart-wrapper {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Table */
.table-container {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th { background: #f8fafc; font-weight: 600; color: var(--text-muted); font-size: 0.9rem; }
td { font-size: 0.95rem; }

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.settings-card {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.settings-card h3 { margin-bottom: 1.5rem; font-size: 1.2rem; }

.reset-card {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.reset-card h3 { color: var(--danger); }
.reset-card p { margin-bottom: 1rem; font-size: .9rem; line-height: 1.5; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 600; font-size: 0.9rem; }

.toggle-wrap { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1rem; cursor: pointer; font-weight:600}
.toggle-wrap input[type="checkbox"] { width: auto; margin:0; transform: scale(1.5);}

.text-muted { color: var(--text-muted); }

.alert {
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
}
.alert.error-msg { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert.success-msg { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: #fff;
    padding: 1rem 2rem;
    border-radius: 99px;
    font-weight: 600;
    transition: bottom 0.4s;
    z-index: 2000;
}
.toast.show { bottom: 30px; }

/* === Mobile Responsiveness === */
@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; flex-basis: auto; border-right: none; }
    .logo { padding: 1.5rem 1rem; font-size: 1.2rem; text-align: center; }
    
    .nav-links { display: flex; flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; padding: 0.5rem 0; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .nav-links li { padding: 0.8rem 1rem; border-left: none; border-bottom: 3px solid transparent; font-size: 0.9rem; }
    .nav-links li.active { border-left-color: transparent; border-bottom-color: var(--primary); background: transparent; }
    
    .bottom-nav { padding: 1rem; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
    .user-info { margin-bottom: 0; }
    
    .content { height: auto; padding: 1rem; overflow-y: visible; }
    
    .settings-grid { grid-template-columns: 1fr; gap: 1rem; }
    .charts-container { grid-template-columns: 1fr; }
    .stats-cards { grid-template-columns: 1fr; gap: 1rem; }
    
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }
    
    .settings-card { padding: 1.5rem; }
    #addPhotoForm { flex-direction: column; align-items: stretch !important; }
}

[hidden] { display:none!important; }
.section:not(.active-section) { display:none; }
.btn:disabled { opacity:.5; cursor:not-allowed; }
.draw-info { margin-bottom:.75rem; color:var(--primary); font-weight:600; }
.draw-rules { margin-bottom:1.5rem; color:var(--text-muted); line-height:1.6; }
.content-header { flex-wrap:wrap; gap:1rem; }
.content { min-width:0; }
input[type=datetime-local] { min-width:0; }
@media(max-width:768px) { .content-header > div { flex-wrap:wrap; } .login-card { padding:1.5rem; } }

@media (max-width: 420px) {
    .content { padding: .75rem; }
    .settings-card { padding: 1rem; }
    .content-header { align-items: stretch; }
    .content-header .btn { width: 100%; }
    #addPhotoForm .form-group { min-width: 0 !important; width: 100%; }
    #addPhotoForm .btn { width: 100%; margin-bottom: 0 !important; }
    #adminPhotoGallery { grid-template-columns: 1fr !important; }
    .bottom-nav { align-items: stretch; }
    .bottom-nav .btn { width: 100%; }
}
