/* Author: Guo Jiali */
:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-soft: #f1f5f9;
    --text: #1e293b;
    --muted: #64748b;
    --hint: #94a3b8;
    --border: #e2e8f0;
    --outline: #cbd5e1;
    --primary: #45b5d6;
    --primary-dark: #2fa8c4;
    --secondary: #64e0b5;
    --green: #16a34a;
    --blue: #2563eb;
    --warm: #f59e0b;
    --danger: #ef4444;
    --danger-dark: #b91c1c;
    --danger-soft: #fef2f2;
    --success-soft: #dcfce7;
    --success-text: #166534;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.07);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: "Segoe UI", Arial, Helvetica, sans-serif;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 64px;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    font-weight: 900;
}

.brand-mark.small {
    width: 30px;
    height: 30px;
    font-size: 14px;
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nav a {
    padding: 8px 11px;
    color: var(--muted);
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.nav a.active,
.nav a:hover {
    color: var(--text);
    background: var(--surface-soft);
}

.page {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.page.narrow {
    width: min(720px, calc(100% - 32px));
}

.page-header,
.detail-topbar,
.section-header,
.home-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-header {
    margin-bottom: 22px;
}

.detail-topbar {
    min-height: 56px;
    margin: 0 0 16px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.home-topbar {
    margin-bottom: 28px;
}

.home-topbar h1,
h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.muted,
.help-text,
.empty-state {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.greeting {
    margin: 0 0 3px;
}

.empty-state {
    margin: 0;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.panel,
.auth-panel,
.insight-panel,
.insight-result,
.history-item,
.profile-card,
.chart-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel,
.auth-panel,
.insight-panel,
.insight-result,
.history-item,
.profile-card,
.chart-panel {
    padding: 22px;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-shell {
    width: min(440px, 100%);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.auth-switch {
    color: var(--muted);
    text-align: center;
}

.auth-switch a,
.section-header a,
.back-link {
    color: var(--primary-dark);
    font-weight: 800;
    text-decoration: none;
}

.form-stack {
    display: grid;
    gap: 12px;
}

label {
    color: var(--text);
    font-size: 14px;
    font-weight: 750;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--outline);
    border-radius: 8px;
    font: inherit;
    font-size: 15px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(69, 181, 214, 0.18);
}

button,
.button {
    font: inherit;
}

.button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button.primary {
    color: #ffffff;
    background: var(--primary);
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.secondary,
.icon-button {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
}

.button.danger {
    color: #ffffff;
    background: var(--danger);
}

.button.small,
.button.compact {
    min-height: 34px;
    padding: 7px 11px;
    font-size: 13px;
}

.button:disabled,
button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 650;
}

.alert.error {
    color: var(--danger-dark);
    background: var(--danger-soft);
}

.alert.success {
    color: var(--success-text);
    background: var(--success-soft);
}

.alert.info {
    color: #075985;
    background: #e0f2fe;
}

.field-error {
    margin: -5px 0 0;
    color: var(--danger-dark);
    font-size: 13px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.field-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.avatar-link,
.profile-avatar {
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    font-weight: 900;
    text-decoration: none;
}

.avatar-link {
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
}

.avatar-link img,
.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.settings-link {
    color: var(--muted);
    font-weight: 800;
    text-decoration: none;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.metric-card,
.tip-card,
.record-summary,
.add-choice-card,
.action-tile {
    display: grid;
    gap: 12px;
    min-height: 180px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.metric-card {
    color: var(--text);
}

.sleep-card,
.sleep-summary {
    background: linear-gradient(135deg, #ffffff, #eef6ff);
}

.exercise-card,
.exercise-summary {
    background: linear-gradient(135deg, #ffffff, #ecfdf5);
}

.card-head,
.record-summary,
.history-heading,
.rail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-icon,
.choice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 30px;
    padding: 0 10px;
    color: var(--blue);
    background: #dbeafe;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.card-icon.wide,
.choice-icon.wide {
    color: var(--green);
    background: #dcfce7;
}

.metric-line {
    display: grid;
    gap: 2px;
}

.metric-value {
    color: var(--blue);
    font-size: 34px;
    font-weight: 900;
    line-height: 1;
}

.exercise-card .metric-value {
    color: var(--green);
}

.metric-caption,
.mini-meta small {
    color: var(--hint);
    font-size: 12px;
}

.mini-meta {
    display: grid;
    justify-items: end;
    gap: 3px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 750;
}

.sparkline {
    min-height: 52px;
}

.sparkline svg,
.bar-chart svg {
    width: 100%;
    height: 100%;
    display: block;
}

.tip-card {
    grid-column: 1 / -1;
    min-height: 130px;
    color: var(--text);
    background: linear-gradient(135deg, #ffffff, #fffbeb);
}

.tip-card h2 {
    font-size: 22px;
}

.tip-card span {
    color: var(--warm);
    font-weight: 850;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.compact-actions {
    margin-top: 16px;
}

.action-tile {
    min-height: 116px;
    background: var(--surface);
}

.tile-title {
    font-size: 17px;
    font-weight: 900;
}

.tile-copy {
    color: var(--muted);
    line-height: 1.45;
}

.records-overview,
.two-column,
.profile-grid,
.insight-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.records-overview {
    margin-bottom: 22px;
}

.record-summary {
    min-height: 110px;
}

.section-list,
.manage-list,
.history-list,
.session-list,
.profile-forms,
.settings-list {
    display: grid;
    gap: 12px;
}

.date-label {
    margin: 14px 0 8px;
    color: var(--hint);
    font-size: 12px;
    font-weight: 850;
    text-transform: uppercase;
}

.record-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.record-main {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.record-main span,
.record-main small {
    color: var(--muted);
    font-size: 13px;
}

.row-actions,
.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.add-choice-page {
    min-height: calc(100vh - 64px);
    display: grid;
    align-content: center;
    gap: 24px;
}

.add-choice-page h1 {
    text-align: center;
}

.add-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.add-choice-card {
    min-height: 220px;
    place-items: center;
    text-align: center;
}

.add-choice-card strong {
    color: #475569;
    font-size: 18px;
}

.add-choice-card small {
    color: var(--hint);
}

.duration-pill,
.provider-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 32px;
    padding: 6px 12px;
    color: var(--muted);
    background: var(--surface-soft);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.stats-row {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.stats-row.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-row.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
    display: grid;
    justify-items: center;
    gap: 4px;
    padding: 18px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.stat-card strong {
    color: var(--blue);
    font-size: 28px;
    line-height: 1;
}

.stat-card strong.green {
    color: #34c759;
}

.stat-card strong.warm {
    color: var(--warm);
}

.stat-card span {
    color: var(--hint);
    font-size: 12px;
}

.week-nav {
    display: grid;
    grid-template-columns: 80px 1fr 80px;
    align-items: center;
    margin: 10px 0 16px;
    color: var(--text);
}

.week-nav a {
    color: var(--muted);
    font-weight: 850;
    text-decoration: none;
}

.week-nav a:last-child {
    text-align: right;
}

.week-nav strong {
    text-align: center;
}

.chart-panel {
    margin-bottom: 16px;
}

.chart-panel .section-header {
    margin-bottom: 14px;
}

.chart-panel .section-header span {
    color: var(--hint);
    font-size: 12px;
    font-weight: 800;
}

.bar-chart {
    position: relative;
    min-height: 280px;
}

.breakdown-list {
    display: grid;
    gap: 12px;
}

.breakdown-row {
    display: grid;
    grid-template-columns: 130px 1fr 70px;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.breakdown-track {
    height: 10px;
    overflow: hidden;
    background: var(--surface-soft);
    border-radius: 999px;
}

.breakdown-track i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), #86efac);
    border-radius: inherit;
}

.chat-body {
    overflow: hidden;
}

.chat-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    height: calc(100vh - 64px);
    background: var(--bg);
}

.chat-main {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    min-width: 0;
}

.character-stage {
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 210px;
    padding: 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.yui-avatar {
    display: grid;
    place-items: center;
    width: 148px;
    height: 148px;
    color: #ffffff;
    background: radial-gradient(circle at 35% 30%, #93c5fd, var(--primary));
    border-radius: 50%;
    box-shadow: 0 18px 40px rgba(69, 181, 214, 0.28);
    font-size: 24px;
    font-weight: 900;
}

.yui-avatar.agent {
    background: radial-gradient(circle at 35% 30%, #fef3c7, var(--warm));
}

.chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.mode-toggle {
    display: inline-flex;
    padding: 3px;
    background: var(--surface-soft);
    border-radius: 8px;
}

.mode-toggle button {
    min-width: 70px;
    min-height: 30px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 7px;
    font-weight: 850;
    cursor: pointer;
}

.mode-toggle button.active {
    color: #ffffff;
    background: var(--primary);
}

.chat-window {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
}

.empty-chat {
    align-self: center;
    max-width: 420px;
    margin: auto;
    padding: 22px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
}

.chat-bubble {
    max-width: min(720px, 82%);
    padding: 11px 13px;
    border-radius: 8px;
    line-height: 1.5;
}

.chat-bubble p {
    margin: 0;
    white-space: pre-wrap;
}

.chat-bubble.user {
    align-self: flex-end;
    color: #ffffff;
    background: var(--primary);
}

.chat-bubble.ai {
    align-self: flex-start;
    background: var(--surface-soft);
}

.message-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
    color: var(--hint);
    font-size: 12px;
}

.chat-form {
    display: grid;
    grid-template-columns: 1fr 62px;
    gap: 8px;
    padding: 8px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.send-button {
    color: #ffffff;
    background: var(--primary);
    border: 0;
    border-radius: 8px;
    font-weight: 900;
    cursor: pointer;
}

.session-rail {
    min-width: 0;
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
}

.rail-header {
    min-height: 56px;
    padding: 12px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.session-list {
    padding: 10px;
}

.session-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
}

.session-item.active {
    background: #e0f2fe;
}

.session-item button {
    width: 100%;
    padding: 0;
    color: inherit;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
}

.session-item strong,
.session-item span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-item span {
    color: var(--muted);
    font-size: 12px;
}

.delete-text {
    color: var(--danger);
    background: transparent;
    border: 0;
    font-weight: 850;
    cursor: pointer;
}

.loading-panel {
    margin-top: 16px;
    padding: 16px;
    background: var(--surface-soft);
    border-radius: 8px;
}

.loading-panel[hidden] {
    display: none;
}

.recommendation-text {
    font-size: 20px;
    line-height: 1.55;
}

.evidence-box {
    margin-top: 16px;
    padding: 14px;
    background: var(--surface-soft);
    border-radius: 8px;
}

.evidence-box summary,
.history-item summary {
    cursor: pointer;
    font-weight: 850;
}

.history-preview {
    margin-top: 18px;
}

.history-list.compact .history-item {
    box-shadow: none;
}

.profile-grid {
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
}

.profile-card {
    display: grid;
    justify-items: center;
    gap: 12px;
}

.profile-avatar {
    width: 104px;
    height: 104px;
    font-size: 40px;
}

.profile-card h2 {
    font-size: 22px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
}

.settings-row div {
    display: grid;
    gap: 3px;
}

.settings-row span {
    color: var(--muted);
    font-size: 13px;
}

.language-row select {
    width: 150px;
}

.danger-zone {
    margin-top: 18px;
    border-color: #fecaca;
}

@media (max-width: 900px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        padding: 12px 16px;
    }

    .nav {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .chat-shell {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 122px);
    }

    .session-rail {
        order: -1;
        max-height: 220px;
        border-left: 0;
        border-bottom: 1px solid var(--border);
    }

    .chat-body {
        overflow: auto;
    }

    .chat-main {
        min-height: 760px;
    }
}

@media (max-width: 720px) {
    .page-header,
    .detail-topbar,
    .home-topbar,
    .record-row,
    .settings-row {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-grid,
    .records-overview,
    .two-column,
    .profile-grid,
    .insight-layout,
    .add-choice-grid,
    .action-grid,
    .stats-row.three,
    .stats-row.two,
    .field-grid,
    .field-grid.three {
        grid-template-columns: 1fr;
    }

    .tip-card {
        grid-column: auto;
    }

    .row-actions,
    .form-actions {
        width: 100%;
    }

    .row-actions .button,
    .row-actions form,
    .row-actions button,
    .form-actions .button,
    .form-actions button {
        flex: 1;
    }

    .character-stage {
        min-height: 170px;
    }

    .yui-avatar {
        width: 96px;
        height: 96px;
        font-size: 18px;
    }

    .chat-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .mode-toggle {
        width: 100%;
    }

    .mode-toggle button {
        flex: 1;
    }

    .breakdown-row {
        grid-template-columns: 1fr;
    }

    .week-nav {
        grid-template-columns: 58px 1fr 58px;
        font-size: 13px;
    }
}
