*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg: #0a1020;
    --bg-soft: rgba(255, 255, 255, 0.04);
    --panel: rgba(14, 23, 44, 0.92);
    --panel-2: rgba(17, 30, 58, 0.86);
    --border: rgba(255, 255, 255, 0.08);
    --text: #ecf3ff;
    --muted: #9db0d2;
    --primary: #6ea8fe;
    --primary-2: #7cf0c8;
    --danger: #ff7f96;
    --warning: #ffcf70;
    --success: #6ee7b7;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background:
        radial-gradient(circle at top right, rgba(110, 168, 254, 0.2), transparent 28%),
        radial-gradient(circle at left bottom, rgba(124, 240, 200, 0.13), transparent 30%),
        linear-gradient(180deg, #08101f 0%, #0b1327 60%, #09111d 100%);
    color: var(--text);
    min-height: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

.nav-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.sidebar-overlay {
    display: none;
}

.sidebar-close,
.hamburger-btn {
    display: none;
}

.hamburger-btn {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.05);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    transition: transform .16s ease, background .16s ease, border-color .16s ease;
}

.hamburger-btn:hover {
    transform: translateY(-1px);
    background: rgba(255,255,255,0.08);
}

.hamburger-line {
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: var(--text);
    display: block;
}

.sidebar-close {
    margin-left: auto;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.05);
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    padding: 28px 20px;
    border-right: 1px solid var(--border);
    background: rgba(7, 14, 27, 0.86);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.brand-badge {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #07111f;
    font-weight: 800;
    box-shadow: var(--shadow);
}

.brand-title {
    font-size: 1.2rem;
    font-weight: 800;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 0.9rem;
}

.nav-links {
    display: grid;
    gap: 10px;
}

.nav-links a {
    padding: 13px 15px;
    border-radius: 14px;
    color: var(--muted);
    border: 1px solid transparent;
    transition: all .18s ease;
}

.nav-links a:hover,
.nav-links a.active {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border-color: var(--border);
    transform: translateY(-1px);
}

.sidebar-footer {
    display: grid;
    gap: 16px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: rgba(255,255,255,0.04);
    border-radius: 18px;
    border: 1px solid var(--border);
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-weight: 800;
    background: linear-gradient(135deg, rgba(110,168,254,0.8), rgba(124,240,200,0.65));
    color: #09111f;
}

.user-chip-name {
    font-weight: 700;
}

.user-chip-email,
.topbar-subtitle,
.card-subtitle,
.muted,
.table-muted {
    color: var(--muted);
}

.logout-link {
    text-align: center;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
}

.main-content {
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.topbar h1,
.page-section h2,
.login-card h1 {
    margin: 0;
    font-size: clamp(1.6rem, 2vw, 2.2rem);
    letter-spacing: -0.03em;
}

.topbar-actions,
.inline-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pill {
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 0.86rem;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
}

.pill-primary {
    background: linear-gradient(135deg, rgba(110,168,254,0.25), rgba(124,240,200,0.18));
}

.pill-ghost {
    color: var(--muted);
}

.flash {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 18px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.05);
}

.flash-success { border-color: rgba(110, 231, 183, 0.35); }
.flash-warning { border-color: rgba(255, 207, 112, 0.35); }
.flash-danger  { border-color: rgba(255, 127, 150, 0.35); }

.grid {
    display: grid;
    gap: 18px;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
    background: linear-gradient(180deg, rgba(17,30,58,0.88), rgba(10,18,36,0.9));
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 22px;
    overflow: hidden;
}

.card.glow {
    position: relative;
}

.card.glow::after {
    content: '';
    position: absolute;
    inset: auto -40px -40px auto;
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, rgba(110,168,254,0.22), transparent 65%);
    pointer-events: none;
}

.metric-card {
    min-height: 146px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.metric-label {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 8px;
}

.metric-value {
    font-size: clamp(1.8rem, 2.6vw, 2.4rem);
    font-weight: 800;
    letter-spacing: -0.04em;
}

.metric-foot {
    font-size: 0.92rem;
    color: var(--muted);
}

.progress-track {
    width: 100%;
    height: 11px;
    border-radius: 999px;
    background: rgba(255,255,255,0.07);
    overflow: hidden;
    margin-top: 12px;
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.page-section {
    margin-bottom: 22px;
}

.page-section-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: end;
    margin-bottom: 16px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 6px 0;
}

.card-subtitle {
    margin: 0;
    font-size: 0.94rem;
}

form {
    width: 100%;
}

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid-3 {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-group {
    display: grid;
    gap: 8px;
}

.form-group-full {
    grid-column: 1 / -1;
}

label {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 14px;
    padding: 13px 14px;
    outline: none;
}

textarea {
    resize: vertical;
    min-height: 110px;
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary), rgba(124,240,200,0.92));
    color: #07111f;
    font-weight: 700;
    transition: transform .16s ease, opacity .16s ease;
}

button:hover,
.btn:hover {
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-danger {
    background: linear-gradient(135deg, rgba(255,127,150,0.95), rgba(255,180,130,0.95));
    color: #1d0d12;
}

.btn-warning {
    background: linear-gradient(135deg, rgba(255,207,112,0.95), rgba(255,168,110,0.95));
    color: #23170b;
}

.btn-sm {
    padding: 9px 12px;
    font-size: 0.88rem;
    border-radius: 12px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 440px);
    background: linear-gradient(180deg, rgba(17,30,58,0.95), rgba(10,18,36,0.96));
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-hero {
    text-align: center;
    margin-bottom: 24px;
}

.login-hero .brand-badge {
    margin: 0 auto 16px;
}

.login-footer {
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.kicker {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--primary-2);
    font-size: 0.82rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 800;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 18px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: rgba(255,255,255,0.02);
}

th,
td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 7px 10px;
    font-size: 0.8rem;
    font-weight: 700;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
}

.badge.success { color: var(--success); }
.badge.warning { color: var(--warning); }
.badge.danger  { color: var(--danger); }

.hero-card {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 18px;
    align-items: stretch;
}

.callout {
    display: grid;
    gap: 12px;
}

.callout-quote {
    font-size: clamp(1.25rem, 2vw, 1.7rem);
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.04em;
}

.callout-muted {
    color: var(--muted);
    max-width: 65ch;
}

.insight-list {
    display: grid;
    gap: 12px;
}

.insight-item,
.quick-card,
.favorite-card,
.routine-card,
.habit-item {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255,255,255,0.04);
}

.quick-add-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.timer-panel {
    display: grid;
    gap: 12px;
    padding: 18px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(110,168,254,0.15), rgba(124,240,200,0.08));
    border: 1px solid rgba(110, 168, 254, 0.25);
}

.timer-display {
    font-size: clamp(2rem, 3vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.05em;
}

.routines-grid,
.favorites-grid,
.habits-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.routine-card h3,
.favorite-card h3,
.habit-item h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.02rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    color: var(--muted);
    font-size: 0.92rem;
    margin: 10px 0 0;
}

.chart-card canvas {
    width: 100% !important;
    height: 340px !important;
}

.mini-chart canvas {
    width: 100% !important;
    height: 220px !important;
}

.empty-state {
    padding: 18px;
    border-radius: 18px;
    border: 1px dashed rgba(255,255,255,0.15);
    color: var(--muted);
    background: rgba(255,255,255,0.03);
}

.inline-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.summary-list {
    display: grid;
    gap: 12px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px dashed rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

.summary-item:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.tag {
    font-size: 0.78rem;
    color: var(--primary-2);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

@media (max-width: 1080px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero-card { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: min(86vw, 320px);
        height: 100vh;
        z-index: 40;
        border-right: 1px solid var(--border);
        border-bottom: 0;
        transform: translateX(-105%);
        transition: transform .24s ease;
        box-shadow: var(--shadow);
        overflow-y: auto;
    }

    .nav-toggle:checked ~ .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(3, 8, 18, 0.58);
        backdrop-filter: blur(4px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .24s ease;
        z-index: 30;
    }

    .nav-toggle:checked ~ .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-close,
    .hamburger-btn {
        display: inline-flex;
    }

    .main-content {
        padding: 20px;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
        align-items: center;
    }
}

@media (max-width: 700px) {
    .grid-2,
    .grid-3,
    .grid-4,
    .form-grid,
    .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
    }

    .timer-display {
        font-size: 2.2rem;
    }
}