/* ── Design tokens ─────────────────────────────────────── */
:root {
    --blue:       #0045C5;
    --blue-dark:  #003399;
    --blue-light: #1A5ADB;
    --gold:       #FFD600;
    --gold-dark:  #E6C000;
    --navy:       #0A1A4A;
    --navy-mid:   #1E2E5C;

    --bg:         #F0F4FF;
    --surface:    #FFFFFF;
    --surface-2:  #F7F9FF;
    --text:       #0A1A4A;
    --text-muted: #4A5580;
    --border:     #D0D8F0;

    --accent:     var(--blue);
    --accent-btn: var(--gold);
    --accent-btn-text: var(--navy);

    --radius:     12px;
    --radius-sm:  8px;
    --nav-h:      64px;
    --header-h:   56px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:         #070E2B;
        --surface:    #0F1D45;
        --surface-2:  #132255;
        --text:       #E8EDFF;
        --text-muted: #8899CC;
        --border:     #1E2E5C;
        --blue:       #1A5ADB;
        --blue-dark:  #0045C5;
    }
}

[data-theme="dark"] {
    --bg:         #070E2B;
    --surface:    #0F1D45;
    --surface-2:  #132255;
    --text:       #E8EDFF;
    --text-muted: #8899CC;
    --border:     #1E2E5C;
    --blue:       #1A5ADB;
    --blue-dark:  #0045C5;
}

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

html { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; }

/* ── Top header ────────────────────────────────────────── */
.app-header {
    background: #0045C5;
    color: #fff;
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top, 0px);
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 100;
    gap: 12px;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
    flex: 1;
}

.app-header .header-date {
    font-size: 13px;
    opacity: 0.8;
    font-weight: 400;
}

/* ── Bottom nav ────────────────────────────────────────── */
.nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #0045C5;
    display: flex;
    align-items: stretch;
    z-index: 200;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.15s;
    padding-top: 4px;
}

.nav-item .nav-icon {
    font-size: 22px;
    line-height: 1;
}

.nav-item.active {
    color: #FFD600;
}

.nav-item:hover {
    color: rgba(255,255,255,0.9);
}

/* ── Page content ──────────────────────────────────────── */
.page-content {
    padding: 16px;
    max-width: 640px;
    margin: 0 auto;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ── Scale row (home + history) ────────────────────────── */
.scale-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 14px 16px;
    margin-bottom: 10px;
}

.scale-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.scale-locked-icon {
    font-size: 12px;
    opacity: 0.6;
}

.emoji-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.emoji-btn {
    font-size: 30px;
    line-height: 1;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: transform 0.1s, background 0.15s, border-color 0.15s;
    opacity: 0.45;
    position: relative;
}

.emoji-btn:hover:not(:disabled) {
    opacity: 0.75;
    transform: scale(1.08);
}

.emoji-btn.selected {
    opacity: 1;
    background: #FFF5B0;
    border-color: #FFD600;
    transform: scale(1.1);
}

.emoji-btn:disabled {
    cursor: default;
}

.emoji-btn.selected:disabled {
    opacity: 1;
    background: #FFF5B0;
    border-color: #FFD600;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .emoji-btn.selected {
        background: #2A2010;
        border-color: #FFD600;
    }
}

[data-theme="dark"] .emoji-btn.selected {
    background: #2A2010;
    border-color: #FFD600;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
    background: #0045C5;
    color: #fff;
}

.btn-gold {
    background: #FFD600;
    color: #0A1A4A;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-danger {
    background: #DC2626;
    color: #fff;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

/* ── FAB ────────────────────────────────────────────────── */
.fab {
    position: fixed;
    bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #FFD600;
    color: #0A1A4A;
    border: none;
    font-size: 26px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 150;
    transition: transform 0.15s;
    text-decoration: none;
}

.fab:active { transform: scale(0.93); }

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s;
    -webkit-appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: #0045C5;
}

.form-error {
    color: #DC2626;
    font-size: 13px;
    margin-top: 4px;
}

/* ── Login page ─────────────────────────────────────────── */
.login-wrap {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: #0045C5;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo .logo-emoji {
    font-size: 48px;
    display: block;
    margin-bottom: 6px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 800;
    color: #0045C5;
    letter-spacing: -0.5px;
}

/* ── Modals ─────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop.center {
    align-items: center;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px;
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
}

.modal-backdrop.center .modal {
    border-radius: var(--radius);
    max-width: 380px;
    margin: 16px;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions .btn { flex: 1; }

/* ── Scale management ───────────────────────────────────── */
.scale-list-item {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.scale-list-item.dragging {
    opacity: 0.5;
    border-color: #0045C5;
}

.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    font-size: 18px;
    padding: 4px;
    touch-action: none;
}

.drag-handle:active { cursor: grabbing; }

.scale-list-info {
    flex: 1;
    min-width: 0;
}

.scale-list-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.scale-list-emojis {
    font-size: 18px;
    margin-top: 2px;
}

.scale-list-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s;
}

.icon-btn:hover { background: var(--border); }
.icon-btn.danger:hover { background: #FEE2E2; color: #DC2626; }

/* ── Emoji chips (scale editor) ─────────────────────────── */
.emoji-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
    padding: 8px;
    border-radius: var(--radius-sm);
    border: 1.5px dashed var(--border);
    background: var(--surface-2);
}

.emoji-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 8px 4px 10px;
    font-size: 20px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.emoji-chip .chip-remove {
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 2px;
}

.add-emoji-btn {
    background: var(--surface);
    border: 1.5px dashed #0045C5;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #0045C5;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.emoji-type-input {
    margin-top: 10px;
    font-size: 20px;
}

/* ── Calendar ───────────────────────────────────────────── */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.calendar-month {
    font-size: 17px;
    font-weight: 700;
}

.calendar-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-dow {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    padding-bottom: 4px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    transition: background 0.1s;
}

.calendar-day:hover { background: var(--surface-2); }
.calendar-day.empty { pointer-events: none; }
.calendar-day.today { font-weight: 800; color: #0045C5; }
.calendar-day.has-ratings::after {
    content: '';
    position: absolute;
    bottom: 3px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #FFD600;
}

.calendar-day.today.has-ratings::after { background: #0045C5; }

/* ── Charts ─────────────────────────────────────────────── */
.chart-section {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    margin-bottom: 16px;
}

.chart-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
    flex-wrap: wrap;
}

.chart-title {
    font-size: 16px;
    font-weight: 700;
}

.archived-badge {
    font-size: 11px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 20px;
}

.time-range-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}

.time-range-tab {
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.time-range-tab.active {
    background: #0045C5;
    border-color: #0045C5;
    color: #fff;
}

.custom-range-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.custom-range-row .form-input {
    flex: 1;
    min-width: 120px;
    font-size: 13px;
    padding: 7px 10px;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    width: calc(100% - 32px);
    max-width: 400px;
}

.toast {
    background: var(--navy);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-align: center;
    animation: toastIn 0.25s ease, toastOut 0.3s ease 2.5s forwards;
}

.toast.success { background: #15803D; }
.toast.error   { background: #DC2626; }

@keyframes toastIn  { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { to   { opacity:0; transform:translateY(10px); } }

/* ── Archived section toggle ────────────────────────────── */
.section-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border: none;
    background: none;
    width: 100%;
}

/* ── Loading spinner ────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: #0045C5;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state .empty-emoji {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 16px;
}

/* ── Utilities ──────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* ── Drag-over indicator ────────────────────────────────── */
.drag-over {
    border-color: #0045C5 !important;
    background: #EEF3FF !important;
}

/* ── WebAuthn face-id button ────────────────────────────── */
.faceid-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    border: 2px solid #0045C5;
    background: transparent;
    color: #0045C5;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    transition: background 0.15s;
}

.faceid-btn:hover {
    background: #EEF3FF;
}

/* ── Setup / one-time pages ─────────────────────────────── */
.setup-wrap {
    max-width: 480px;
    margin: 40px auto;
    padding: 0 20px 80px;
}

.setup-wrap h1 {
    font-size: 22px;
    font-weight: 800;
    color: #0045C5;
    margin-bottom: 24px;
}

.qr-placeholder {
    background: var(--surface-2);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin: 16px 0;
}

/* ── Day view (history detail) ──────────────────────────── */
.day-view-header {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.day-view-btn-row {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}
