/* Household Chores App - Extended CSS with Stats, Users, PWA, Dark Mode */

/* ============ Reset & Base ============ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4a90d9;
    --primary-dark: #357abd;
    --success: #5cb85c;
    --warning: #f0ad4e;
    --danger: #d9534f;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #6c757d;
    --gray-700: #495057;
    --gray-900: #212529;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-lg: 12px;
    
    /* Theme colors */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
}

/* Dark Mode */
[data-theme="dark"] {
    --primary: #5c9ce6;
    --primary-dark: #4a8bd4;
    --gray-100: #1a1a2e;
    --gray-200: #252540;
    --gray-300: #3d3d5c;
    --gray-500: #9e9eb3;
    --gray-700: #c5c5d3;
    --gray-900: #e8e8f0;
    --shadow: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --text-primary: #e8e8f0;
    --text-secondary: #9e9eb3;
    --border-color: #3d3d5c;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============ Header & Nav ============ */
header {
    background: var(--bg-secondary);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--text-primary);
    text-decoration: none;
    margin-right: 0.5rem;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    flex-wrap: wrap;
}

.nav-links a {
    padding: 0.4rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-size: 0.9rem;
}

.nav-links a:hover {
    background: var(--gray-200);
    color: var(--text-primary);
}

.nav-links a.active {
    background: var(--primary);
    color: white;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: var(--gray-200);
}

.user-badge {
    background: var(--gray-200);
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-link,
.logout-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 1rem;
    padding: 0 0.25rem;
    transition: color 0.2s;
}

.settings-link:hover {
    color: var(--primary);
}

.logout-link:hover {
    color: var(--danger);
}

/* ============ Main Content ============ */
main {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    flex: 1;
    width: 100%;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.page-header p,
.date {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.back-link {
    display: inline-block;
    margin-bottom: 0.5rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-large {
    padding: 0.7rem 1.5rem;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

/* ============ Forms ============ */
.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.85rem;
}

input[type="text"],
input[type="email"],
input[type="number"],
select {
    width: 100%;
    padding: 0.5rem 0.7rem;
    font-size: 0.95rem;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

input[type="color"] {
    width: 40px;
    height: 36px;
    padding: 2px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 0.75rem;
    align-items: end;
}

.form-row.compact {
    grid-template-columns: 1fr auto auto;
}

@media (max-width: 600px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-section {
    background: var(--gray-100);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
}

.form-section.compact {
    padding: 0.5rem;
}

.section-label {
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-actions {
    margin-top: 1rem;
}

.error {
    background: #fee;
    color: var(--danger);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border-left: 4px solid var(--danger);
    font-size: 0.9rem;
}

/* Schedule Options */
.schedule-options {
    display: flex;
    gap: 1rem;
    margin: 0.5rem 0;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.weekday-selector {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.day-checkbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.3rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.75rem;
}

.day-checkbox:has(input:checked) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.day-checkbox input {
    display: none;
}

.interval-input {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.rotation-members {
    margin-top: 0.5rem;
}

.rotation-members small {
    display: block;
    color: var(--gray-500);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* ============ Filter Bar ============ */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.filter-bar > span {
    color: var(--gray-500);
    font-size: 0.85rem;
}

.filter-chip {
    padding: 0.3rem 0.6rem;
    background: var(--bg-secondary);
    border: 1px solid var(--gray-300);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--gray-700);
    text-decoration: none;
    transition: all 0.2s;
}

.filter-chip:hover {
    background: var(--gray-200);
}

.filter-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ============ Chores Section ============ */
.chores-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.chores-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chores-section .count {
    font-weight: normal;
    color: var(--gray-500);
    font-size: 0.9rem;
}

.completed-section {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    box-shadow: none;
}

.chore-list {
    list-style: none;
}

.chore-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--gray-200);
}

.chore-item:last-child {
    border-bottom: none;
}

.chore-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    padding: 0.2rem;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.chore-btn:hover {
    background: var(--gray-100);
}

.checkbox {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--gray-300);
    border-radius: 50%;
    font-size: 0.9rem;
    color: var(--gray-300);
    flex-shrink: 0;
    transition: all 0.2s;
}

.chore-btn:hover .checkbox {
    border-color: var(--primary);
    color: var(--primary);
}

.chore-item.done .checkbox {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.chore-title {
    flex: 1;
}

.chore-item.done .chore-title {
    text-decoration: line-through;
    color: var(--gray-500);
}

.chore-category {
    background: var(--gray-200);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--gray-500);
}

.assigned-to {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 500;
}

.completed-by {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-style: italic;
}

.empty-message {
    color: var(--gray-500);
    text-align: center;
    padding: 0.75rem;
    font-size: 0.9rem;
}

/* ============ Templates Page ============ */
.add-template, .add-member {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.add-template h2, .add-member h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.template-list-section, .users-list-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.template-list-section h2, .users-list-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

/* Template Cards */
.template-cards {
    display: grid;
    gap: 0.75rem;
}

.template-card {
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 0.75rem;
    border-left: 4px solid var(--primary);
}

.template-card.archived {
    opacity: 0.6;
    border-left-color: var(--gray-400);
}

.template-card.editing {
    background: var(--bg-secondary);
    border: 2px solid var(--primary);
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.template-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.template-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.meta-item {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.meta-item.rotation {
    color: var(--primary);
}

.template-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.edit-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
}

.badge-active {
    background: #d4edda;
    color: #155724;
}

.badge-archived {
    background: var(--gray-200);
    color: var(--gray-500);
}

/* ============ Stats Page ============ */
.period-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-card.large {
    grid-column: span 2;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.stats-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.stats-section h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

/* Leaderboard */
.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: var(--gray-100);
    border-radius: var(--radius);
}

.rank {
    font-size: 1.25rem;
    width: 2rem;
    text-align: center;
}

.member-badge {
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 2px solid;
}

.entry-count {
    font-weight: 600;
    flex: 1;
}

.entry-days {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Bar Chart */
.chart-container {
    overflow-x: auto;
    padding: 0.5rem 0;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 150px;
    min-width: max-content;
}

.bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 40px;
}

.bar {
    width: 100%;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    transition: height 0.3s;
}

.bar-value {
    font-size: 0.65rem;
    color: white;
    padding-top: 2px;
}

.bar-label {
    font-size: 0.6rem;
    color: var(--gray-500);
    margin-top: 4px;
    white-space: nowrap;
}

/* Category Stats */
.category-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.category-stat {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.category-name {
    width: 100px;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-bar {
    flex: 1;
    height: 20px;
    background: var(--gray-200);
    border-radius: 10px;
    overflow: hidden;
}

.category-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 10px;
    transition: width 0.3s;
}

.category-count {
    font-size: 0.85rem;
    font-weight: 600;
    width: 30px;
    text-align: right;
}

/* ============ Users Page ============ */
.users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem;
}

.user-card {
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 0.75rem;
    border-left: 4px solid var(--primary);
}

.user-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
}

.user-info h3 {
    font-size: 0.95rem;
    margin-bottom: 0.1rem;
}

.user-stat {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.user-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

.mini-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.35rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    color: var(--gray-600);
}

.user-actions {
    display: flex;
    gap: 0.4rem;
}

/* Recent List */
.recent-list {
    list-style: none;
}

.recent-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.85rem;
}

.recent-item:last-child {
    border-bottom: none;
}

.recent-title {
    flex: 1;
}

.recent-date {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ============ Name Setup Page ============ */
.name-setup {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, #6ab0e3 100%);
}

.name-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 350px;
    width: 100%;
    text-align: center;
}

.name-card h1 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.name-card > p {
    color: var(--gray-500);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

.name-card .form-group {
    text-align: left;
}

.name-card input {
    text-align: center;
}

.name-card .btn {
    width: 100%;
    margin-top: 0.5rem;
}

.hint {
    margin-top: 0.75rem;
    color: var(--gray-500);
}

/* ============ Footer ============ */
footer {
    text-align: center;
    padding: 0.75rem;
    color: var(--gray-500);
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

footer .bug-link {
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.75rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

footer .bug-link:hover {
    opacity: 1;
    color: var(--primary);
}

/* ============ PWA Install Prompt ============ */
.install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    z-index: 1000;
    flex-wrap: wrap;
}

.install-prompt span {
    font-size: 0.85rem;
}

/* ============ HTMX Loading State ============ */
.htmx-request {
    opacity: 0.7;
    pointer-events: none;
}

.htmx-request .chore-btn {
    cursor: wait;
}

/* ============ Mobile Adjustments ============ */
@media (max-width: 600px) {
    nav {
        padding: 0.5rem;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .nav-links a {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }
    
    main {
        padding: 1rem 0.75rem;
    }
    
    .page-header h1 {
        font-size: 1.25rem;
    }
    
    .stats-cards {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stat-card.large {
        grid-column: span 3;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .leaderboard-entry {
        flex-wrap: wrap;
    }
    
    .entry-days {
        width: 100%;
        margin-left: 2.75rem;
    }
    
    .bar-chart {
        height: 100px;
    }
    
    .bar-group {
        width: 30px;
    }
}

/* Standalone PWA mode adjustments */
@media (display-mode: standalone) {
    header {
        padding-top: env(safe-area-inset-top);
    }
    
    .install-prompt {
        display: none !important;
    }
}
