:root {
    --primary-color: #4a90e2;
    --primary-dark: #3a73b5;
    --success-color: #4caf50;
    --error-color: #f44336;
    --text-color: #333;
    --light-bg: #f5f5f5;
    --white: #ffffff;
    --border-color: #ddd;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', sans-serif;
}

body {
    background-color: var(--light-bg);
    color: var(--text-color);
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Authentication Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background-color: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}

.auth-tabs {
    display: flex;
    background-color: var(--primary-dark);
}

.auth-tab {
    flex: 1;
    padding: 1rem;
    background: none;
    border: none;
    color: var(--white);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
}

.auth-tab.active {
    background-color: var(--primary-color);
}

.auth-form {
    padding: 1.5rem;
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.error-message {
    color: var(--error-color);
    margin: 0.5rem 0;
    font-size: 0.9rem;
    min-height: 1.5rem;
}

.auth-form button[type="submit"] {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
    transition: background-color 0.3s;
}

.auth-form button[type="submit"]:hover {
    background-color: var(--primary-dark);
}

/* App Container Styles */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--white);
    min-height: 100vh;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.app-interface {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Styles */
header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem;
    text-align: center;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

#username-display {
    font-weight: bold;
}

.logout-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--white);
    border: none;
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
}

header h1 {
    font-size: 1.8rem;
}

nav {
    display: flex;
    justify-content: space-between;
    background-color: var(--primary-dark);
    border-radius: 8px;
    overflow: hidden;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--white);
    padding: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.nav-btn.active {
    background-color: rgba(255, 255, 255, 0.2);
    font-weight: bold;
}

main {
    flex: 1;
    padding: 1rem;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.date-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    background-color: var(--light-bg);
    padding: 0.5rem;
    border-radius: 8px;
}

.date-selector button {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0 0.5rem;
}

#current-date {
    font-weight: bold;
}

/* Habit List Styles */
.habits-list, .admin-habits-list {
    list-style: none;
}

.habit-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.habit-item.loading {
    justify-content: center;
    color: #888;
}

.habit-name {
    flex: 1;
}

.habit-check {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.habit-check.checked {
    background-color: var(--success-color);
    border-color: var(--success-color);
    color: var(--white);
}

.habit-check.checked::after {
    content: '✓';
    font-weight: bold;
}

.add-habit-form {
    display: flex;
    margin-bottom: 1rem;
}

.add-habit-form input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px 0 0 4px;
}

.add-habit-form button {
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
}

.delete-btn {
    background-color: var(--error-color);
    color: var(--white);
    border: none;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.habit-selector {
    margin-bottom: 1rem;
}

/* Calendar Styles */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background-color: var(--light-bg);
    border-radius: 8px;
}

.calendar-header button {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0 0.5rem;
}

#current-month {
    font-weight: bold;
    font-size: 1.2rem;
}

.calendar-container {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
    margin-bottom: 2rem;
}

.day-header {
    text-align: center;
    font-weight: bold;
    color: var(--primary-color);
    font-size: 0.9rem;
    padding: 0.5rem 0;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--light-bg);
    border-radius: 50%;
    font-size: 1rem;
    position: relative;
    border: 1px solid transparent;
}

.calendar-day.other-month {
    color: #aaa;
}

.calendar-day.completed::after {
    content: "";
    position: absolute;
    bottom: 3px;
    width: 5px;
    height: 5px;
    background-color: var(--success-color);
    border-radius: 50%;
}

.calendar-day.missed::after {
    content: "";
    position: absolute;
    bottom: 3px;
    width: 5px;
    height: 5px;
    background-color: var(--error-color);
    border-radius: 50%;
}

.calendar-day.today {
    border: 1px solid var(--primary-color);
    font-weight: bold;
}

.completion-summary {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.completion-circle {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: conic-gradient(var(--primary-color) 0% var(--completion-percentage, 0%), #f0f0f0 var(--completion-percentage, 0%) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 1rem 0;
}

.completion-circle::before {
    content: "";
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: white;
}

#completion-rate {
    position: relative;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--text-color);
}

.rate-label {
    position: relative;
    font-size: 0.9rem;
    color: #888;
}

/* Stats Styles */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.stats-table th, .stats-table td {
    padding: 0.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stats-table th {
    background-color: var(--light-bg);
}

.success-rate {
    font-weight: bold;
}

.success-rate.high {
    color: var(--success-color);
}

.success-rate.medium {
    color: orange;
}

.success-rate.low {
    color: var(--error-color);
}

/* User Management Styles */
.user-management {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.add-user-form {
    background-color: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
}

.add-user-form h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th, .users-table td {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.users-table th {
    background-color: var(--light-bg);
}

.users-table .action-btns {
    display: flex;
    gap: 0.5rem;
}

.edit-btn {
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--white);
    padding: 1.5rem;
    border-radius: 8px;
    max-width: 400px;
    width: 100%;
    position: relative;
}

.close-modal {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1.5rem;
    cursor: pointer;
}

footer {
    background-color: var(--light-bg);
    padding: 1rem;
    text-align: center;
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
}

#install-btn {
    color: var(--primary-color);
    text-decoration: underline;
    cursor: pointer;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .nav-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.2rem;
    }
    
    .stats-table, .users-table {
        font-size: 0.8rem;
    }
    
    .stats-table th, .stats-table td,
    .users-table th, .users-table td {
        padding: 0.3rem;
    }
    
    .modal-content {
        padding: 1rem;
    }
}

@media (min-width: 768px) {
    .user-management {
        grid-template-columns: 1fr 1.5fr;
    }
}