/* ============================================================
   Brainwave — VoiceFlow Design System
   ============================================================ */

:root {
    --bg: #f5f0e8;
    --card-bg: #ffffff;
    --navy: #1e3a5f;
    --navy-light: #2a4d72;
    --navy-hover: #15304f;
    --text-primary: #1e3a5f;
    --text-secondary: #5a6b7f;
    --text-muted: #8a95a5;
    --border: #e2ddd5;
    --border-light: #ebe6de;
    --shadow: 0 1px 3px rgba(30, 58, 95, 0.06), 0 1px 2px rgba(30, 58, 95, 0.04);
    --shadow-md: 0 4px 12px rgba(30, 58, 95, 0.08), 0 2px 4px rgba(30, 58, 95, 0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-pill: 100px;
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.2s ease;

    /* Status colors */
    --green: #34C759;
    --orange: #FF9500;
    --red: #FF3B30;
    --blue: #007AFF;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   App Layout
   ============================================================ */

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 20px;
    gap: 12px;
}

/* ============================================================
   Top Bar
   ============================================================ */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    flex-shrink: 0;
    min-height: 44px;
}

.top-bar-left {
    flex: 1;
}

.top-bar-center {
    flex: 0 0 auto;
}

.top-bar-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: -0.02em;
}

/* Mode Toggle (pill) */
.mode-toggle {
    display: flex;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 3px;
    gap: 2px;
}

.mode-btn {
    padding: 6px 20px;
    border: none;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.mode-btn.active {
    background: var(--navy);
    color: #fff;
}

.mode-btn:hover:not(.active) {
    color: var(--text-primary);
    background: var(--border-light);
}

/* Model Selector */
.model-selector {
    position: relative;
}

.model-selector select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 6px 32px 6px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font);
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%235a6b7f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color var(--transition);
}

.model-selector select:hover {
    border-color: var(--navy);
}

.model-selector select:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.15);
}

/* ============================================================
   Timer
   ============================================================ */

.timer {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
    height: 20px;
    line-height: 20px;
    font-variant-numeric: tabular-nums;
}

.timer.active {
    color: var(--red);
    font-weight: 600;
}

/* ============================================================
   Main Content
   ============================================================ */

.main-content {
    flex: 1;
    min-height: 0;
    display: flex;
}

.content-card {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.view-active {
    display: flex;
}

.view-hidden {
    display: none !important;
}

/* ============================================================
   Transcribe Mode
   ============================================================ */

.transcript-area {
    flex: 1;
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: 24px;
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: transparent;
    font-family: var(--font);
}

.transcript-area::placeholder {
    color: var(--text-muted);
}

/* ============================================================
   Editor Mode
   ============================================================ */

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.editor-toolbar::-webkit-scrollbar {
    height: 4px;
}

.editor-toolbar::-webkit-scrollbar-track {
    background: transparent;
}

.editor-toolbar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    flex-shrink: 0;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.toolbar-btn:active {
    background: var(--border);
}

.toolbar-label {
    margin-left: 2px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 6px;
    flex-shrink: 0;
}

.editor-split {
    flex: 1;
    display: flex;
    min-height: 0;
}

.editor-textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 20px;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: transparent;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

.editor-textarea::placeholder {
    color: var(--text-muted);
    font-family: var(--font);
}

.editor-divider {
    width: 1px;
    background: var(--border-light);
    flex-shrink: 0;
}

.editor-preview {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.preview-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* Editor preview typography */
.editor-preview h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 12px 0;
    color: var(--navy);
}

.editor-preview h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: var(--navy);
}

.editor-preview h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 12px 0 6px 0;
    color: var(--navy);
}

.editor-preview p {
    margin: 0 0 12px 0;
}

.editor-preview strong {
    font-weight: 600;
    color: var(--navy);
}

.editor-preview em {
    font-style: italic;
}

.editor-preview ul, .editor-preview ol {
    margin: 0 0 12px 0;
    padding-left: 24px;
}

.editor-preview li {
    margin-bottom: 4px;
}

.editor-preview code {
    background: var(--border-light);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.9em;
}

.editor-preview blockquote {
    border-left: 3px solid var(--navy);
    margin: 0 0 12px 0;
    padding: 4px 16px;
    color: var(--text-secondary);
}

.editor-preview del {
    text-decoration: line-through;
    color: var(--text-muted);
}

.editor-preview pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0 0 12px 0;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.85em;
    line-height: 1.6;
}

.editor-preview pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
}

.editor-preview hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 16px 0;
}

.editor-preview a {
    color: var(--blue);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.editor-preview a:hover {
    color: var(--navy);
}

.editor-preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

/* ============================================================
   Bottom Controls
   ============================================================ */

.bottom-controls {
    flex-shrink: 0;
    padding: 8px 0 4px 0;
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

/* Status Pill */
.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 100px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--blue);
    flex-shrink: 0;
    transition: background-color var(--transition);
}

.status-pill.connected .status-dot {
    background: var(--green);
}

.status-pill.connecting .status-dot {
    background: var(--orange);
    animation: pulse-dot 1.5s infinite;
}

.status-pill.recording .status-dot {
    background: var(--red);
    animation: pulse-dot 1.5s infinite;
}

.status-pill.idle .status-dot {
    background: var(--blue);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.control-btn:hover {
    border-color: var(--navy);
    color: var(--navy);
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn:disabled:hover {
    border-color: var(--border);
    color: var(--text-secondary);
    box-shadow: none;
}

/* Record Button (primary) */
.record-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    box-shadow: var(--shadow-md);
}

.record-btn:hover {
    background: var(--navy-hover);
    transform: scale(1.05);
}

.record-btn:active {
    transform: scale(0.95);
}

.record-btn.recording {
    background: var(--red);
    animation: pulse-record 2s infinite;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes pulse-record {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4); }
    50% { transform: scale(1.03); box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 59, 48, 0); }
}

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

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .app {
        padding: 12px 12px;
        gap: 8px;
    }

    .top-bar {
        flex-wrap: wrap;
        gap: 8px;
    }

    .top-bar-left {
        order: 1;
        flex: 0 0 auto;
    }

    .top-bar-right {
        order: 2;
        flex: 0 0 auto;
    }

    .top-bar-center {
        order: 3;
        flex: 1 0 100%;
        display: flex;
        justify-content: center;
    }

    .mode-btn {
        padding: 6px 16px;
        font-size: 0.8rem;
    }

    /* Editor: stack vertically on mobile */
    .editor-split {
        flex-direction: column;
    }

    .editor-divider {
        width: 100%;
        height: 1px;
    }

    .editor-textarea,
    .editor-preview {
        min-height: 30vh;
    }

    .toolbar-label {
        display: none;
    }

    .controls-row {
        gap: 12px;
    }

    .status-pill {
        min-width: auto;
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .control-btn {
        width: 38px;
        height: 38px;
    }

    .record-btn {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1.1rem;
    }

    .model-selector select {
        font-size: 0.8rem;
        padding: 5px 28px 5px 12px;
    }

    .transcript-area {
        padding: 16px;
        font-size: 0.95rem;
    }

    .editor-textarea,
    .editor-preview {
        padding: 14px;
        font-size: 0.9rem;
    }

    .status-text {
        display: none;
    }

    .status-pill {
        min-width: auto;
        padding: 6px 8px;
    }
}

/* ============================================================
   Copy feedback toast
   ============================================================ */

.copy-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--navy);
    color: #fff;
    padding: 8px 20px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 100;
}

.copy-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
