/* =========================================================================
   Tidewell design system
   Palette: steady teal (primary) + warm clay (elevated states) on a calm,
   warm-neutral ground. Signature element: the "mood wave" — a continuous
   line motif (nav underline + dashboard hero) standing in for the literal
   mood-over-time line this whole app exists to help smooth out.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    /* -- palette -- */
    --bg:            #FAFAF8;
    --surface:       #FFFFFF;
    --surface-2:     #F3F1EA;
    --ink:           #1C2321;
    --ink-muted:     #5B6660;
    --ink-faint:     #8B948E;
    --border:        #E4E1DA;
    --primary:       #2F6F62;
    --primary-dark:  #21504C;
    --primary-tint:  #E7F0ED;
    --accent:        #C97B4A;   /* elevated / warm states */
    --accent-tint:   #FBECE0;
    --low:           #5C6BC0;   /* depressive / low states */
    --low-tint:      #EBEDFA;
    --danger:        #B3432B;
    --danger-tint:   #FBE7E1;
    --success:       #3F8459;

    /* -- type -- */
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    /* -- layout -- */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(28, 35, 33, 0.06);
    --shadow: 0 4px 16px rgba(28, 35, 33, 0.07);
    --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; color: var(--ink); }
h1 { font-size: 28px; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
@media (max-width: 640px) {
    h1 { font-size: 23px; }
    h2 { font-size: 18px; }
}
p { margin: 0 0 8px; color: var(--ink-muted); }
a { color: var(--primary); text-decoration: none; }
.mono { font-family: var(--font-mono); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; } }

/* ---------------------------------------------------------------------
   App shell: sidebar + main
   ------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 20px; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.nav-group { margin-bottom: 18px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); padding: 0 10px; margin-bottom: 6px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--ink-muted); font-size: 14px; font-weight: 500;
    margin-bottom: 2px; transition: background .15s, color .15s;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--primary-tint); color: var(--primary-dark); }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: var(--radius-sm); }
.user-chip:hover { background: var(--surface-2); cursor: pointer; }
.avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 600; font-size: 13px; font-family: var(--font-display);
}
.user-chip-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip-role { font-size: 11px; color: var(--ink-faint); }

.main { flex: 1; min-width: 0; padding: 28px 34px 60px; max-width: 1180px; margin: 0 auto; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-head p { margin: 0; }

/* ---------------------------------------------------------------------
   Cards / grid
   ------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .18s ease, transform .18s ease;
}
.card-interactive { cursor: pointer; }
.card-interactive:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 500; color: var(--ink); }
.stat-label { font-size: 12.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-sub { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; }

/* ---------------------------------------------------------------------
   Buttons / inputs (shadcn-style)
   ------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
    padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
    cursor: pointer; transition: background .15s, border-color .15s, opacity .15s, transform .08s;
    line-height: 1;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 34px; height: 34px; padding: 0; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], select, textarea {
    width: 100%; font-family: var(--font-body); font-size: 14px; color: var(--ink);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 9px 11px; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
textarea { resize: vertical; min-height: 72px; font-family: var(--font-body); }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
@media (max-width: 560px) {
    .field-row { flex-direction: column; gap: 0; }
}
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }

/* Slider (mood/energy 1-10) */
input[type=range] {
    width: 100%; accent-color: var(--primary);
    height: 22px; /* larger hit area than the visual track for touch */
}
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-value {
    font-family: var(--font-mono); font-weight: 600; font-size: 15px; width: 30px; text-align: center;
    background: var(--primary-tint); color: var(--primary-dark); border-radius: 6px; padding: 4px 0;
    flex-shrink: 0;
}

/* Toggle chips (yes/no, adaptive follow-ups) */
.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); font-size: 13px; font-weight: 500; cursor: pointer; color: var(--ink-muted);
    transition: all .15s; user-select: none; min-height: 34px; display: inline-flex; align-items: center;
}
.chip:hover { border-color: var(--primary); }
.chip.selected { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge-primary { background: var(--primary-tint); color: var(--primary-dark); }
.badge-accent { background: var(--accent-tint); color: var(--accent); }
.badge-low { background: var(--low-tint); color: var(--low); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--ink-muted); }

/* ---------------------------------------------------------------------
   Crisis banner — always visually distinct from the calm brand palette
   ------------------------------------------------------------------- */
.crisis-banner {
    background: var(--danger-tint); border: 1px solid #E8B8A8; border-radius: var(--radius);
    padding: 16px 18px; margin-bottom: 20px; display: flex; gap: 12px; align-items: flex-start;
}
.crisis-banner svg { flex-shrink: 0; color: var(--danger); margin-top: 2px; }
.crisis-banner strong { color: var(--danger); display: block; margin-bottom: 3px; font-size: 14px; }
.crisis-banner p { color: #7A3323; font-size: 13.5px; margin: 0; }

/* ---------------------------------------------------------------------
   Timeline
   ------------------------------------------------------------------- */
.timeline-day { display: flex; gap: 16px; margin-bottom: 4px; }
.timeline-rail { display: flex; flex-direction: column; align-items: center; width: 18px; flex-shrink: 0; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); margin-top: 5px; }
.timeline-line { flex: 1; width: 2px; background: var(--border); margin-top: 4px; }
.timeline-content { flex: 1; padding-bottom: 26px; }
.timeline-date { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-faint); margin-bottom: 6px; }
.timeline-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* ---------------------------------------------------------------------
   Auth pages
   ------------------------------------------------------------------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background-color: var(--bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='40' viewBox='0 0 120 40'%3E%3Cpath d='M0 20c6 0 6-12 12-12s6 12 12 12 6-16 12-16 6 16 12 16 6-12 12-12 6 12 12 12 6-16 12-16 6 16 12 16 6-12 12-12 6 12 12 12' fill='none' stroke='%232F6F62' stroke-width='1.4' stroke-linecap='round' opacity='0.05'/%3E%3C/svg%3E");
    background-size: 240px 80px;
}
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px 30px; box-shadow: var(--shadow); }
@media (max-width: 420px) { .auth-card { padding: 26px 20px; } }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-error { background: var(--danger-tint); color: var(--danger); font-size: 13px; padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; display: none; }
.auth-switch { text-align: center; font-size: 13.5px; color: var(--ink-muted); margin-top: 16px; }

/* ---------------------------------------------------------------------
   Table
   ------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 480px; }

/* utility */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); font-size: 12.5px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-faint); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .45; }

/* Loading skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, #ece9e0 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Mobile nav */
.mobile-topbar { display: none; }
.mobile-nav { display: none; }
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { display: none; }
    .mobile-topbar {
        display: flex; align-items: center; justify-content: space-between;
        padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
        position: sticky; top: 0; z-index: 10;
    }
    .main { padding: 20px 16px 90px; }
    .mobile-nav {
        position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
        border-top: 1px solid var(--border); display: flex; justify-content: space-around;
        padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 10;
    }
    .mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--ink-faint); font-weight: 600; }
    .mobile-nav a.active { color: var(--primary); }
    .mobile-nav svg { width: 20px; height: 20px; }
}
