/* ===== Flash Messages ===== */
.flash-container {
    position: fixed;
    top: 64px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 420px;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 0.875em;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    animation: flash-in 0.2s ease;
}

@keyframes flash-in {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

.flash-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
}

.flash-success {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
}

.flash-icon {
    flex-shrink: 0;
    font-weight: 700;
    font-size: 0.8em;
    margin-top: 1px;
}

.flash-message {
    flex: 1;
    word-break: break-word;
}

.flash-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8em;
    opacity: 0.5;
    padding: 0;
    color: inherit;
    line-height: 1;
    margin-top: 1px;
}

.flash-close:hover {
    opacity: 1;
}

/* ===== Navbar ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2em;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1em;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.navbar-logo {
    font-size: 1.3em;
    line-height: 1;
}

.navbar-links {
    display: flex;
    gap: 4px;
}

.navbar-link {
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.88em;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.navbar-link:hover {
    background: var(--bg);
    color: var(--text);
}

.navbar-link.active {
    background: #eff6ff;
    color: var(--primary);
}

/* ===== Page Wrapper ===== */
.page-wrapper {
    padding: 2em 1.5em;
    min-height: calc(100vh - 56px);
}

/* ===== Base ===== */
:root {
    --primary:     #2563eb;
    --primary-hover: #1d4ed8;
    --success:     #16a34a;
    --success-hover: #15803d;
    --danger:      #dc2626;
    --danger-hover: #b91c1c;
    --neutral:     #6b7280;
    --neutral-hover: #4b5563;

    --bg:          #f8f9fc;
    --surface:     #ffffff;
    --border:      #e5e7eb;
    --text:        #111827;
    --text-muted:  #6b7280;

    --radius:      8px;
    --radius-lg:   12px;
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
    --shadow:      0 4px 16px rgba(0,0,0,0.08);
    --transition:  0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--surface);
    padding: 2.5em 3em;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.container.narrow  { max-width: 960px; }
.container.media-view { max-width: 800px; text-align: center; }

/* ===== Headings ===== */
h1 {
    font-size: 1.75em;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.25em;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--text);
    margin: 1.5em 0 0.75em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid var(--border);
}

h3 {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 0.5em;
}

/* ===== Section Title ===== */
.section-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text);
    margin: 2em 0 0.75em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid var(--border);
}

.section-title .total {
    font-size: 0.8em;
    color: var(--text-muted);
    font-weight: 400;
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* ===== Table ===== */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75em 0 2em;
    font-size: 0.93em;
}

th {
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: #fafbff; }

td.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

/* ===== Buttons ===== */
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
    letter-spacing: 0.01em;

    background: var(--success);
    color: #fff !important;
}

button:hover, .button:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

button:active, .button:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

button:disabled, .button:disabled {
    background: #d1d5db !important;
    color: #9ca3af !important;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

button.secondary, .button.secondary {
    background: var(--primary);
}
button.secondary:hover, .button.secondary:hover {
    background: var(--primary-hover);
}

button.view, .button.view {
    background: var(--neutral);
}
button.view:hover, .button.view:hover {
    background: var(--neutral-hover);
}

button.danger, .button.danger {
    background: var(--danger);
}
button.danger:hover, .button.danger:hover {
    background: var(--danger-hover);
}

/* ===== Header Actions ===== */
.header-actions {
    display: flex;
    gap: 10px;
    margin: 1.25em 0 2em;
    align-items: center;
    flex-wrap: wrap;
}

.header-actions form { margin: 0; }

/* ===== Form Elements ===== */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4em;
    color: var(--text-muted);
    font-size: 0.9em;
}

.form-group {
    margin-bottom: 1.5em;
}

textarea {
    width: 100%;
    padding: 0.75em 1em;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.93em;
    line-height: 1.6;
    resize: vertical;
    min-height: 100px;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    box-sizing: border-box;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea[readonly] {
    background: var(--bg);
    color: var(--text-muted);
    cursor: default;
}

textarea.editor { height: 580px; }

input[type="text"] {
    width: 100%;
    padding: 0.6em 1em;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.93em;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    box-sizing: border-box;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===== Captions ===== */
.caption-container {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.caption-field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.caption-label {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

/* ===== Prompt Group ===== */
.prompt-group { margin-bottom: 2.5em; }

/* ===== Media ===== */
video, img.preview {
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5em;
    box-shadow: var(--shadow-sm);
}

/* ===== Form Actions ===== */
.form-actions {
    margin-top: 2em;
    padding-top: 1.5em;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ===== Back Link ===== */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 1.5em;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
}

.back-link:hover { text-decoration: underline; }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin: 0 0 2em;
}

.pagination a, .pagination span {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 0.88em;
    transition: background var(--transition);
}

.pagination a:hover { background: var(--bg); }
.pagination .disabled { color: #d1d5db; cursor: not-allowed; }
.pagination .current {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== Loading Overlay ===== */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000;
    color: #fff;
    gap: 16px;
}

#loading-overlay p {
    margin: 0;
    font-size: 0.95em;
    font-weight: 500;
    color: rgba(255,255,255,0.9);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

.progress-bar-track {
    width: 260px;
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 99px;
    overflow: hidden;
    margin-top: 4px;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: #fff;
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 2em;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    border: 1px solid var(--border);
}

.modal-box h3 {
    font-size: 1.1em;
    font-weight: 700;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    margin: 0 0 0.5em;
}

.modal-box p {
    color: var(--text-muted);
    font-size: 0.9em;
    margin: 0 0 1em;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 1.5em;
}

/* ===== HR ===== */
hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2em 0;
}

/* ===== Status Badge ===== */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-approved  { background: #dcfce7; color: #15803d; }
.badge-generating { background: #fef9c3; color: #a16207; }
.badge-assembled  { background: #dbeafe; color: #1d4ed8; }
.badge-uploading  { background: #f3e8ff; color: #7c3aed; }
.badge-uploaded   { background: #f0fdf4; color: #166534; }

/* ===== Responsive (Mobile) ===== */
@media (max-width: 640px) {
    .page-wrapper {
        padding: 1em 0.75em;
    }

    .container {
        padding: 1.25em 1em;
        border-radius: var(--radius);
    }

    .navbar {
        padding: 0 1em;
    }

    h1 {
        font-size: 1.3em;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    td.actions {
        min-width: 140px;
    }

    .caption-container {
        flex-direction: column;
    }

    .flash-container {
        right: 8px;
        left: 8px;
        max-width: 100%;
    }

    .modal-box {
        padding: 1.25em;
    }

    .header-actions {
        flex-wrap: wrap;
    }
}
