/* ============================================================
   Habit Tracker — Global Styles
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

:root {
    --primary:      #4f46e5;
    --primary-dark: #3730a3;
    --primary-light:#e0e7ff;
    --success:      #16a34a;
    --success-light:#dcfce7;
    --warning:      #d97706;
    --warning-light:#fef3c7;
    --danger:       #dc2626;
    --danger-light: #fee2e2;
    --gray-50:      #f9fafb;
    --gray-100:     #f3f4f6;
    --gray-200:     #e5e7eb;
    --gray-300:     #d1d5db;
    --gray-400:     #9ca3af;
    --gray-500:     #6b7280;
    --gray-600:     #4b5563;
    --gray-700:     #374151;
    --gray-800:     #1f2937;
    --gray-900:     #111827;
    --white:        #ffffff;
    --radius:       10px;
    --radius-sm:    6px;
    --shadow:       0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);
    --font:         'Inter', system-ui, sans-serif;
}

html { font-size: 16px; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 60px;
}
.nav-brand {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .4rem;
    white-space: nowrap;
}
.nav-icon { font-size: 1.3rem; }
.nav-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: .25rem;
    margin-left: auto;
}
.nav-link {
    display: block;
    padding: .4rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link.nav-logout { color: var(--danger); }
.nav-link.nav-logout:hover { background: var(--danger-light); }
.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; }

@media (max-width: 640px) {
    .nav-toggle { display: block; margin-left: auto; }
    .nav-menu {
        display: none;
        position: absolute;
        top: 60px; left: 0; right: 0;
        background: var(--white);
        flex-direction: column;
        padding: .75rem;
        border-bottom: 1px solid var(--gray-200);
        box-shadow: var(--shadow-md);
        gap: .25rem;
    }
    .nav-menu.open { display: flex; }
    .nav-link { width: 100%; }
}

/* ============================================================
   LAYOUT
   ============================================================ */
.main-content { min-height: calc(100vh - 60px - 48px); }
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
}
.container-sm { max-width: 720px; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1.5rem;
}
.page-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}
.date-badge {
    background: var(--primary-light);
    color: var(--primary);
    font-size: .8rem;
    font-weight: 600;
    padding: .25rem .75rem;
    border-radius: 999px;
}

/* ============================================================
   CARDS & SECTIONS
   ============================================================ */
.section-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}
.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: .75rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--gray-100);
}
.section-desc {
    font-size: .8rem;
    color: var(--gray-500);
    margin: -.25rem 0 .75rem;
}

/* ============================================================
   STAT GRID
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: var(--shadow);
}
.stat-icon { font-size: 2rem; flex-shrink: 0; line-height: 1; }
.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.1;
}
.stat-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin: .2rem 0 .15rem;
}
.stat-sub { font-size: .75rem; color: var(--gray-500); }

/* ============================================================
   TRACKER TABLE
   ============================================================ */
.tracker-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tracker-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
    white-space: nowrap;
}
.tracker-table th,
.tracker-table td {
    padding: .5rem .6rem;
    text-align: center;
    border-bottom: 1px solid var(--gray-100);
}
.tracker-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    font-size: .775rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.col-habit {
    text-align: left !important;
    min-width: 160px;
    font-weight: 500;
    color: var(--gray-800);
    white-space: normal;
}
.col-date { min-width: 52px; }
.col-today { background: var(--primary-light) !important; }
.col-streak { min-width: 120px; font-size: .8rem; }
.th-day { display: block; font-size: .65rem; color: var(--gray-400); }
.th-date { display: block; font-size: .9rem; font-weight: 700; }
.tracker-table tfoot td { font-size: .8rem; background: var(--gray-50); }
.tracker-table tbody tr:hover { background: var(--gray-50); }

/* Check cells */
.check-cell { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; font-size: .875rem; }
.check-done  { background: var(--success-light); color: var(--success); }
.check-miss  { background: var(--danger-light);  color: var(--danger); }
.check-future { color: var(--gray-300); font-size: .75rem; }

.check-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    font-size: .9rem;
    cursor: pointer;
    transition: transform .12s, box-shadow .12s;
    line-height: 1;
}
.check-btn:hover { transform: scale(1.15); box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.check-btn.check-done   { background: var(--success-light); border-color: var(--success); color: var(--success); }
.check-btn.check-undone { background: var(--gray-100);      border-color: var(--gray-300); color: var(--gray-400); }

/* Pct footer cells */
.pct-cell { display: inline-block; font-weight: 600; font-size: .8rem; padding: .15rem .4rem; border-radius: 4px; }
.pct-high { background: var(--success-light); color: var(--success); }
.pct-mid  { background: var(--warning-light); color: var(--warning); }
.pct-low  { background: var(--danger-light);  color: var(--danger);  }

/* Streak in table */
.streak-current { font-weight: 700; color: var(--warning); }
.streak-best    { font-size: .75rem; color: var(--gray-400); }

/* ============================================================
   STREAK GRID
   ============================================================ */
.streak-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.streak-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.streak-habit-name {
    font-size: .85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: .75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.streak-numbers { display: flex; align-items: center; justify-content: center; gap: .5rem; }
.streak-item    { display: flex; flex-direction: column; align-items: center; }
.streak-num     { font-size: 1.75rem; font-weight: 800; color: var(--warning); line-height: 1; }
.streak-best-num { color: var(--primary); }
.streak-lbl     { font-size: .65rem; color: var(--gray-400); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-top: .15rem; }
.streak-divider { width: 1px; height: 40px; background: var(--gray-200); }

/* ============================================================
   HABIT LIST
   ============================================================ */
.habit-list { display: flex; flex-direction: column; gap: .75rem; }
.habit-item {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: .875rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
    transition: border-color .15s;
}
.habit-item:hover { border-color: var(--primary); }
.habit-inactive   { opacity: .6; }
.habit-item-info  { display: flex; align-items: center; gap: .625rem; flex: 1; min-width: 0; }
.habit-item-status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-active   { background: var(--success); }
.dot-inactive { background: var(--gray-400); }
.habit-item-name { font-weight: 500; color: var(--gray-800); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit-badge {
    font-size: .7rem;
    font-weight: 600;
    padding: .15rem .5rem;
    border-radius: 999px;
    background: var(--success-light);
    color: var(--success);
    white-space: nowrap;
}
.habit-inactive .habit-badge { background: var(--gray-100); color: var(--gray-500); }
.habit-item-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ============================================================
   STATISTICS PAGE
   ============================================================ */
.stats-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) { .stats-grid-2 { grid-template-columns: 1fr; } }

.rekap-list { display: flex; flex-direction: column; gap: .75rem; }
.rekap-item {}
.rekap-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .3rem; }
.rekap-name  { font-size: .875rem; font-weight: 500; color: var(--gray-700); }
.rekap-fraction { font-size: .75rem; color: var(--gray-400); }
.rekap-bar-wrap { display: flex; align-items: center; gap: .75rem; }
.rekap-bar { flex: 1; background: var(--gray-100); border-radius: 999px; height: 10px; overflow: hidden; }
.rekap-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .4s ease;
    min-width: 4px;
}
.rekap-bar-fill.pct-high { background: var(--success); }
.rekap-bar-fill.pct-mid  { background: var(--warning); }
.rekap-bar-fill.pct-low  { background: var(--danger);  }
.rekap-pct { font-size: .8rem; font-weight: 700; min-width: 36px; text-align: right; }
.today-badge {
    display: inline-block;
    font-size: .65rem;
    background: var(--primary);
    color: var(--white);
    padding: .1rem .4rem;
    border-radius: 999px;
    margin-left: .4rem;
    font-weight: 600;
    vertical-align: middle;
}

/* Data table */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.data-table th, .data-table td {
    padding: .625rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}
.data-table th { background: var(--gray-50); font-weight: 600; font-size: .8rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }
.data-table tbody tr:hover { background: var(--gray-50); }

/* Streak badges */
.streak-badge {
    display: inline-block;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 700;
}
.badge-gold    { background: #fef3c7; color: #b45309; }
.badge-silver  { background: var(--gray-100); color: var(--gray-600); }
.badge-default { background: var(--gray-100); color: var(--gray-500); }
.badge-best    { background: var(--primary-light); color: var(--primary-dark); }

/* ============================================================
   PROFILE
   ============================================================ */
.profile-hero {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}
.profile-avatar {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    font-size: 2rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-info h3 { margin: 0 0 .15rem; font-size: 1.25rem; font-weight: 700; }
.profile-info p  { margin: 0 0 .1rem; font-size: .875rem; color: var(--gray-600); }
.profile-email   { color: var(--gray-500) !important; }
.profile-joined  { color: var(--gray-400) !important; font-size: .8rem !important; }
.profile-stats   { display: flex; gap: 1.5rem; }
.pstat           { text-align: center; }
.pstat-num       { display: block; font-size: 1.75rem; font-weight: 800; color: var(--primary); }
.pstat-lbl       { display: block; font-size: .75rem; color: var(--gray-500); font-weight: 500; }
.form-row        { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: .35rem;
}
.form-control {
    display: block;
    width: 100%;
    padding: .6rem .875rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-family: var(--font);
    color: var(--gray-800);
    background: var(--white);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    appearance: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.form-control.is-invalid { border-color: var(--danger); }
.invalid-feedback { display: block; font-size: .78rem; color: var(--danger); margin-top: .25rem; }

.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.form-check-input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.form-check-label { font-size: .875rem; color: var(--gray-600); cursor: pointer; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .6rem 1.25rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.3;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary);  border-color: var(--primary);       color: var(--white); }
.btn-primary:hover  { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success);  border-color: var(--success);        color: var(--white); }
.btn-warning { background: var(--warning);  border-color: var(--warning);        color: var(--white); }
.btn-danger  { background: var(--danger);   border-color: var(--danger);         color: var(--white); }
.btn-outline { background: transparent;     border-color: var(--gray-300);       color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-100); }
.btn-block   { width: 100%; }
.btn-sm      { padding: .35rem .7rem; font-size: .8rem; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gray-500); line-height: 1; }
.modal-close:hover { color: var(--gray-900); }
.modal-box form { padding: 1.25rem 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1rem; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    padding: .875rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    margin: .75rem 1.25rem;
    border-left: 4px solid transparent;
}
.alert-success { background: var(--success-light); color: #14532d; border-color: var(--success); }
.alert-danger  { background: var(--danger-light);  color: #7f1d1d; border-color: var(--danger);  }
.alert-warning { background: var(--warning-light); color: #78350f; border-color: var(--warning); }
.alert-close   { background: none; border: none; font-size: 1.1rem; cursor: pointer; opacity: .6; flex-shrink: 0; }
.alert-close:hover { opacity: 1; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 1.5rem;
}
.auth-wrapper { width: 100%; max-width: 420px; }
.auth-card {
    background: var(--white);
    border-radius: 16px;
    padding: 2rem 2.25rem;
    box-shadow: 0 25px 60px rgba(0,0,0,.3);
}
.auth-header { text-align: center; margin-bottom: 1.75rem; }
.auth-icon   { font-size: 3rem; display: block; margin-bottom: .5rem; }
.auth-header h1 { margin: 0 0 .25rem; font-size: 1.5rem; font-weight: 800; color: var(--gray-900); }
.auth-header p  { margin: 0; color: var(--gray-500); font-size: .9rem; }
.auth-footer { text-align: center; margin: 1rem 0 0; font-size: .875rem; color: var(--gray-500); }
.auth-footer a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}
.empty-icon { font-size: 3rem; display: block; margin-bottom: .75rem; }
.empty-state p { margin: 0; font-size: .9rem; }
.empty-state a { color: var(--primary); font-weight: 600; }

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
    text-align: center;
    padding: .75rem 1rem;
    font-size: .8rem;
    color: var(--gray-400);
    border-top: 1px solid var(--gray-200);
    background: var(--white);
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-muted { color: var(--gray-400); font-size: .875rem; }
