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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --recording: #dc2626;
    --recording-dark: #b91c1c;
    --success: #16a34a;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 33%;
    --sidebar-min-width: 250px;
    --sidebar-max-width: 50%;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* App Layout */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-min-width);
    max-width: var(--sidebar-max-width);
    height: 100vh;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Sidebar Resize Handle */
.sidebar-resize {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    transition: background 0.2s ease;
    z-index: 10;
}

.sidebar-resize:hover,
.sidebar-resize.resizing {
    background: var(--primary);
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--bg);
    color: var(--primary);
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.visible {
    display: block;
}

/* Main Content */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 1rem;
}

.container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
    padding-top: 1rem;
}

.user-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.user-name {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.lang-toggle {
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--card-bg);
    border: 1px solid var(--primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.lang-toggle:hover {
    background: var(--primary);
    color: white;
}

.lang-code {
    font-weight: 700;
}

.logout-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    color: var(--recording);
    border-color: var(--recording);
    background: #fef2f2;
}

h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.transcription-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    min-height: 200px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.transcription-textarea {
    width: 100%;
    min-height: 150px;
    font-size: 1.125rem;
    line-height: 1.75;
    font-family: inherit;
    border: none;
    outline: none;
    resize: vertical;
    background: transparent;
    color: var(--text);
}

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

.transcription-textarea:focus {
    background: #f8fafc;
    border-radius: 8px;
    margin: -8px;
    padding: 8px;
    width: calc(100% + 16px);
}

.transcription-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.transcription-status {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.transcription-status.editing {
    color: var(--primary);
}

.transcription-status.saved {
    color: var(--success);
}

.save-review-btn {
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
    background: var(--success);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-review-btn:hover:not(:disabled) {
    background: #15803d;
}

.save-review-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.mic-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    position: relative;
    width: 150px;
}

.mic-button.mic-batch {
    background: #7c3aed;
}

.mic-button.mic-batch:hover {
    background: #6d28d9;
}

.mic-button:hover {
    transform: scale(1.02);
}

.mic-button.mic-streaming:hover {
    background: var(--primary-dark);
}

.mic-button:active,
.mic-button.recording {
    background: var(--recording);
    transform: scale(0.98);
}

.mic-button.recording {
    animation: pulse 1.5s ease-in-out infinite;
}

.button-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #f59e0b;
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
    }
    50% {
        box-shadow: 0 0 0 20px rgba(220, 38, 38, 0);
    }
}

.mic-icon {
    width: 48px;
    height: 48px;
}

.button-text {
    font-size: 1rem;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status.ready .status-dot {
    background: var(--success);
}

.status.recording .status-dot {
    background: var(--recording);
    animation: blink 1s ease-in-out infinite;
}

.status.processing .status-dot {
    background: var(--primary);
    animation: blink 0.5s ease-in-out infinite;
}

.status.error .status-dot {
    background: var(--recording);
}

.status.streaming .status-dot {
    background: var(--success);
    animation: streaming-pulse 0.8s ease-in-out infinite;
}

.status.streaming .status-text {
    color: var(--success);
    font-weight: 500;
}

@keyframes streaming-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

.audio-player-container {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.audio-player-container.visible {
    display: flex;
}

.audio-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.audio-player-container audio {
    width: 100%;
    max-width: 400px;
}

/* History Items */
.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-style: italic;
}

.history-item {
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    border-color: var(--primary);
    background: #f0f7ff;
}

.history-item.active {
    border-color: var(--primary);
    background: #dbeafe;
}

.history-item.has-review {
    border-left: 3px solid var(--success);
}

.reviewed-badge {
    display: inline-block;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--success);
    background: #dcfce7;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.history-duration {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--card-bg);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
}

.history-text {
    font-size: 0.875rem;
    color: var(--text);
    line-height: 1.5;
}

.refresh-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: var(--bg);
    color: var(--primary);
}

footer {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
    padding-bottom: 1rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 80%;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-resize {
        display: none;
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        width: 100%;
        padding-top: 4rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .transcription-box {
        min-height: 150px;
        padding: 1rem;
    }

    .mic-button {
        padding: 1rem 1.5rem;
        width: 130px;
    }

    .mic-icon {
        width: 40px;
        height: 40px;
    }

    .controls {
        gap: 20px;
    }
}

/* Prevent text selection during resize */
.resizing {
    user-select: none;
    -webkit-user-select: none;
}
