/* ── Design Tokens ─────────────────────────── */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a2e;
    --bg-chat-user: #2d1b69;
    --bg-chat-ai: #1a1a2e;
    --surface-glass: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-active: rgba(139, 92, 246, 0.4);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --accent: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.15);
    --accent-hover: #a78bfa;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;

    --font-sans: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ── Screens ──────────────────────────────── */
.screen {
    display: none;
    height: 100%;
}
.screen.active {
    display: flex;
}

/* ── Auth Screen ──────────────────────────── */
.auth-container {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2xl);
    padding: var(--space-xl);
}

.auth-logo {
    text-align: center;
}

.logo-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #6366f1, #ec4899);
    margin: 0 auto var(--space-lg);
    position: relative;
    animation: pulse-glow 3s ease-in-out infinite;
}
.logo-circle.small {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-md);
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
    50% { box-shadow: 0 0 40px var(--accent-glow), 0 0 60px rgba(139, 92, 246, 0.08); }
}

.auth-logo h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-tagline {
    color: var(--text-secondary);
    margin-top: var(--space-sm);
    font-size: 0.95rem;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    width: 100%;
    max-width: 320px;
}

.btn-auth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 14px var(--space-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--surface-glass);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}
.btn-auth:hover {
    background: var(--surface-hover);
    border-color: var(--border-active);
}
.btn-dev {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ── Chat Layout ──────────────────────────── */
#chat-screen {
    flex-direction: row;
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}
.sidebar-header h2 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.conv-item {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all var(--duration-fast);
    margin-bottom: 2px;
}
.conv-item:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.conv-item.active {
    background: var(--accent-glow);
    color: var(--text-primary);
    border: 1px solid var(--border-active);
}
.conv-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-item-title.placeholder {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.conv-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
    flex-shrink: 0;
    padding-left: var(--space-sm);
}

.sidebar-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-tertiary);
}

/* ── Chat Main ────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}
.chat-header h3 {
    font-size: 0.95rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    scroll-behavior: smooth;
}

/* ── Welcome ──────────────────────────────── */
.welcome {
    margin: auto;
    text-align: center;
    padding: var(--space-2xl);
    max-width: 400px;
}
.welcome h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}
.welcome p {
    color: var(--text-secondary);
    line-height: 1.8;
}

/* ── Message Bubbles ──────────────────────── */
.message {
    max-width: 720px;
    width: fit-content;
    animation: msg-in var(--duration-normal) var(--ease-out);
}
.message.user {
    align-self: flex-end;
}
.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    line-height: 1.7;
    word-break: break-word;
}
.message.user .message-bubble {
    background: var(--bg-chat-user);
    border-bottom-right-radius: var(--space-xs);
}
.message.assistant .message-bubble {
    background: var(--bg-chat-ai);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: var(--space-xs);
}
.message-bubble p { margin-bottom: 0.5em; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble strong { color: var(--accent-hover); }
.message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: rgba(255,255,255,0.06);
    padding: 2px 6px;
    border-radius: 4px;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Typing Indicator ─────────────────────── */
.typing-indicator {
    padding: 0 var(--space-lg) var(--space-sm);
    display: flex;
    gap: 4px;
    align-items: center;
}
.typing-indicator.hidden { display: none; }
.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input Area ───────────────────────────── */
.input-area {
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    background: var(--bg-primary);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-lg);
    transition: border-color var(--duration-fast);
}
.input-wrapper:focus-within {
    border-color: var(--border-active);
}

#message-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    min-height: 60px;
    padding: var(--space-sm) 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    overflow-y: auto;
}
#message-input::placeholder {
    color: var(--text-muted);
}

.btn-voice {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--duration-fast);
}
.btn-voice:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}
.btn-voice.recording {
    color: #fff;
    background: var(--danger);
    animation: pulse-record 1.5s ease-in-out infinite;
}
@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
}

/* Recording overlay inside input area */
.input-wrapper.recording {
    border-color: var(--danger);
    background: rgba(248, 113, 113, 0.06);
}
.recording-overlay {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    padding: var(--space-sm) 0;
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: 500;
}
.recording-overlay .rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: rec-blink 1s ease-in-out infinite;
}
@keyframes rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}
.recording-overlay .rec-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
}
.recording-overlay .rec-wave span {
    width: 3px;
    background: var(--danger);
    border-radius: 2px;
    animation: wave-bar 0.8s ease-in-out infinite;
}
.recording-overlay .rec-wave span:nth-child(1) { height: 6px; animation-delay: 0s; }
.recording-overlay .rec-wave span:nth-child(2) { height: 12px; animation-delay: 0.1s; }
.recording-overlay .rec-wave span:nth-child(3) { height: 18px; animation-delay: 0.2s; }
.recording-overlay .rec-wave span:nth-child(4) { height: 10px; animation-delay: 0.3s; }
.recording-overlay .rec-wave span:nth-child(5) { height: 14px; animation-delay: 0.15s; }
@keyframes wave-bar {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}
.recording-overlay .rec-timer {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Transcribing state */
.input-wrapper.transcribing {
    border-color: var(--accent);
}
.transcribing-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    padding: var(--space-sm) 0;
    color: var(--accent);
    font-size: 0.9rem;
}
.transcribing-indicator .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-subtle);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--duration-fast);
}
.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}
.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Buttons ──────────────────────────────── */
.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}
.btn-icon:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

/* ── Scrollbar ────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Dashboard Button ──────────────────────── */
.btn-dashboard {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--surface-glass);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--duration-fast);
}
.btn-dashboard:hover {
    background: var(--accent-glow);
    color: var(--accent-hover);
    border-color: var(--border-active);
}

/* ── Dashboard View ───────────────────────── */
.dashboard-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.dashboard-view.hidden { display: none; }

.dash-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}
.dash-header h3 {
    font-size: 0.95rem;
    font-weight: 500;
}

.dash-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    align-content: start;
}

.dash-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
}
.dash-card h4 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}
.card-header h4 { margin-bottom: 0; }

.btn-small {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-active);
    background: transparent;
    color: var(--accent);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--duration-fast);
}
.btn-small:hover {
    background: var(--accent-glow);
}
.btn-small:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    padding: var(--space-lg);
}

/* Calendar */
.calendar-card { grid-column: 1 / -1; }
.calendar-card .card-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}
.calendar-card .card-header h4 {
    margin-bottom: 0;
    min-width: 120px;
    text-align: center;
    font-size: 0.95rem;
    text-transform: none;
    letter-spacing: 0;
}
.btn-cal-nav {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
}
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
    padding: 0 var(--space-xs);
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    padding: 0 var(--space-xs);
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast);
    position: relative;
    min-height: 44px;
}
.cal-day:hover { background: var(--surface-hover); }
.cal-day.empty { cursor: default; }
.cal-day.today {
    border: 1px solid var(--accent);
}
.cal-day-num {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1;
}
.cal-day-mood {
    font-size: 1.1rem;
    line-height: 1;
    margin-top: 2px;
}
.cal-day-energy {
    font-size: 0.55rem;
    line-height: 1;
    margin-top: 1px;
}

/* Day detail */
.day-detail-card h4 {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.95rem;
}
.day-detail-summary {
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
}
.day-detail-meta {
    display: flex;
    gap: var(--space-lg);
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}
.day-detail-highlights {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}
.day-detail-highlights li {
    font-size: 0.88rem;
    color: var(--text-secondary);
    list-style: none;
    padding-left: var(--space-md);
    position: relative;
}
.day-detail-highlights li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--accent);
}

/* Streak */
.streak-card { grid-column: 1 / -1; }
.streak-display {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    justify-content: center;
}
.streak-flame {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}
.streak-label {
    font-size: 1rem;
    color: var(--text-secondary);
}
.streak-best {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--space-sm);
}

/* Radar */
.radar-card {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.radar-card canvas {
    max-width: 100%;
    height: auto;
}

/* Insights */
.insights-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.insight-item {
    padding: var(--space-sm) var(--space-md);
    background: var(--surface-glass);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.6;
    border-left: 3px solid var(--accent);
}

/* Actions */
.actions-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.action-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--surface-glass);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast);
}
.action-item:hover { background: var(--surface-hover); }
.action-item.done {
    opacity: 0.5;
    text-decoration: line-through;
}
.action-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}
.action-item.done .action-check {
    border-color: var(--success);
    background: var(--success);
}
.action-item.done .action-check::after {
    content: "✓";
    color: var(--bg-primary);
    font-size: 0.75rem;
    font-weight: 700;
}
.action-text { font-size: 0.9rem; line-height: 1.5; }
.action-difficulty {
    margin-left: auto;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--surface-hover);
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ── Responsive ───────────────────────────── */
.mobile-only { display: none; }

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform var(--duration-normal) var(--ease-out);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .mobile-only {
        display: flex;
    }
    .messages {
        padding: var(--space-md);
    }
    .input-area {
        padding: var(--space-sm) var(--space-md) var(--space-md);
    }
    .dash-content {
        grid-template-columns: 1fr;
        padding: var(--space-md);
    }
}
