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

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --primary: #e94560;
    --primary-hover: #ff6b81;
    --text: #eee;
    --text-muted: #aaa;
    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

.view {
    min-height: 100vh;
}

/* ---- Login ---- */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

.login-container h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 280px;
}

#pin-input {
    background: var(--surface);
    border: 2px solid #333;
    color: var(--text);
    font-size: 1.5rem;
    text-align: center;
    padding: 0.75rem;
    border-radius: var(--radius);
    letter-spacing: 0.5rem;
    outline: none;
    transition: border-color 0.2s;
}

#pin-input:focus {
    border-color: var(--primary);
}

#login-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.75rem;
    font-size: 1.1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
}

#login-btn:hover {
    background: var(--primary-hover);
}

.error {
    color: var(--danger);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
}

/* ---- App Header ---- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--surface);
}

header h1 {
    font-size: 1.25rem;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#connection-status {
    font-size: 0.7rem;
}

#connection-status.online {
    color: var(--success);
}

#connection-status.offline {
    color: var(--danger);
    animation: blink 1.5s infinite;
}

@keyframes blink {
    50% { opacity: 0.3; }
}

#logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

/* ---- Main ---- */
main {
    padding: 1.25rem;
    max-width: 500px;
    margin: 0 auto;
}

/* ---- Recorder ---- */
#recorder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#visualizer-container {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.75rem;
}

#visualizer {
    width: 100%;
    height: 80px;
    display: block;
}

#timer {
    font-size: 2.5rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.1rem;
}

#status-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

#controls {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.5rem;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.15s;
}

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

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    font-size: 1.5rem;
}

.btn-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.record .btn-icon {
    background: var(--primary);
    color: #fff;
    font-size: 2rem;
}

.pause .btn-icon {
    background: var(--warning);
    color: #fff;
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.stop .btn-icon {
    background: var(--danger);
    color: #fff;
}

/* Recording pulse */
.recording .record .btn-icon {
    animation: pulse 1.2s infinite;
    box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.7);
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.7); }
    70% { box-shadow: 0 0 0 16px rgba(233, 69, 96, 0); }
    100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0); }
}

/* Paused state */
.paused .record .btn-icon {
    animation: pulse-orange 1.2s infinite;
    background: var(--warning);
}

@keyframes pulse-orange {
    0% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.7); }
    70% { box-shadow: 0 0 0 16px rgba(243, 156, 18, 0); }
    100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); }
}

/* ---- Result ---- */
#result {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-top: 1.5rem;
}

#result h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--success);
}

#result-text {
    line-height: 1.6;
    margin-bottom: 1rem;
    white-space: pre-wrap;
}

#title-section {
    margin-bottom: 1rem;
}

#note-title {
    width: 100%;
    background: var(--bg);
    border: 1px solid #333;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
}

#note-title:focus {
    border-color: var(--primary);
}

/* ---- Mode Selector ---- */
#mode-section {
    border-top: 1px solid #333;
    padding-top: 1rem;
    margin-bottom: 1rem;
}

#mode-section h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

#mode-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.mode-btn {
    background: var(--bg);
    border: 1px solid #333;
    color: var(--text-muted);
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn:hover {
    border-color: var(--primary);
}

.mode-btn.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

#processed-preview {
    background: var(--bg);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
}

#processed-preview h2,
#processed-preview h3 {
    color: var(--primary);
    margin: 12px 0 6px 0;
}

#processed-preview ul {
    padding-left: 20px;
    margin: 8px 0;
}

#processed-preview li {
    margin: 4px 0;
}

#processed-preview p {
    margin: 8px 0;
}

#process-status {
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

#process-status.loading {
    color: var(--warning);
}

#process-status.error {
    color: var(--danger);
}

/* ---- Email Section ---- */
#email-section {
    border-top: 1px solid #333;
    padding-top: 1rem;
}

#email-section h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

#email-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.email-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg);
    border: 1px solid #333;
    color: var(--text-muted);
    padding: 0.35rem 0.65rem;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.email-chip:hover {
    border-color: var(--primary);
}

.email-chip.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.email-chip .remove-email {
    font-size: 0.7rem;
    opacity: 0.6;
    cursor: pointer;
    margin-left: 0.15rem;
}

.email-chip .remove-email:hover {
    opacity: 1;
}

#email-add {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

#new-email {
    flex: 1;
    background: var(--bg);
    border: 1px solid #333;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
}

#new-email:focus {
    border-color: var(--primary);
}

#add-email-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#action-buttons {
    display: flex;
    gap: 0.5rem;
}

.save-btn {
    flex: 1;
    background: var(--surface);
    border: 1px solid #555;
    color: var(--text);
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}

.save-btn:hover {
    background: #2a2a4a;
}

.send-btn {
    flex: 1;
    background: var(--success);
    color: #fff;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
}

.send-btn:hover:not(:disabled) {
    background: #27ae60;
}

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

#send-status {
    text-align: center;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

#send-status.success {
    color: var(--success);
}

#send-status.error {
    color: var(--danger);
}

/* ---- Processing ---- */
#processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--surface);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

#processing-text {
    color: var(--text-muted);
}

/* ---- Pending Queue ---- */
#pending-section {
    margin-top: 2rem;
    background: #1c1225;
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    padding: 1rem;
}

#pending-section h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--warning);
}

#pending-count {
    font-size: 0.8rem;
    background: var(--warning);
    color: #000;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
}

.pending-item {
    background: var(--surface);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.pending-item .pending-info {
    color: var(--text-muted);
}

.pending-item .pending-duration {
    color: var(--text);
    font-weight: 500;
}

.pending-item .pending-syncing {
    color: var(--warning);
    font-size: 0.8rem;
}

.pending-transcribe-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 0.5rem;
}

.pending-transcribe-btn:hover {
    background: var(--primary-hover);
}

.pending-item > div:last-child {
    display: flex;
    align-items: center;
}

/* ---- History ---- */
#history {
    margin-top: 2rem;
}

#history h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.history-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: #1e2a4a;
}

.history-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-send-btn {
    background: none;
    border: 1px solid #444;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}

.history-send-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.history-title {
    font-weight: 500;
    font-size: 0.95rem;
}

.history-preview {
    display: none;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #333;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--text-muted);
}

.history-item.expanded .history-preview {
    display: block;
}

.history-empty {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
}
