/* AI Radio Show - Control Panel */

:root {
    --bg: #1a1209;
    --bg-light: #2a2015;
    --bg-dark: #110c05;
    --accent: #e8791d;
    --accent-hover: #f59a4a;
    --accent-red: #cc2222;
    --accent-green: #5a8a3c;
    --text: #f5f0e5;
    --text-muted: #9a8b78;
    --radius: 12px;
    --radius-sm: 8px;
}

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

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

#app {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.header-buttons {
    display: flex;
    gap: 8px;
}

header button {
    background: var(--bg-light);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

header button:hover {
    background: #3a2e1f;
    border-color: rgba(232, 121, 29, 0.3);
}

.on-air-btn {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: background 0.2s;
}

.on-air-btn.off {
    background: #4a3d2e !important;
    border-color: transparent !important;
    color: var(--text-muted) !important;
}

.on-air-btn.on {
    background: var(--accent-red) !important;
    border-color: var(--accent-red) !important;
    animation: on-air-pulse 2s ease-in-out infinite;
}

@keyframes on-air-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.rec-btn {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #4a3d2e !important;
    color: var(--text-muted) !important;
    border-color: transparent !important;
    transition: background 0.2s;
}

.rec-btn.recording {
    background: var(--accent-red) !important;
    color: var(--text) !important;
    border-color: var(--accent-red) !important;
    animation: on-air-pulse 2s ease-in-out infinite;
}

.new-session-btn {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
}

.new-session-btn:hover {
    background: var(--accent-hover) !important;
}

.session-id {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: normal;
}

details.caller-background {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    line-height: 1.4;
}

details.caller-background summary {
    cursor: pointer;
    padding: 8px 10px;
    font-weight: bold;
    color: var(--text);
    font-size: 0.8rem;
}

details.caller-background > div {
    padding: 0 10px 10px;
    white-space: pre-wrap;
}

details.caller-background.hidden {
    display: none;
}

/* Main layout */
main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 700px) {
    main {
        grid-template-columns: 1fr;
    }
}

/* Sections */
section {
    background: var(--bg-light);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid rgba(232, 121, 29, 0.08);
}

section h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    color: var(--text-muted);
}

/* Callers */
.caller-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.caller-btn {
    background: var(--bg);
    color: var(--text);
    border: 2px solid transparent;
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.caller-btn:hover {
    border-color: var(--accent);
    background: #2a1e10;
}

.caller-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.call-status {
    text-align: center;
    padding: 8px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.hangup-btn {
    width: 100%;
    background: var(--accent-red);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.hangup-btn:hover {
    background: #e03030;
}

.hangup-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Chat */
.chat-section {
    grid-column: span 2;
}

@media (max-width: 700px) {
    .chat-section {
        grid-column: span 1;
    }
}

.chat-log {
    height: 300px;
    overflow-y: auto;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid rgba(232, 121, 29, 0.06);
}

.message {
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    line-height: 1.4;
}

.message.host {
    background: #3a2510;
}

.message.caller {
    background: #2a1a0a;
}

.message strong {
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
    margin-bottom: 4px;
}

.talk-controls {
    display: flex;
    gap: 10px;
}

.talk-btn {
    flex: 1;
    background: var(--accent);
    color: white;
    border: none;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.talk-btn:hover {
    background: var(--accent-hover);
}

.talk-btn.recording {
    background: var(--accent-red);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.type-btn {
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
    padding: 16px 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.type-btn:hover {
    border-color: var(--accent);
}

.status {
    text-align: center;
    padding: 12px;
    color: var(--accent);
    font-weight: bold;
}

.status.hidden {
    display: none;
}

/* Music */
.music-section select {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.music-section select optgroup {
    color: var(--accent);
    font-weight: bold;
    font-style: normal;
    padding: 4px 0;
}

.music-section select option {
    color: var(--text);
    font-weight: normal;
    padding: 2px 8px;
}

.music-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.music-controls button {
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.music-controls button:hover {
    border-color: var(--accent);
    background: #2a1e10;
}

.music-controls input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

/* Soundboard */
.sounds-section {
    grid-column: span 2;
}

@media (max-width: 700px) {
    .sounds-section {
        grid-column: span 1;
    }
}

.soundboard {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.sound-btn {
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.1);
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.1s;
}

.sound-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

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

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-light);
    padding: 24px;
    border-radius: var(--radius);
    width: 90%;
    max-width: 400px;
    border: 1px solid rgba(232, 121, 29, 0.15);
}

.modal-content h2 {
    margin-bottom: 16px;
    color: var(--accent);
}

.modal-content h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 16px 0 8px 0;
    border-bottom: 1px solid rgba(232, 121, 29, 0.1);
    padding-bottom: 4px;
}

.settings-group {
    margin-bottom: 16px;
}

.device-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.device-row label:first-child {
    flex: 1;
}

.channel-row {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.channel-row label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
}

.channel-input {
    width: 50px !important;
    text-align: center;
}

.modal-content label {
    display: block;
    margin-bottom: 16px;
}

.modal-content label.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-content select,
.modal-content input[type="text"],
.modal-content textarea {
    width: 100%;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
    border-radius: var(--radius-sm);
    margin-top: 4px;
}

.modal-content select:focus,
.modal-content input[type="text"]:focus,
.modal-content textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.modal-buttons button:first-child {
    background: var(--accent);
    color: white;
}

.modal-buttons button:first-child:hover {
    background: var(--accent-hover);
}

.modal-buttons button:last-child {
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(232, 121, 29, 0.15);
}

.refresh-btn {
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid rgba(232, 121, 29, 0.15);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    margin-top: 8px;
    transition: all 0.2s;
}

.refresh-btn:hover {
    background: var(--bg-light);
    color: var(--text);
    border-color: var(--accent);
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* Server Log */
.log-section {
    grid-column: span 2;
}

@media (max-width: 700px) {
    .log-section {
        grid-column: span 1;
    }
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.log-header h2 {
    margin-bottom: 0;
}

.server-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.server-btn {
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.2s;
}

.server-btn.restart {
    background: var(--accent);
    color: white;
}

.server-btn.restart:hover {
    background: var(--accent-hover);
}

.server-btn.stop {
    background: var(--accent-red);
    color: white;
}

.server-btn.stop:hover {
    background: #e03030;
}

.auto-scroll-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

.auto-scroll-label input[type="checkbox"] {
    accent-color: var(--accent);
}

.server-log {
    height: 200px;
    overflow-y: auto;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    color: #b8a88a;
    border: 1px solid rgba(232, 121, 29, 0.06);
}

.server-log .log-line {
    white-space: pre-wrap;
    word-break: break-all;
}

.server-log .log-line.error {
    color: #e8604a;
}

.server-log .log-line.warning {
    color: #e8b84a;
}

.server-log .log-line.tts {
    color: var(--accent);
}

.server-log .log-line.chat {
    color: var(--accent-hover);
}

/* Call Queue */
.queue-section { margin: 1rem 0; }
.call-queue { border: 1px solid rgba(232, 121, 29, 0.15); border-radius: var(--radius-sm); padding: 0.5rem; max-height: 150px; overflow-y: auto; }
.queue-empty { color: var(--text-muted); text-align: center; padding: 0.5rem; }
.queue-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0.5rem; border-bottom: 1px solid rgba(232, 121, 29, 0.08); flex-wrap: wrap; }
.queue-item:last-child { border-bottom: none; }
.queue-phone { font-family: monospace; color: var(--accent); }
.queue-wait { color: var(--text-muted); font-size: 0.85rem; flex: 1; }
.queue-take-btn { background: var(--accent-green); color: white; border: none; padding: 0.25rem 0.75rem; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.2s; }
.queue-take-btn:hover { background: #6a9a4c; }
.queue-drop-btn { background: var(--accent-red); color: white; border: none; padding: 0.25rem 0.5rem; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.2s; }
.queue-drop-btn:hover { background: #e03030; }

/* Active Call Indicator */
.active-call { border: 1px solid rgba(232, 121, 29, 0.15); border-radius: var(--radius-sm); padding: 0.75rem; margin: 0.5rem 0; background: var(--bg); }
.caller-info { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.caller-info:last-of-type { margin-bottom: 0; }
.caller-type { font-size: 0.7rem; font-weight: bold; padding: 0.15rem 0.4rem; border-radius: var(--radius-sm); text-transform: uppercase; }
.caller-type.real { background: var(--accent-red); color: white; }
.caller-type.ai { background: var(--accent); color: white; }
.channel-badge { font-size: 0.75rem; color: var(--text-muted); background: var(--bg-light); padding: 0.1rem 0.4rem; border-radius: var(--radius-sm); }
.call-duration { font-family: monospace; color: var(--accent); }
.ai-controls { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.mode-toggle { display: flex; border: 1px solid rgba(232, 121, 29, 0.2); border-radius: var(--radius-sm); overflow: hidden; }
.mode-btn { background: var(--bg-light); color: var(--text-muted); border: none; padding: 0.2rem 0.5rem; font-size: 0.75rem; cursor: pointer; transition: all 0.2s; }
.mode-btn.active { background: var(--accent); color: white; }
.respond-btn { background: var(--accent-green); color: white; border: none; padding: 0.25rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.8rem; cursor: pointer; transition: background 0.2s; }
.respond-btn:hover { background: #6a9a4c; }
.hangup-btn.small { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
.auto-followup-label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Returning Caller */
.caller-btn.returning {
    border-color: var(--accent);
    color: var(--accent);
}

.caller-btn.returning:hover {
    border-color: var(--accent-hover);
    color: var(--accent-hover);
}

.caller-btn.returning.active {
    color: #fff;
}

/* Screening Badges */
.screening-badge { font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: var(--radius-sm); font-weight: bold; }
.screening-badge.screening { background: var(--accent); color: white; animation: pulse 1.5s infinite; }
.screening-badge.screened { background: var(--accent-green); color: white; }
.screening-summary { font-size: 0.8rem; color: var(--text-muted); font-style: italic; flex-basis: 100%; margin-top: 0.2rem; }

/* Three-Party Chat */
.message.real-caller { border-left: 3px solid var(--accent-red); padding-left: 0.5rem; }
.message.ai-caller { border-left: 3px solid var(--accent); padding-left: 0.5rem; }
.message.host { border-left: 3px solid var(--accent-green); padding-left: 0.5rem; }

/* Voicemail */
.voicemail-section { margin: 1rem 0; }
.voicemail-list { border: 1px solid rgba(232, 121, 29, 0.15); border-radius: var(--radius-sm); padding: 0.5rem; max-height: 200px; overflow-y: auto; }
.voicemail-badge { background: var(--accent-red); color: white; font-size: 0.7rem; font-weight: bold; padding: 0.1rem 0.45rem; border-radius: 10px; margin-left: 0.4rem; vertical-align: middle; }
.voicemail-badge.hidden { display: none; }
.vm-item { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0.5rem; border-bottom: 1px solid rgba(232, 121, 29, 0.08); }
.vm-item:last-child { border-bottom: none; }
.vm-item.vm-unlistened { background: rgba(232, 121, 29, 0.06); }
.vm-info { display: flex; gap: 0.6rem; align-items: center; flex: 1; min-width: 0; }
.vm-phone { font-family: monospace; color: var(--accent); font-size: 0.85rem; }
.vm-time { color: var(--text-muted); font-size: 0.8rem; }
.vm-dur { color: var(--text-muted); font-size: 0.8rem; }
.vm-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.vm-btn { border: none; padding: 0.2rem 0.5rem; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.75rem; transition: background 0.2s; }
.vm-btn.listen { background: var(--accent); color: white; }
.vm-btn.listen:hover { background: var(--accent-hover); }
.vm-btn.on-air { background: var(--accent-green); color: white; }
.vm-btn.on-air:hover { background: #6a9a4c; }
.vm-btn.save { background: #3a7bd5; color: white; }
.vm-btn.save:hover { background: #2a5db0; }
.vm-btn.delete { background: var(--accent-red); color: white; }
.vm-btn.delete:hover { background: #e03030; }

/* Listener Emails */
.email-item { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem; border-bottom: 1px solid rgba(232, 121, 29, 0.08); }
.email-item:last-child { border-bottom: none; }
.email-item.vm-unlistened { background: rgba(232, 121, 29, 0.06); }
.email-header { display: flex; justify-content: space-between; align-items: center; }
.email-sender { color: var(--accent); font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-subject { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-preview { font-size: 0.8rem; color: var(--text-muted); line-height: 1.3; }
.email-item .vm-actions { margin-top: 0.25rem; }
.email-body-expanded { margin-top: 0.4rem; padding: 0.5rem; background: rgba(232, 121, 29, 0.08); border-radius: var(--radius-sm); font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; max-height: 200px; overflow-y: auto; }
