/* novelcast/static/css/components/unified-panel.css */
/* Replaces: add_story_panel.css + metadata_panel.css */

/* ── Backdrop ─────────────────────────────────────────────────────────── */

.unified-panel-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-color);
    z-index: var(--z-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.unified-panel-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.chapter-item.chapter-locked {
    opacity: 0.5;
}
.chapter-lock-icon {
    margin-left: 0.5rem;
    color: var(--text-muted, #999);
}

/* ── Modal (centered) ─────────────────────────────────────────────────── */

.unified-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -48%) scale(0.97);
    z-index: var(--z-modal);

    width: min(680px, calc(100vw - 2rem));
    height: 65vh;

    background: var(--surface-raised);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);

    display: flex;
    flex-direction: column;
    overflow: hidden;

    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.unified-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

/* ── Header ───────────────────────────────────────────────────────────── */

.unified-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    flex-shrink: 0;
}

.unified-panel-title {
    margin: 0;
    font-size: 0.97rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #0f172a;
}

.unified-panel-title i {
    color: #94a3b8;
    font-size: 0.9rem;
}

.unified-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
    transition:
        background 0.12s ease,
        color 0.12s ease;
}

.unified-panel-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #0f172a;
}

/* ── Tabs ─────────────────────────────────────────────────────────────── */

.unified-panel-tabs {
    display: flex;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    gap: 0;
}

.unified-panel-tab {
    padding: 0.6rem 0.9rem;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition:
        color 0.12s ease,
        border-color 0.12s ease;
    font-family: inherit;
    white-space: nowrap;
}

.unified-panel-tab:hover {
    color: #0f172a;
}

.unified-panel-tab.active {
    color: #0f172a;
    border-bottom-color: #6366f1;
}

/* ── Body ─────────────────────────────────────────────────────────────── */

.unified-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;

    height: 65vh; /* 65% of screen height */
    /* min-height: 400px;     Don't shrink below 400px */
}

/* ── Content panels ───────────────────────────────────────────────────── */

.unified-panel-content {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.unified-panel-content[style*='display:none'] {
    display: none !important;
}

/* ── Section + heading ────────────────────────────────────────────────── */

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.panel-section > h3 {
    margin: 0 0 0.3rem 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
}

.panel-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
    padding: 2rem 0;
}

.panel-spinner {
    font-size: 2.5rem;
    color: #6366f1;
    animation: spin 1s linear infinite;
}

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

.panel-center h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #0f172a;
}

.panel-center p {
    margin: 0;
    font-size: 0.88rem;
    color: #64748b;
}

/* ── Form layouts ─────────────────────────────────────────────────────── */

.form-row-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
}

.form-input {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    color: #0f172a;
    font-size: 0.9rem;
    font-family: inherit;
    transition:
        border-color 0.12s ease,
        box-shadow 0.12s ease;
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-input::placeholder {
    color: #94a3b8;
}

textarea.form-input {
    resize: vertical;
    line-height: 1.6;
    min-height: 110px;
}

/* ── Info box ─────────────────────────────────────────────────────────── */

.form-info-box {
    display: flex;
    align-items: center;
    padding: 0.75rem 0.85rem;
    border-radius: 7px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.form-info-text {
    margin: 0;
    font-size: 0.88rem;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-info-text i {
    color: #6366f1;
}

.form-hint {
    margin: 0;
    font-size: 0.82rem;
    color: #64748b;
}

/* ── Tag system ───────────────────────────────────────────────────────── */

.tags-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.65rem;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    min-height: 38px;
}

.tag-entry {
    flex: 1 1 150px;
    min-width: 140px;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    color: #0f172a;
    padding: 0.2rem 0.2rem;
}

.tag-entry:focus {
    outline: none;
}

.tag-entry::placeholder {
    color: #94a3b8;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    border-radius: 5px;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
    font-size: 0.82rem;
    font-weight: 600;
}

.tag-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font-size: 0.65rem;
    opacity: 0.6;
    transition: opacity 0.12s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
}

.tag-remove:hover {
    opacity: 1;
}

.tag-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1px dashed rgba(0, 0, 0, 0.2);
    background: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.65rem;
    font-family: inherit;
    transition:
        border-color 0.12s,
        color 0.12s;
}

.tag-add:hover {
    border-color: #6366f1;
    color: #6366f1;
}

/* ── Checkbox / Switch ────────────────────────────────────────────────── */

.form-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #334155;
}

.form-checkbox-label input[type='checkbox'] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: #6366f1;
    cursor: pointer;
}

.form-switch {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.form-switch input[type='checkbox'] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: #6366f1;
}

/* ── Description toolbar (for rich text) ───────────────────────────────── */

.description-toolbar {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    padding: 0.25rem 0.45rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-bottom: none;
    border-radius: 7px 7px 0 0;
    background: #f8fafc;
}

.description-toolbar + textarea {
    border-radius: 0 0 7px 7px;
    border-top: none;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 26px;
    padding: 0 0.3rem;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
    transition:
        background 0.1s,
        color 0.1s;
}

.toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.07);
    color: #0f172a;
}

.toolbar-sep {
    width: 1px;
    height: 16px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 0.15rem;
}

/* ── Progress bar ─────────────────────────────────────────────────────── */

.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #4f46e5);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ── Chapter list (for add story) ─────────────────────────────────────── */

.chapter-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: background 0.12s;
}

.chapter-item:hover {
    background: rgba(99, 102, 241, 0.04);
}

.chapter-item:last-child {
    border-bottom: none;
}

.chapter-item input[type='checkbox'] {
    width: 1rem;
    height: 1rem;
    accent-color: #6366f1;
    cursor: pointer;
}

.chapter-item label {
    flex: 1;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin: 0;
}

.chapter-number {
    font-weight: 600;
    color: #0f172a;
    font-size: 0.88rem;
}

.chapter-title {
    color: #64748b;
    font-size: 0.82rem;
}

/* ── Cover preview (for metadata panel) ────────────────────────────────── */

.cover-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 2rem 0;
}

.cover-preview {
    width: 150px;
    height: 150px;
    border-radius: 10px;
    border: 2px dashed rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0f172a;
    font-size: 2rem;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    overflow: hidden;
    position: relative;
    padding: 0.75rem;
    box-sizing: border-box;
}

.cover-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.cover-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    color: #334155;
    text-align: center;
}

.cover-placeholder p {
    font-size: 0.82rem;
    margin: 0;
    color: #475569;
    text-align: center;
}

.cover-preview.has-image .cover-placeholder {
    display: none;
}

.cover-actions {
    display: flex;
    gap: 0.6rem;
    width: 100%;
}

.cover-actions .form-input {
    flex: 1;
}

.form-help {
    margin: 0;
    font-size: 0.82rem;
    color: #64748b;
    text-align: center;
}

.author-links-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.author-link-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.45rem;
    align-items: center;
}

.author-link-row input {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 7px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    color: #0f172a;
    font-size: 0.85rem;
    box-sizing: border-box;
}

.author-link-remove {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    border: none;
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
    cursor: pointer;
}

.author-links-empty {
    font-size: 0.84rem;
    color: #64748b;
    margin: 0;
}

/* ── Footer ───────────────────────────────────────────────────────────── */

.unified-panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.9rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.unified-panel-status {
    font-size: 0.8rem;
    color: #94a3b8;
    flex: 1;
}

.unified-panel-status.success {
    color: #16a34a;
}

.unified-panel-status.error {
    color: #dc2626;
}

.unified-panel-actions {
    display: flex;
    gap: 0.45rem;
    align-items: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.45rem 0.9rem;
    border-radius: 7px;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition:
        background 0.12s,
        color 0.12s;
}

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

.btn-primary {
    background: #1e293b;
    color: #fff;
    border: none;
}

.btn-primary:hover:not(:disabled) {
    background: #0f172a;
}

.btn-primary:disabled {
    background: #cbd5e1;
}

.btn-secondary {
    background: transparent;
    color: #334155;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.04);
}

.btn-outline {
    background: transparent;
    color: #334155;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.btn-outline:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.04);
}

/* ── Mobile ───────────────────────────────────────────────────────────── */

@media (max-width: 540px) {
    .unified-panel {
        width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
    }

    .unified-panel.open {
        transform: none;
    }

    .unified-panel-body,
    .unified-panel-header,
    .unified-panel-footer {
        padding-inline: 1rem;
    }

    .form-row-two {
        grid-template-columns: 1fr;
    }

    .unified-panel-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .unified-panel-actions {
        width: 100%;
        flex-direction: column;
    }

    .unified-panel-actions .btn {
        width: 100%;
        justify-content: center;
    }
}
