:root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f232f;
    --border: #2a2f3d;
    --text: #e7e9ee;
    --muted: #8f96a8;
    --accent: #e0453f;
    --accent-hover: #c93a35;
    --ok: #3fb27f;
    --danger: #e05a5a;
}

* { box-sizing: border-box; }

/* Các khối dùng display:flex/grid sẽ ghi đè thuộc tính hidden nếu không có dòng này */
[hidden] { display: none !important; }

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

.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(23, 26, 35, 0.9);
    padding: 18px 24px;
}

.brand { display: flex; align-items: center; gap: 14px; max-width: 1180px; margin: 0 auto; }

.logo {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: linear-gradient(140deg, var(--accent), #8f2d2a);
    font-size: 22px; font-weight: 700;
}

.topbar h1 { margin: 0; font-size: 19px; }
.topbar p { margin: 0; font-size: 13px; color: var(--muted); }

.layout {
    max-width: 1180px;
    margin: 24px auto;
    padding: 0 24px 48px;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
}

.tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 18px;
}

.tab {
    flex: 1;
    padding: 9px 12px;
    border: none;
    border-radius: 9px;
    background: none;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.mode-switch { display: grid; gap: 10px; margin-bottom: 18px; }

.mode-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    cursor: pointer;
}
.mode-option:has(input:checked) { border-color: var(--accent); background: rgba(224, 69, 63, 0.09); }
.mode-option input { accent-color: var(--accent); width: 16px; height: 16px; margin-top: 3px; }
.mode-option span { display: flex; flex-direction: column; }
.mode-option strong { font-size: 14.5px; }
.mode-option small { color: var(--muted); font-size: 12px; }

.dlg-options { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }

.inline-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

select {
    padding: 8px 10px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
}

.btn-row { display: flex; gap: 10px; }
.btn-row .primary-btn { flex: 1; }

.secondary-btn {
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.secondary-btn:hover:not(:disabled) { border-color: var(--accent); }
.secondary-btn:disabled { opacity: 0.6; cursor: progress; }

.script-box {
    margin-top: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}
.script-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.script-head strong { font-size: 14.5px; }
.script-head span { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.script-head-actions { display: flex; gap: 12px; }
.script-hint { margin: 6px 0 12px; font-size: 12px; color: var(--muted); }
.script-lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; max-height: 340px; overflow-y: auto; }

.script-row { display: flex; align-items: flex-start; gap: 8px; }
.script-row .script-text {
    flex: 1;
    min-height: 38px;
    padding: 9px 11px;
    font-size: 15px;
    border-radius: 9px;
    resize: vertical;
}

.speaker-tag {
    flex-shrink: 0;
    min-width: 38px;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
}
.speaker-tag.female { background: rgba(224, 69, 63, 0.18); color: #ff9d99; border-color: rgba(224, 69, 63, 0.45); }
.speaker-tag.male { background: rgba(72, 132, 214, 0.18); color: #9dc0f5; border-color: rgba(72, 132, 214, 0.45); }

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

textarea {
    width: 100%;
    min-height: 210px;
    resize: vertical;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
}

textarea:focus, input:focus { outline: 2px solid rgba(224, 69, 63, 0.5); outline-offset: 1px; }

.composer-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12.5px;
    color: var(--muted);
    margin: 8px 0 18px;
}

.link-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 12.5px;
    padding: 0;
    text-decoration: underline;
}
.link-btn:hover { color: var(--text); }
.link-btn.danger:hover { color: var(--danger); }

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

.voice-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    cursor: pointer;
}
.voice-option:has(input:checked) { border-color: var(--accent); background: rgba(224, 69, 63, 0.09); }
.voice-option input { accent-color: var(--accent); width: 16px; height: 16px; }
.voice-body { display: flex; flex-direction: column; }
.voice-body strong { font-size: 14.5px; }
.voice-body small { color: var(--muted); font-size: 11.5px; }

.primary-btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-size: 15.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.65; cursor: progress; }

.spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    margin-top: 14px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 13.5px;
    background: rgba(224, 90, 90, 0.12);
    border: 1px solid rgba(224, 90, 90, 0.4);
    color: #ffb9b9;
}
.alert.ok {
    background: rgba(63, 178, 127, 0.12);
    border-color: rgba(63, 178, 127, 0.4);
    color: #a8e6c7;
}

.result {
    margin-top: 18px;
    padding: 16px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.result-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 14px; }
.result-head span { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.result audio { width: 100%; }

.ghost-btn {
    display: inline-block;
    margin-top: 12px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
}
.ghost-btn:hover { border-color: var(--accent); }

.result-lines { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }

.line-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 9px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.03);
    font-size: 14.5px;
}
.line-row .line-text { flex: 1; word-break: break-word; }
.line-row .speaker-tag { cursor: default; padding: 3px 7px; font-size: 11px; min-width: 32px; }

.play-line {
    flex-shrink: 0;
    width: 26px; height: 26px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 10px;
    line-height: 1;
}
.play-line:hover { color: var(--accent); border-color: var(--accent); }

.item-lines { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }

.history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.history-head h2 { margin: 0; font-size: 16px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 14px; }

#search {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}

.history-list { display: flex; flex-direction: column; gap: 10px; max-height: 640px; overflow-y: auto; }

.history-item {
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}
.history-item .row1 { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.history-item .title { font-weight: 600; font-size: 14.5px; word-break: break-word; }
.history-item .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.history-item audio { width: 100%; margin-top: 10px; height: 34px; }
.history-item .actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 8px;
    width: 30px; height: 30px;
    cursor: pointer;
    display: grid; place-items: center;
    font-size: 14px;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.icon-btn.dl { text-decoration: none; }
.icon-btn.dl:hover { color: var(--ok); border-color: var(--ok); }
.icon-btn.reuse:hover { color: #e9c46a; border-color: #e9c46a; }

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 20px;
    font-size: 11px;
    background: rgba(224, 69, 63, 0.15);
    color: #ffb0ad;
    margin-left: 6px;
}
.badge.missing { background: rgba(143, 150, 168, 0.15); color: var(--muted); }
.badge.dlg { background: rgba(72, 132, 214, 0.18); color: #9dc0f5; }

.empty { color: var(--muted); font-size: 13.5px; text-align: center; padding: 22px 0; }

@media (max-width: 880px) {
    .layout { grid-template-columns: 1fr; }
    .voices { grid-template-columns: 1fr; }
}
