/* ============================================================
   HealthTrack — Main stylesheet
   Dark-first design, CSS custom properties
   ============================================================ */

/* ------------------------------------------------------------
   Design tokens
   ------------------------------------------------------------ */
:root {
    --bg-0:        #0f1117;   /* page background */
    --bg-1:        #1a1d27;   /* card / panel */
    --bg-2:        #22263a;   /* input / hover */
    --bg-3:        #2a2f47;   /* active / selected */

    --border:      rgba(255,255,255,0.08);
    --border-focus:rgba(59,130,246,0.6);

    --text-1:      #f0f2ff;   /* primary */
    --text-2:      #9ca3c4;   /* secondary */
    --text-3:      #5f6480;   /* muted */

    --accent:      #3b82f6;   /* blue */
    --accent-hover:#2563eb;
    --accent-dim:  rgba(59,130,246,0.15);

    --success:     #22c55e;
    --warning:     #eab308;
    --danger:      #ef4444;
    --info:        #38bdf8;

    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   16px;
    --radius-xl:   22px;

    --shadow-sm:   0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:   0 4px 16px rgba(0,0,0,0.5);

    --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono:   'JetBrains Mono', 'Fira Code', monospace;

    --sidebar-w:   240px;
    --topbar-h:    60px;

    --transition:  0.18s ease;
}

[data-theme="light"] {
    --bg-0:    #f4f6fb;
    --bg-1:    #ffffff;
    --bg-2:    #eef0f8;
    --bg-3:    #e3e6f0;
    --border:  rgba(0,0,0,0.08);
    --text-1:  #0f1117;
    --text-2:  #4b5280;
    --text-3:  #9ca3c4;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
}

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

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg-0);
    color: var(--text-1);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------
   Auth page
   ------------------------------------------------------------ */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 16px;
}

.auth-wrap {
    width: 100%;
    max-width: 400px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 36px 36px;
    box-shadow: var(--shadow-md);
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-1);
}

.auth-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-2);
    border-radius: var(--radius-md);
    padding: 4px;
    margin-bottom: 28px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.auth-tab.active {
    background: var(--bg-1);
    color: var(--text-1);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ------------------------------------------------------------
   Form fields
   ------------------------------------------------------------ */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
}

.field input,
.field select,
.field textarea {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-1);
    font-size: 15px;
    font-family: var(--font);
    padding: 10px 14px;
    outline: none;
    transition: border-color var(--transition), background var(--transition);
    width: 100%;
}

.field input::placeholder,
.field textarea::placeholder { color: var(--text-3); }

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--border-focus);
    background: var(--bg-1);
}

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn-primary {
    width: 100%;
    padding: 11px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background var(--transition), opacity var(--transition);
    margin-top: 4px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg-2);
    color: var(--text-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
}
.btn-secondary:hover { background: var(--bg-3); }

.btn-icon {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-2);
    transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg-3); color: var(--text-1); }

/* Spinner (pure CSS) */
.btn-spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------
   Error / alert
   ------------------------------------------------------------ */
.auth-error {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius-md);
    color: #fca5a5;
    font-size: 13px;
    padding: 10px 14px;
}

.alert {
    border-radius: var(--radius-md);
    font-size: 14px;
    padding: 12px 16px;
    margin-bottom: 16px;
}
.alert-success { background: rgba(34,197,94,0.12);  border: 1px solid rgba(34,197,94,0.3);  color: #86efac; }
.alert-warning { background: rgba(234,179,8,0.12);  border: 1px solid rgba(234,179,8,0.3);  color: #fde047; }
.alert-danger  { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.3);  color: #fca5a5; }
.alert-info    { background: rgba(56,189,248,0.12); border: 1px solid rgba(56,189,248,0.3); color: #7dd3fc; }

/* ------------------------------------------------------------
   App layout (dashboard shell — used in pages/)
   ------------------------------------------------------------ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--text-1);
    height: var(--topbar-h);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    padding: 0 8px;
    margin-bottom: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-1); text-decoration: none; }
.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition);
}
.user-chip:hover { background: var(--bg-2); }

.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: #fff;
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name  { font-size: 13px; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main content area */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-h);
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-body { padding: 28px; flex: 1; }

/* ------------------------------------------------------------
   Cards & widgets
   ------------------------------------------------------------ */
.card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    margin-bottom: 12px;
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.widget {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    position: relative;
    overflow: hidden;
}
.widget:hover { background: var(--bg-2); border-color: rgba(255,255,255,0.14); }

.widget-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 14px;
    font-size: 20px;
}

.widget-label  { font-size: 12px; font-weight: 500; color: var(--text-3); margin-bottom: 4px; }
.widget-value  { font-size: 26px; font-weight: 700; color: var(--text-1); line-height: 1.1; }
.widget-unit   { font-size: 13px; font-weight: 400; color: var(--text-2); margin-left: 3px; }
.widget-trend  { font-size: 12px; margin-top: 8px; color: var(--text-3); }
.widget-trend.up   { color: var(--success); }
.widget-trend.down { color: var(--danger); }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

@media (max-width: 900px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
}

/* ------------------------------------------------------------
   Tables
   ------------------------------------------------------------ */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-2);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-2); color: var(--text-1); }

/* ------------------------------------------------------------
   Badges
   ------------------------------------------------------------ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15);  color: #86efac; }
.badge-warning { background: rgba(234,179,8,0.15);  color: #fde047; }
.badge-danger  { background: rgba(239,68,68,0.15);  color: #fca5a5; }
.badge-info    { background: rgba(56,189,248,0.15); color: #7dd3fc; }
.badge-neutral { background: var(--bg-3); color: var(--text-2); }

/* ------------------------------------------------------------
   Utility
   ------------------------------------------------------------ */
.text-muted  { color: var(--text-3); }
.text-sm     { font-size: 13px; }
.text-xs     { font-size: 11px; }
.text-right  { text-align: right; }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.gap-16      { gap: 16px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.hidden      { display: none !important; }
