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

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #e0e0e0;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --radius: 12px;
    --success: #2e7d32;
    --error: #d93025;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100vh; }

/* ===== Setup / Login ===== */
.setup-container {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; padding: 24px; text-align: center;
}
.app-logo { font-size: 64px; margin-bottom: 16px; }
.setup-container h1 { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: 16px; }

.auth-form {
    width: 100%; max-width: 320px;
    display: flex; flex-direction: column; gap: 12px;
}

.input {
    width: 100%; padding: 12px 16px;
    border: 2px solid var(--border); border-radius: var(--radius);
    font-size: 16px; background: var(--card); color: var(--text);
    appearance: none; -webkit-appearance: none;
}
select.input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%235f6368'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    cursor: pointer;
}
.input:focus { outline: none; border-color: var(--primary); }

.form-error { color: var(--error); font-size: 14px; min-height: 20px; }
.form-status { font-size: 13px; margin-top: 6px; color: var(--text-secondary); }
.form-status.success { color: var(--success); }
.form-status.error { color: var(--error); }

/* ===== Buttons ===== */
.btn {
    display: inline-block; padding: 12px 32px; border: none; border-radius: var(--radius);
    font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.2s, transform 0.1s;
    text-align: center; width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--error); color: white; }
.btn-inline { border: none; background: none; cursor: pointer; font-size: 13px; padding: 4px 8px; border-radius: 6px; }
.btn-inline-danger { color: var(--error); }
.btn-inline-danger:hover { background: #fce4ec; }

/* ===== Header ===== */
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--primary); color: white;
    position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 4px; }
.header-icon { font-size: 28px; }
.header-title { font-size: 18px; font-weight: 700; }
.header-subtitle { font-size: 12px; opacity: 0.85; }

.icon-btn {
    background: none; border: none; color: inherit; font-size: 24px;
    cursor: pointer; padding: 8px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ===== Tabs ===== */
.tabs {
    display: flex; background: var(--card); border-bottom: 1px solid var(--border);
    position: sticky; top: 60px; z-index: 99;
}
.tab {
    flex: 1; padding: 12px 8px; border: none; background: none;
    font-size: 14px; font-weight: 500; color: var(--text-secondary);
    cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Views ===== */
.view { display: none; padding: 16px; padding-bottom: 80px; }
.view.active { display: block; }

/* ===== Event list ===== */
.event-list { display: flex; flex-direction: column; gap: 8px; }
.event-card {
    display: flex; align-items: center; gap: 12px;
    background: var(--card); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
    animation: fadeIn 0.3s ease-out;
}
.event-icon {
    font-size: 28px; width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px; flex-shrink: 0;
}
.event-info { flex: 1; min-width: 0; }
.event-type { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.event-date { font-size: 13px; color: var(--text-secondary); }
.event-badge {
    font-size: 12px; padding: 4px 10px; border-radius: 20px;
    font-weight: 600; white-space: nowrap; flex-shrink: 0;
}
.badge-today { background: #e8f5e9; color: #2e7d32; }
.badge-tomorrow { background: #fff3e0; color: #e65100; }
.badge-soon { background: #e3f2fd; color: #1565c0; }
.badge-request { background: #fce4ec; color: #c62828; font-size: 11px; }
.section-header {
    font-size: 13px; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px; padding: 16px 0 8px;
}
.section-header:first-child { padding-top: 0; }
.no-events { text-align: center; padding: 40px 16px; color: var(--text-secondary); }
.no-events-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Calendar ===== */
.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.calendar-nav .icon-btn { color: var(--text); font-size: 20px; }
.calendar-month-label { font-size: 18px; font-weight: 600; }
.calendar-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
    background: var(--card); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
}
.cal-header { text-align: center; padding: 8px 4px; font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--card); }
.cal-days { display: contents; }
.cal-day {
    aspect-ratio: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 4px; font-size: 14px; cursor: pointer;
    position: relative; background: var(--card); transition: background 0.15s;
}
.cal-day:hover { background: #f0f0f0; }
.cal-day.empty { cursor: default; }
.cal-day.today { font-weight: 700; }
.cal-day.today .cal-day-num {
    background: var(--primary); color: white; border-radius: 50%;
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
}
.cal-day.past { opacity: 0.4; }
.cal-dots { display: flex; gap: 2px; margin-top: 2px; flex-wrap: wrap; justify-content: center; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; }
.day-detail { margin-top: 16px; background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.day-detail h3 { font-size: 16px; margin-bottom: 12px; }
.day-detail-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.day-detail-item:last-child { border-bottom: none; }

/* ===== Month table ===== */
.month-table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.month-table {
    width: 100%; border-collapse: collapse; background: var(--card);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
    font-size: 13px; min-width: 360px;
}
.month-table th { padding: 10px 6px; background: var(--primary); color: white; font-weight: 600; font-size: 11px; text-align: center; }
.month-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--border); }
.month-table tr:last-child td { border-bottom: none; }
.month-table .type-cell { text-align: left; font-weight: 500; white-space: nowrap; padding-left: 12px; }
.type-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ===== Settings panel ===== */
.settings-panel {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 200; display: flex; justify-content: flex-end;
}
.settings-content {
    width: 100%; max-width: 380px; background: var(--card);
    height: 100%; overflow-y: auto; padding: 20px;
    animation: slideIn 0.25s ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.settings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.settings-header h2 { font-size: 22px; }
.settings-header .icon-btn { color: var(--text); font-size: 28px; }
.settings-group { margin-bottom: 16px; }
.settings-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 8px; color: var(--text-secondary); }
.settings-group .input { max-width: 100%; }
.settings-group .btn { max-width: 100%; }
.settings-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.settings-footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); text-align: center; color: var(--text-secondary); }

.waste-toggles { display: flex; flex-direction: column; gap: 8px; }
.waste-toggle { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 14px; }
.waste-toggle input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ===== Info boxes ===== */
.info-box { background: var(--bg); border-radius: 8px; padding: 12px; font-size: 13px; }
.info-empty { color: var(--text-secondary); font-style: italic; }
.info-item { line-height: 1.5; }

/* ===== User list ===== */
.user-list { display: flex; flex-direction: column; gap: 4px; }
.user-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; background: var(--bg); border-radius: 8px; font-size: 14px;
}
.role-badge {
    font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; margin-left: 6px;
}
.role-badge.admin { background: #e3f2fd; color: #1565c0; }
.role-badge.user { background: #f3e5f5; color: #7b1fa2; }

/* ===== Log list ===== */
.log-list {
    background: var(--bg); border-radius: 8px; padding: 12px;
    max-height: 200px; overflow-y: auto; font-size: 12px;
}
.log-item { padding: 4px 0; border-bottom: 1px solid var(--border); line-height: 1.4; }
.log-item:last-child { border-bottom: none; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .view { max-width: 600px; margin: 0 auto; }
    .calendar-grid { max-width: 500px; margin: 0 auto; }
}

/* ===== Theme switcher ===== */
.theme-switcher { display: flex; gap: 6px; }
.theme-btn {
    flex: 1; padding: 8px 4px; border: 2px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer; text-align: center;
    transition: border-color 0.2s;
}
.theme-btn.active { border-color: var(--primary); background: var(--primary); color: white; }

/* ===== Import preview ===== */
.import-preview-box {
    background: var(--bg); border-radius: 8px; padding: 12px; font-size: 13px; max-height: 200px; overflow-y: auto;
}
.import-preview-district { padding: 4px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.import-preview-district:hover { color: var(--primary); }
.import-preview-district:last-child { border-bottom: none; }

/* ===== Dark mode (manual via data-theme or auto) ===== */
[data-theme="dark"] {
    --bg: #121212; --card: #1e1e1e; --text: #e0e0e0;
    --text-secondary: #9e9e9e; --border: #333; --shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-theme="dark"] .cal-day:hover { background: #2a2a2a; }
[data-theme="dark"] .badge-today { background: #1b3a1b; color: #81c784; }
[data-theme="dark"] .badge-tomorrow { background: #3e2723; color: #ffab40; }
[data-theme="dark"] .badge-soon { background: #0d2137; color: #64b5f6; }
[data-theme="dark"] .badge-request { background: #3e1515; color: #ef9a9a; }
[data-theme="dark"] .theme-btn { background: #1e1e1e; color: #e0e0e0; border-color: #444; }
[data-theme="dark"] .theme-btn.active { background: var(--primary); color: white; }

@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg: #121212; --card: #1e1e1e; --text: #e0e0e0;
        --text-secondary: #9e9e9e; --border: #333; --shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
    [data-theme="auto"] .cal-day:hover { background: #2a2a2a; }
    [data-theme="auto"] .badge-today { background: #1b3a1b; color: #81c784; }
    [data-theme="auto"] .badge-tomorrow { background: #3e2723; color: #ffab40; }
    [data-theme="auto"] .badge-soon { background: #0d2137; color: #64b5f6; }
    [data-theme="auto"] .badge-request { background: #3e1515; color: #ef9a9a; }
}
