:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --error: #ef4444;
    --border: #334155;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

body.modal-open {
    overflow: hidden;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

header {
    text-align: center;
    margin-bottom: 32px;
}

header h1 {
    margin: 0;
    font-size: 2rem;
}

header p {
    color: var(--muted);
    margin-top: 8px;
    margin-bottom: 16px;
}

.btn-header-info {
    padding: 8px 14px;
    font-size: 0.9rem;
}

main {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

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

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.panel h2 {
    margin-top: 0;
    font-size: 1.25rem;
}

.field {
    margin-bottom: 18px;
}

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

.field-header label {
    margin-bottom: 0;
}

.field-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-hover);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

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

.btn-action:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.dictate-status {
    display: block;
    margin-top: 6px;
    color: var(--success);
    font-size: 0.85rem;
    font-weight: 600;
}

.dictate-status.listening {
    animation: pulse 1.2s infinite;
}

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

.field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #0b1220;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

.field small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.8rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 600px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .field-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .field-actions {
        justify-content: flex-start;
        width: 100%;
    }
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: var(--surface-hover);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

button:hover,
.btn:hover {
    filter: brightness(1.1);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    font-size: 1rem;
}

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

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-success {
    background: var(--success);
}

.btn-danger {
    background: var(--danger);
}

.btn-link {
    background: transparent;
    color: var(--primary);
    padding: 8px 0;
    justify-content: flex-start;
}

.btn-link:hover {
    color: var(--primary-hover);
    filter: none;
    text-decoration: underline;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.result {
    margin-top: 20px;
    padding: 16px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success);
    border-radius: var(--radius);
}

.result h3 {
    margin-top: 0;
    color: var(--success);
}

.result audio {
    width: 100%;
    margin: 12px 0;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.error {
    margin-top: 16px;
    padding: 14px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    color: #fca5a5;
    white-space: pre-wrap;
}

.hidden {
    display: none !important;
}

/* Panel lateral */
.last-audio {
    margin-top: 16px;
    padding: 16px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
}

.last-audio h3 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--primary);
}

.last-audio audio {
    width: 100%;
    margin: 10px 0;
}

.older-audios {
    margin-top: 20px;
}

.older-audios h3 {
    font-size: 1rem;
    margin-bottom: 10px;
}

.audio-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 400px;
    overflow-y: auto;
}

.audio-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.audio-list li:last-child {
    border-bottom: none;
}

.audio-list.compact li {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.audio-list.compact .filename {
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-all;
}

.audio-list.compact .meta {
    font-size: 0.8rem;
    color: var(--muted);
}

.audio-list.compact .audio-wrapper {
    display: none;
}

.audio-list.compact .audio-wrapper.expanded {
    display: block;
}

.audio-list.compact .audio-wrapper audio {
    width: 100%;
}

.audio-list.compact .actions {
    gap: 6px;
}

.audio-list.compact .actions button,
.audio-list.compact .actions a {
    padding: 5px 10px;
    font-size: 0.8rem;
}

.empty {
    color: var(--muted);
    text-align: center;
    margin-top: 24px;
}

footer {
    text-align: center;
    margin-top: 32px;
    color: var(--muted);
    font-size: 0.9rem;
}

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

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

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

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-wide {
    max-width: 800px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px;
}

.modal-body .field:first-child {
    margin-top: 0;
}

.modal-body .field:last-child {
    margin-bottom: 0;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.modal-footer .btn-primary {
    width: auto;
    padding: 10px 20px;
}

.modal .error {
    margin-top: 0;
    margin-bottom: 0;
}

/* Modal de generación */
.generation-loading {
    text-align: center;
    padding: 20px 0;
}

.generation-spinner {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    border: 5px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.generation-status {
    font-size: 1.05rem;
    margin-bottom: 12px;
}

.generation-timer {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-bottom: 16px;
    color: var(--primary);
}

.generation-info {
    color: var(--muted);
    font-size: 0.9rem;
}

.generation-info code {
    color: var(--text);
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.generation-result {
    text-align: center;
}

.generation-result audio {
    width: 100%;
    margin-bottom: 16px;
}

.generation-result .actions {
    justify-content: center;
    margin-bottom: 16px;
}

.generation-details {
    margin-top: 16px;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.generation-details h4 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--primary);
}

.details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.details-grid .detail-item {
    background: var(--surface);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.details-grid .detail-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.details-grid .detail-value {
    font-size: 0.95rem;
    font-weight: 600;
    word-break: break-word;
}

.generation-details pre {
    background: #0b1220;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
    max-height: 300px;
    color: #a5b4fc;
}

/* Historial */
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 60vh;
    overflow-y: auto;
}

.history-list li {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 10px;
}

.history-list .history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.history-list .history-date {
    font-size: 0.8rem;
    color: var(--muted);
}

.history-list .history-file {
    font-weight: 600;
    word-break: break-all;
}

.history-list .history-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 10px;
}

.history-list .history-error {
    color: var(--error);
    font-size: 0.85rem;
}

.history-list .history-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-list .history-actions a,
.history-list .history-actions button {
    padding: 6px 10px;
    font-size: 0.8rem;
}
