* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: #0b1220;
    color: #e7ecf3;
}

/* Focus mode: maximize workspace while keeping wheel scroll. */
body.app-focus-ui .topbar {
    display: none !important;
}
body.app-focus-ui .container {
    width: min(99vw, 2200px);
    margin: 0.2rem auto 0.6rem;
}
body.app-focus-ui,
html.app-focus-ui {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
body.app-focus-ui::-webkit-scrollbar,
html.app-focus-ui::-webkit-scrollbar {
    width: 0;
    height: 0;
}
/* Keep sidebar sticky position consistent across pages in focus mode. */
body.app-focus-ui .dashboard-sidebar {
    top: 1rem !important;
}
:fullscreen .topbar,
:-webkit-full-screen .topbar {
    display: none !important;
}
:fullscreen .container,
:-webkit-full-screen .container {
    width: min(99vw, 2200px);
    margin: 0.2rem auto 0.6rem;
}

a {
    color: #93c5fd;
    text-decoration: none;
}

.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #1e293b, #0b1220);
}

.auth-card,
.panel {
    background: #111827;
    border: 1px solid #263247;
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.panel,
.panel h2,
.panel h3,
.panel p,
.panel span,
.panel label,
.panel strong {
    color: #e7ecf3;
}

.auth-card {
    width: min(460px, 92vw);
}

.auth-card h1 {
    text-align: center;
}

.auth-card .login-title {
    text-align: center !important;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.logo {
    width: 220px;
    max-width: 100%;
    display: block;
    margin: 0 auto 1rem;
}

.login-logo {
    width: 330px;
}

.subtitle {
    color: #9ca3af;
    margin-top: -0.3rem;
    margin-bottom: 1rem;
}

.form-stack {
    display: grid;
    gap: 0.8rem;
}

label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.95rem;
}

input,
select,
textarea,
button {
    border-radius: 10px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #f8fafc;
    padding: 0.75rem;
    font-size: 0.95rem;
}

select.form-select,
.inline-form select.form-select,
.filter-grid select.form-select {
    min-width: 220px;
}

.form-select-lg {
    font-size: 1rem;
}

button {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    cursor: pointer;
    font-weight: 600;
}

button:hover {
    filter: brightness(1.08);
}

.alert {
    background: #1f2937;
    border: 1px solid #3b82f6;
    padding: 0.8rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid #263247;
    background: #111827;
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar h1 {
    margin: 0;
    font-size: 1.1rem;
}

.topbar > div:first-child {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.topbar-actions {
    display: flex;
    gap: 0.7rem;
    align-items: center;
}

.balance-pill {
    border: 1px solid #334155;
    border-radius: 999px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.balance-pill.ok {
    border-color: #10b981;
    background: #064e3b;
}

.balance-pill.warn {
    border-color: #f59e0b;
    background: #78350f;
}

.logo-small {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.btn-outline {
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 0.45rem 0.75rem;
}

#appFocusToggleBtn {
    border: 1px solid #ea580c !important;
    background: #9a3412 !important;
    color: #fff !important;
    border-radius: 8px !important;
    padding: 0.22rem 0.5rem !important;
    font-size: 0.76rem !important;
    line-height: 1.1 !important;
    min-height: 30px !important;
}

#appFocusToggleBtn:hover {
    filter: brightness(1.1);
}

.container {
    width: min(1200px, 94vw);
    margin: 1.2rem auto 4rem;
    display: grid;
    gap: 1rem;
}

.workspace-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1.35fr 1fr;
    align-items: start;
}

.workspace-group-border {
    border: 2px solid #2563eb;
    border-radius: 14px;
    padding: 0.8rem;
}

.tts-panel {
    display: grid;
    gap: 0.8rem;
    border: 2px solid #facc15;
}

.saved-images-panel {
    border: 2px solid #22c55e;
}

.tts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

.tts-counter {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.88rem;
}

.tts-actions-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
}

.tts-preview-status {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.85rem;
}

.tts-preview-divider {
    border-top: 2px solid #facc15;
    padding-top: 0.65rem;
}

.tts-collapsible-content {
    display: none;
    gap: 0.7rem;
}

.tts-list {
    display: grid;
    gap: 0.6rem;
}

.tts-profile-form {
    margin-top: 0.35rem;
}

.tts-profile-actions {
    display: flex;
    align-items: end;
}

.tts-profiles-list {
    display: grid;
    gap: 0.6rem;
}

.tts-profile-item {
    border: 1px solid #2b3a53;
    border-radius: 10px;
    padding: 0.6rem;
    background: #0a1120;
    display: grid;
    gap: 0.35rem;
}

.tts-profile-item p {
    margin: 0;
}

.tts-profile-item form {
    margin-top: 0.25rem;
}

.tts-item {
    border: 1px solid #2b3a53;
    border-radius: 10px;
    padding: 0.6rem;
    background: #0b1324;
    display: grid;
    gap: 0.45rem;
}

.tts-item p {
    margin: 0;
}

.tts-item audio {
    width: 100%;
}

.side-panel {
    min-height: 500px;
}

.panel-title-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.panel-title-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.filter-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: end;
    margin-top: 0.8rem;
}

.saved-filter-row {
    margin-top: 0.8rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chip {
    border: 1px solid #334155;
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    font-size: 0.82rem;
}

.chip.active {
    border-color: #60a5fa;
    background: #1e3a8a;
}

.inline-form {
    display: flex;
    gap: 0.45rem;
    align-items: center;
    flex-wrap: wrap;
}

.library-list {
    margin-top: 0.8rem;
    display: grid;
    gap: 0.65rem;
    max-height: 520px;
    overflow: auto;
    padding-right: 0.2rem;
}

.library-item {
    border: 1px solid #2b3a53;
    border-radius: 10px;
    padding: 0.5rem;
    background: #0b1324;
    display: grid;
    gap: 0.5rem;
    cursor: grab;
}

.library-item[data-ref-id] {
    grid-template-columns: 72px 1fr;
    align-items: start;
}

.library-item p {
    margin: 0;
    font-size: 0.82rem;
}

.library-item img {
    width: 100%;
    max-height: 130px;
    object-fit: cover;
    border-radius: 8px;
}

.library-item[data-ref-id] img {
    width: 72px;
    height: 72px;
    max-height: 72px;
    object-fit: cover;
}

.reference-thumb {
    width: 72px !important;
    height: 72px !important;
    max-width: 72px !important;
    max-height: 72px !important;
    min-width: 72px !important;
    min-height: 72px !important;
    object-fit: cover !important;
    border-radius: 8px;
}

.panel-title-row h2,
.panel-title-row span {
    color: #f8fafc !important;
}

.drop-zone {
    border: 1px dashed #475569;
    border-radius: 10px;
    padding: 0.7rem;
    display: grid;
    gap: 0.45rem;
    background: #0b1320;
}

.drop-zone.dragging {
    border-color: #60a5fa;
    background: #12213a;
}

.inline-form input,
.inline-form select {
    padding: 0.45rem 0.55rem;
    font-size: 0.82rem;
}

.inline-form button {
    padding: 0.45rem 0.55rem;
    font-size: 0.8rem;
}

.grid {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 250px));
    justify-content: center;
    gap: 1rem;
}

.card {
    border: 1px solid #2b3a53;
    border-radius: 14px;
    overflow: hidden;
    background: #0f172a;
    display: flex;
    flex-direction: column;
}

.saved-images-panel .card {
    border: 2px solid #86efac;
    box-shadow: 0 0 0 1px rgba(134, 239, 172, 0.2);
}

.card img {
    width: 100%;
    height: 230px;
    object-fit: cover;
    background: #020617;
}

.card-body {
    padding: 0.75rem;
    font-size: 0.86rem;
    display: grid;
    gap: 0.45rem;
}

.card-body p {
    margin: 0;
}

.source-ref {
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 0.45rem;
    display: grid;
    gap: 0.35rem;
}

.source-ref span {
    font-size: 0.75rem;
    color: #cbd5e1;
}

.source-ref img {
    width: 100%;
    max-height: 95px;
    object-fit: cover;
    border-radius: 8px;
}

.card-actions {
    margin-top: auto;
    padding: 0.75rem;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.card-actions a,
.card-actions button {
    padding: 0.45rem 0.65rem;
    border-radius: 8px;
    border: 1px solid #334155;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 0.83rem;
}

.card-actions .delete {
    background: #7f1d1d;
    border-color: #b91c1c;
}

.pagination {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
}

.footer-brand {
    border-top: 1px solid #263247;
    margin-top: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    align-items: center;
    padding: 1rem;
    background: #0b1220;
}

.footer-brand img {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: #020617;
    border-radius: 10px;
    padding: 0.35rem;
}

.footer-tools {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding-top: 0.15rem;
}

.delete-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
}

.delete-confirm-modal.show {
    display: block;
}

.delete-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
}

.delete-confirm-dialog {
    position: relative;
    width: min(460px, 92vw);
    margin: 12vh auto 0;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
    display: grid;
    gap: 0.65rem;
}

.delete-confirm-dialog h3,
.delete-confirm-dialog p,
.delete-confirm-dialog label {
    margin: 0;
    color: #f8fafc;
}

.delete-confirm-error {
    min-height: 1.1rem;
    color: #fca5a5 !important;
    font-size: 0.85rem;
}

.delete-confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

#scrollTopBtn {
    position: fixed;
    right: 15px;
    bottom: 15px;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s ease;
    border-radius: 999px;
    min-width: 60px;
}

#scrollTopBtn.show {
    opacity: 1;
    visibility: visible;
}

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

    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .footer-brand {
        grid-template-columns: 1fr;
    }

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