﻿:root {
    --bg-color: #050505;
    --card-bg: #0a0a0a;
    --sidebar-bg: #0a0a0a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-color: #fbb1ad;
    --accent-secondary: #ffd590;
    --accent-hover: #ff9595;
    --gradient-primary: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-secondary) 100%);
    --glass-bg: rgba(19, 18, 18, 0.85);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glow-shadow: none;
    --success-color: #00e676;
    --error-color: #ff1744;
    --border-color: #333333;
    --input-bg: #1a1a1a;
    --transition: color 150ms ease-out, background-color 150ms ease-out, border-color 150ms ease-out, opacity 150ms ease-out, transform 150ms ease-out;
    --font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    --page-gutter: clamp(12px, 4vw, 32px);
    --panel-padding: clamp(12px, 3vw, 24px);
    --radius-panel: 16px;
    --tap-size: 44px;
    --page-background:
        linear-gradient(rgba(255, 255, 255, 0.032) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.032) 1px, transparent 1px),
        radial-gradient(circle at top left, rgba(251, 177, 173, 0.055), transparent 34rem),
        radial-gradient(circle at bottom right, rgba(255, 213, 144, 0.04), transparent 30rem),
        var(--bg-color);
    --page-background-size: 48px 48px, 48px 48px, auto, auto, auto;
    color-scheme: dark;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body,
#auth-view {
    background: var(--page-background);
    background-size: var(--page-background-size);
    background-position: center top;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-family);
    color: var(--text-primary);
    line-height: 1.5;
}

.icon-symbols {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.ui-icon {
    width: 19px;
    height: 19px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

button:focus-visible,
a:focus-visible,
.segmented-control input:focus-visible + label,
.circle-checkbox-wrapper input:focus-visible + .checkmark {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Auth View */
#auth-view {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-container .logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    line-height: 1.2;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.auth-container .app-logo {
    margin: 0;
}

.auth-box {
    background: var(--glass-bg);
    padding: 24px;
    border-radius: var(--radius-panel);
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.tabs {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--glass-border);
}

.tab-btn {
    min-height: var(--tap-size);
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0 4px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.auth-form.active {
    display: flex;
}

.auth-field {
    display: grid;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.auth-field input:not([type='checkbox'], [type='radio'], [type='hidden']) {
    min-height: var(--tap-size);
    padding: 8px 12px;
}

/* Dashboard Layout */
#dashboard-view {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: fixed;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar .logo {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 28px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar .app-logo {
    margin-right: 0;
    height: 24px;
}

.app-logo {
    height: 1em;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    margin-bottom: 4px;
}

.nav-links button {
    width: 100%;
    min-height: var(--tap-size);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.nav-links li.active button {
    background: rgba(251, 177, 173, 0.07);
    border-color: var(--glass-border);
    box-shadow: inset 2px 0 var(--accent-color);
    color: var(--accent-color);
}

@media (hover: hover) and (pointer: fine) {
    .nav-links li:not(.active) button:hover {
        background: rgba(255, 255, 255, 0.05);
        color: var(--text-primary);
    }
}

.user-profile {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.user-info {
    max-width: 100%;
    font-size: 0.9rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

#logout-btn {
    min-height: var(--tap-size);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
    #logout-btn:hover {
        border-color: var(--accent-color);
        color: var(--text-primary);
    }
}

.content {
    flex: 1;
    min-width: 0;
    margin-left: 250px;
    padding: clamp(32px, 4vw, 56px) var(--page-gutter) 32px;
}

/* Sections */
.section {
    display: none;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero {
    margin-bottom: 24px;
}

.hero h1 {
    font-size: clamp(1.75rem, 3vw, 2.25rem);
    font-weight: 600;
    line-height: 1.15;
    margin-bottom: 4px;
}

.hero p {
    color: var(--text-secondary);
}

/* Forms & Inputs */
.input-group {
    position: relative;
}

.input-group i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

input:not([type='checkbox'], [type='radio'], [type='hidden']),
select,
textarea {
    width: 100%;
    padding: 1rem;
    padding-left: 2.5rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
}

textarea {
    padding-left: 1rem;
    resize: vertical;
}

input:not([type='checkbox'], [type='radio'], [type='hidden']):focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(251, 177, 173, 0.2);
}

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

/* Ensure icon + label sit on one line inside primary buttons */
.btn-text {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* Shareable link layout */
.share-section {
    margin-top: 1rem;
}

.share-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    display: block;
}

.share-help {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-primary {
    background: var(--gradient-primary);
    color: #000;
}

@media (hover: hover) and (pointer: fine) {
    .btn-primary:not(:disabled):hover {
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.24);
    }
}

.btn-primary:not(:disabled):active,
.nav-links button:active,
.story-modal .story-item:active {
    transform: scale(0.98);
}

.nav-links button,
.segmented-control label,
.story-modal .story-item,
#download-btn,
#batch-submit-btn {
    -webkit-tap-highlight-color: transparent;
}

.btn-secondary {
    background: var(--input-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #222;
}

/* Modern Glass Card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-panel);
    padding: var(--panel-padding);
    box-shadow: var(--glow-shadow);
    margin-bottom: 24px;
}

/* Segmented Control */
.segmented-control {
    position: relative;
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 16px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
}

.segmented-control label {
    flex: 1;
    min-width: 0;
    min-height: var(--tap-size);
    padding: 8px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
}

.segmented-control input[type='radio'] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.segmented-control input[type='radio']:checked + label {
    background: rgba(251, 177, 173, 0.12);
    color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Modern Input Area */
.modern-input-wrapper {
    position: relative;
    display: flex;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.5rem;
    transition: var(--transition);
}

.modern-input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(251, 177, 173, 0.2);
}

.modern-input-wrapper > input:not([type='checkbox'], [type='radio'], [type='hidden']) {
    border: none;
    background: transparent;
    padding: 1rem;
    padding-left: 1rem;
    box-shadow: none;
}

.modern-input-wrapper .btn-primary {
    width: auto;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    margin-left: 0.5rem;
}

/* Quality Select (Modern) */
.quality-wrapper {
    margin-bottom: 1.5rem;
}

.quality-wrapper select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

/* Download workspace */
.download-mode {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.download-mode button,
#activity-history,
.activity-action {
    min-height: var(--tap-size);
    padding: 0 4px;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
}

.download-mode button {
    border-bottom: 2px solid transparent;
}

.download-mode button[aria-pressed='true'] {
    border-bottom-color: var(--accent-color);
    color: var(--accent-color);
}

#batch-form .modern-textarea-wrapper {
    margin-bottom: 12px;
}

#batch-form textarea {
    min-height: 104px;
    padding: 12px;
}

#batch-form .segmented-control {
    width: fit-content;
    margin: 0 0 8px;
}

#batch-form .batch-controls-row {
    max-width: 320px;
    gap: 8px;
    margin: 0;
}

#batch-form .share-option {
    margin-top: 4px;
}

.download-activity {
    margin-top: 24px;
    padding: 0 var(--panel-padding) 4px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-panel);
    background: var(--glass-bg);
}

.activity-header,
.activity-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.activity-header {
    justify-content: space-between;
    min-height: 52px;
}

.activity-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

#activity-history,
.activity-action {
    color: var(--accent-color);
    white-space: nowrap;
}

#activity-history:hover,
.activity-action:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
}

#activity-list {
    list-style: none;
}

.activity-row {
    min-height: 56px;
    padding: 4px 0;
    border-top: 1px solid var(--glass-border);
}

.activity-row > .ui-icon {
    color: var(--text-secondary);
}

.activity-file {
    flex: 1;
    min-width: 0;
}

.activity-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.activity-status,
.history-file-count {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.instagram-row-thumb {
    position: relative;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 40px;
    height: 44px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-secondary);
}

.instagram-row-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-instagram-row {
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
}

.history-instagram-details {
    min-width: 0;
}

.instagram-row-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.instagram-row-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.25;
}

.instagram-row-meta > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.instagram-original {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    color: var(--text-secondary);
}

.instagram-original .ui-icon {
    width: 15px;
    height: 15px;
}

.instagram-original:hover,
.instagram-original:focus-visible {
    color: var(--accent-color);
}

.instagram-original:focus-visible,
.instagram-row-title:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* On phones, let the identifying text use the space not required by row controls. */
@media (max-width: 768px) {
    #history-table:has(.history-instagram-row) :is(thead th:nth-child(3), td:has(.history-instagram-row)),
    #history-section.history-select-mode #history-table:has(.history-instagram-row) :is(th:nth-child(3), td:nth-child(3)) {
        width: auto !important;
        max-width: none !important;
    }

    #history-table:has(.history-instagram-row) :is(th, td):nth-last-child(2),
    #history-section.history-select-mode #history-table:has(.history-instagram-row) :is(th, td):nth-last-child(2) {
        width: 46px !important;
        padding-inline: 2px;
    }

    #history-table:has(.history-instagram-row) :is(th, td):last-child,
    #history-section.history-select-mode #history-table:has(.history-instagram-row) :is(th, td):last-child {
        width: 90px !important;
        padding-inline: 4px;
    }

    #history-section.history-select-mode #history-table:has(.history-instagram-row) :is(th, td):last-child:not(.history-empty-cell) {
        display: none;
    }

    #history-table tr:has(.history-instagram-row) > td {
        vertical-align: middle;
    }

    .history-instagram-row .instagram-row-thumb {
        width: 32px;
        height: 36px;
    }

    .history-instagram-row .instagram-row-meta > span {
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

.history-preview-image {
    width: 100%;
    text-align: center;
}

.history-preview-image img {
    -webkit-touch-callout: none;
}

.activity-status[data-active='true'] {
    color: var(--accent-secondary);
}

.activity-action {
    display: inline-flex;
    align-items: center;
    min-width: var(--tap-size);
    justify-content: center;
    text-decoration: none;
}

.batch-receipt {
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.batch-receipt > summary {
    cursor: pointer;
    padding: 8px 0;
}

.batch-receipt > summary:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Download console: link first, then media and sharing options. */
#home-section :is(.download-container, #status-container, #result-container, #batch-results, #download-activity) {
    max-width: 880px;
}

.download-link-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
}

.download-controls-row .modern-input-wrapper,
.modern-input-wrapper.share-input-group {
    height: 56px;
    min-width: 0;
    align-items: center;
    padding: 5px;
    gap: 4px;
}

.download-controls-row #url-input,
.modern-input-wrapper > input.share-input {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
}

.download-controls-row #download-btn,
.modern-input-wrapper .btn-copy-share {
    height: var(--tap-size);
    margin: 0;
    padding: 0 8px;
    touch-action: manipulation;
}

.download-controls-row #download-btn {
    flex: 0 0 124px;
}

.modern-input-wrapper .btn-copy-share {
    flex: 0 0 var(--tap-size);
}

.btn-copy-share:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.download-options,
.download-settings {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.download-options {
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--glass-border);
}

.download-options .segmented-control,
#admin-section .segmented-control {
    gap: 4px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
}

.download-options .segmented-control label,
#admin-section .segmented-control label {
    flex: 0 0 auto;
    min-height: var(--tap-size);
    padding: 4px 10px;
    border: 1px solid transparent;
    font-size: 0.875rem;
}

.download-options .segmented-control input:checked + label,
#admin-section .segmented-control input:checked + label {
    background: rgba(251, 177, 173, 0.07);
    border-color: rgba(251, 177, 173, 0.28);
    box-shadow: none;
}

#admin-section .admin-segmented {
    margin-bottom: 24px;
}

#admin-section .segmented-control label {
    min-width: var(--tap-size);
}

.download-settings .quality-wrapper {
    margin: 0;
}

.download-settings select {
    min-height: var(--tap-size);
    width: 128px;
    padding: 0 8px;
    font-size: 1rem;
}

:is(.download-settings, #batch-form) .circle-checkbox-wrapper {
    width: 16px;
    height: 16px;
}

:is(.download-settings, #batch-form, #user-retention-list) .circle-checkbox-wrapper .checkmark {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border-width: 1px;
}

:is(.download-settings, #batch-form, #user-retention-list) .circle-checkbox-wrapper .checkmark::after {
    left: 5px;
    top: 1px;
    width: 4px;
    height: 8px;
}

#user-retention-list .circle-checkbox-wrapper {
    flex: none;
    width: var(--tap-size);
    height: var(--tap-size);
    touch-action: manipulation;
}

#user-retention-list .circle-checkbox-wrapper .checkmark {
    top: 50%;
    left: 50%;
    translate: -50% -50%;
}

#download-btn:disabled {
    cursor: wait;
    opacity: 0.8;
}

.spinner-icon {
    animation: download-spin 850ms linear infinite;
}

@keyframes download-spin {
    to { transform: rotate(360deg); }
}

.quality-wrapper:has(> #quality-group.hidden):has(> #format-group.hidden) {
    display: none;
}

.share-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap-size);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
}

@media (max-width: 560px) {
    .download-controls-row #download-btn {
        flex-basis: var(--tap-size);
    }

    #download-btn .download-label {
        display: none;
    }

    .segmented-control label {
        font-size: 0.875rem;
    }

    .download-options .segmented-control {
        width: 100%;
    }

    .download-options .segmented-control label {
        flex: 1;
        padding-inline: 4px;
    }
}

/* Tables */
.table-container {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    overflow-x: auto;
    max-width: 1200px;
    margin: 0 auto;
}

/* Keep history controls content-sized and in keyboard order at every width. */
.history-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.history-toolbar button {
    flex: none;
    width: auto;
    min-height: var(--tap-size);
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    touch-action: manipulation;
}

.history-toolbar #refresh-history {
    width: var(--tap-size);
    padding: 0;
}

.history-toolbar #toggle-history-select-mode {
    min-width: 64px;
}

.history-toolbar #toggle-history-select-mode.active {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.history-toolbar #delete-selected-history {
    background: rgba(255, 23, 68, 0.1);
    border: 1px solid rgba(255, 23, 68, 0.25);
    color: #ff6b81;
}

#history-section.history-select-mode #history-table .history-actions {
    opacity: 0.55;
    pointer-events: none;
    filter: grayscale(0.15);
}

#history-table .history-select-cell {
    padding: 0.5rem;
}

#history-table .history-select-cell .checkbox-wrapper {
    justify-content: center;
}

/* Force the history select checkbox to be a true square (avoid global input padding/width rules) */
#history-table .history-select-cell .checkbox-wrapper input[type='checkbox'] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    display: inline-block;
}

#history-table .history-select-cell .checkbox-wrapper span {
    display: none;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--text-secondary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Wrap long text in Title/URL column and center text (generic tables) */
td:nth-child(2) {
    word-break: break-all;
    max-width: 300px;
    text-align: center;
}

/* History table: keep Date on one line (especially in multi-select mode). */
#history-table tbody td:nth-child(1) {
    white-space: nowrap;
}

/* In history select mode, the Date becomes column 2 (because column 1 is the checkbox). */
#history-section.history-select-mode #history-table tbody td:nth-child(2) {
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}

/* History table: ensure Title wraps nicely in both modes.
   - Normal mode: Title is column 2
   - Select mode: Title is column 3 */
#history-table tbody td:nth-child(2),
#history-section.history-select-mode #history-table tbody td:nth-child(3) {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 360px;
    text-align: center;
}

/* Download status: one label, one rail, no competing spinner. */
#status-container {
    margin-top: 1rem;
}

.progress-bar {
    position: relative;
    isolation: isolate;
    display: grid;
    place-items: center;
    min-height: 40px;
    padding: 8px 12px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--accent-color) 30%, var(--border-color));
    border-radius: 999px;
    background: var(--input-bg);
    background: color-mix(in srgb, var(--accent-color) 6%, var(--input-bg));
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    overflow-wrap: anywhere;
}

.progress-fill {
    position: absolute;
    inset: 0;
    z-index: -1;
    transform-origin: left center;
    transform: scaleX(var(--progress, 0));
    background: #704943;
    background: color-mix(in srgb, var(--accent-color) 36%, var(--input-bg));
}

@media (prefers-reduced-motion: no-preference) {
    .progress-fill { transition: transform 200ms ease-out; }
}

.progress-announcement {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Result Card */
.result-card {
    background: linear-gradient(145deg, var(--card-bg), #1a1a1a);
    border: 1px solid var(--success-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-top: 2rem;
    animation: slideUp 0.3s ease;
}

.result-icon {
    font-size: 2.5rem;
    color: var(--success-color);
}

.result-info {
    flex: 1;
}

.result-info h3 {
    color: var(--success-color);
    margin-bottom: 0.5rem;
}

.result-info p {
    margin-bottom: 1rem;
    font-weight: 500;
}

.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.result-actions .btn-primary,
.result-actions .btn-secondary {
    width: auto;
    padding: 0.75rem 1.5rem;
}

.result-preview {
    width: 100%;
    max-height: 360px;
    margin-bottom: 1rem;
    border-radius: 12px;
    background: #000;
    display: block;
}

/* Batch Section */
.batch-container {
    max-width: 800px;
    margin: 0 auto;
}

.textarea-wrapper {
    margin-bottom: 1.5rem;
}

.batch-options {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.batch-options select {
    width: auto;
    min-width: 150px;
}

.batch-options button {
    width: auto;
    padding-left: 2rem;
    padding-right: 2rem;
}

/* Settings Section */
.settings-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.settings-card h2 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.settings-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

#create-key-form {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

#create-key-form button {
    width: auto;
    white-space: nowrap;
}

/* Match dropdown-style text for key/profile buttons */
#profile-form .btn-primary,
#create-key-form .btn-primary {
    font-size: 1rem;
    font-weight: 500;
}

.api-key-item {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.key-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.key-info code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    color: var(--accent-color);
    font-size: 0.9rem;
    word-break: break-all;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    transition: var(--transition);
    font-size: 1.1rem;
}

.btn-icon:hover {
    color: var(--text-primary);
}

.btn-icon.delete:hover {
    color: var(--error-color);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.pagination button {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Vertically center the "Page X" text with the buttons */
.pagination span {
    display: flex;
    align-items: center;
    height: 36px;
}

/* Badge */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.completed {
    background: rgba(0, 230, 118, 0.15);
    color: var(--success-color);
}

.badge.processing {
    background: rgba(124, 77, 255, 0.15);
    color: var(--accent-color);
}

.badge.failed {
    background: rgba(255, 23, 68, 0.15);
    color: var(--error-color);
}

.badge.pending {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}

.badge.deleted {
    background: rgba(158, 158, 158, 0.15);
    color: #bdbdbd;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Toast */
#toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Batch Results */
.batch-results-list {
    margin-top: 2rem;
}

.batch-results-list h3 {
    margin-bottom: 1rem;
    color: var(--accent-color);
}

.batch-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.batch-item-url {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

.batch-item-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Header Row */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-row h1 {
    margin: 0;
}

/* Controls alignment - make type/quality/format/buttons same height and row */
.batch-options .option-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.batch-options .toggle-switch {
    height: 40px;
    display: flex;
}

.batch-options .toggle-switch label {
    height: 100%;
    display: flex;
    align-items: center;
}

/* Override global padding for these selects so text is vertically centered */
.batch-options select {
    height: 40px;
    padding: 0 1rem;
}

/* Align button with bottom of selects in batch row */
.batch-options {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.batch-options .btn-primary {
    height: 40px;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
}

/* Responsive */
@media (max-width: 768px) {
    #dashboard-view {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        overflow: visible;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: max(8px, env(safe-area-inset-top))
            max(var(--page-gutter), env(safe-area-inset-right)) 8px
            max(var(--page-gutter), env(safe-area-inset-left));
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .sidebar .logo {
        margin-bottom: 0;
        gap: 4px;
        font-size: 1.3rem;
    }

    .nav-links {
        grid-row: 2;
        grid-column: 1 / -1;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        gap: 4px;
    }

    .nav-links li {
        margin-bottom: 0;
    }

    .nav-links button {
        min-height: 52px;
        flex-direction: column;
        justify-content: center;
        gap: 3px;
        padding: 3px 0;
        font-size: 0.75rem;
    }

    .nav-links li.active button {
        box-shadow: inset 0 -2px var(--accent-color);
    }

    .user-profile {
        grid-row: 1;
        grid-column: 2;
        border: 0;
        padding: 0;
    }

    .user-info {
        display: none;
    }

    .content {
        margin-left: 0;
        padding: 24px max(var(--page-gutter), env(safe-area-inset-right))
            max(24px, env(safe-area-inset-bottom)) max(var(--page-gutter), env(safe-area-inset-left));
    }

    .batch-options {
        flex-direction: column;
        align-items: stretch;
    }

    .batch-options button {
        width: 100%;
    }

    /* Make table responsive on mobile */
    .table-container {
        overflow-x: visible;
    }

    table {
        font-size: 0.85rem;
    }

    th,
    td {
        padding: 0.5rem;
        white-space: nowrap;
    }

    /* Hide less critical columns on mobile */
    th:nth-child(1),
    td:nth-child(1) {
        display: none;
        /* Hide Date column (most tables) */
    }

    th:nth-child(3),
    td:nth-child(3) {
        display: none;
        /* Hide Type column (most tables) */
    }

    /* History table (mobile):
       Header columns are always:
       1 Select (hidden unless select-mode)
       2 Date
       3 Title
       4 Quality/Format
       5 Status
       6 Action

       Generic mobile rules hide nth-child(3) for "Type", but that breaks History because Title is #3.
       Force the correct History headers/columns explicitly. */

    /* Hide Date + Quality/Format headers; keep Title header visible */
    #history-table thead th:nth-child(2) {
        display: none !important;
    }

    #history-table thead th:nth-child(4) {
        display: none !important;
    }

    #history-table thead th:nth-child(3) {
        display: table-cell !important;
    }

    /* When history select mode is ON:
       body columns become: 1 Select, 2 Date, 3 Title, 4 Quality, 5 Status, 6 Action
       - keep Select visible
       - hide Date + Quality
       - ensure Title is visible (generic rules would hide td#3) */
    #history-section.history-select-mode #history-table thead th:nth-child(1),
    #history-section.history-select-mode #history-table tbody td:nth-child(1) {
        display: table-cell !important;
    }

    #history-section.history-select-mode #history-table tbody td:nth-child(2),
    #history-section.history-select-mode #history-table tbody td:nth-child(4) {
        display: none !important;
    }

    #history-section.history-select-mode #history-table tbody td:nth-child(3) {
        display: table-cell !important;
    }

}

/* Modern Textarea */
.modern-textarea-wrapper {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0;
    transition: var(--transition);
    overflow: hidden;
}

.modern-textarea-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(251, 177, 173, 0.2);
}

.modern-textarea-wrapper textarea {
    border: none;
    background: transparent;
    padding: 1rem;
    width: 100%;
    box-shadow: none;
    resize: vertical;
    min-height: 200px;
    display: block;
}

/* Batch Controls Layout */
.batch-controls-row {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    align-items: center;
}

/* Make dropdown and Queue All button always the same width */
.batch-controls-row > * {
    flex: 1 1 0;
    min-width: 0;
}

.batch-controls-row select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    height: 48px;
    /* Match button height */
}

.batch-controls-row .btn-primary {
    height: 48px;
    width: 100%;
    justify-content: center;
    /* Match dropdown text size/weight */
    font-size: 1rem;
    font-weight: 500;
    padding-inline: 8px;
}

/* Responsive Batch */
@media (max-width: 768px) {
    /* Keep the quality/format dropdown and Queue All button side by side on mobile */
    .batch-controls-row {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
    }

    /* Let the inner controls fill their 50% containers */
    .batch-controls-row select,
    .batch-controls-row .btn-primary {
        width: 100%;
    }

    table {
        table-layout: fixed !important;
    }

    th,
    td {
        vertical-align: top;
        overflow-wrap: break-word;
        word-wrap: break-word;
        hyphens: auto;
    }

    /* Hide Date and Type columns on mobile */
    th:nth-child(1),
    td:nth-child(1),
    th:nth-child(3),
    td:nth-child(3) {
        display: none !important;
    }

    /* History table (mobile): keep Title header correct after adding select column */
    #history-table thead th:nth-child(2) {
        display: none !important;
        /* Date */
    }

    #history-table thead th:nth-child(4) {
        display: none !important;
        /* Quality/Format */
    }

    #history-table thead th:nth-child(3) {
        display: table-cell !important;
        /* Title */
    }

    /* History select mode: keep checkbox column, hide Date+Quality, ensure Title is visible */
    #history-section.history-select-mode #history-table thead th:nth-child(1),
    #history-section.history-select-mode #history-table tbody td:nth-child(1) {
        display: table-cell !important;
    }

    #history-section.history-select-mode #history-table tbody td:nth-child(2),
    #history-section.history-select-mode #history-table tbody td:nth-child(4) {
        display: none !important;
    }

    #history-section.history-select-mode #history-table tbody td:nth-child(3) {
        display: table-cell !important;
    }

    /* Title/URL column */
    th:nth-child(2),
    td:nth-child(2) {
        width: 40% !important;
        max-width: 40% !important;
        overflow: hidden;
        white-space: normal;
    }

    /* Status column */
    th:nth-child(4),
    td:nth-child(4) {
        width: 40% !important;
    }

    /* Action column */
    th:nth-child(5),
    td:nth-child(5) {
        width: 20% !important;
        text-align: center;
    }

    /* History table widths in SELECT MODE (columns shift because of the checkbox column):
       1 Select, 2 Date(hidden), 3 Title, 4 Quality(hidden), 5 Status, 6 Action */
    #history-section.history-select-mode #history-table th:nth-child(3),
    #history-section.history-select-mode #history-table td:nth-child(3) {
        width: 40% !important;
        max-width: 40% !important;
        overflow: hidden;
        white-space: normal;
    }

    #history-section.history-select-mode #history-table th:nth-child(5),
    #history-section.history-select-mode #history-table td:nth-child(5) {
        width: 40% !important;
    }

    #history-section.history-select-mode #history-table th:nth-child(6),
    #history-section.history-select-mode #history-table td:nth-child(6) {
        width: 20% !important;
        text-align: center;
    }
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    width: auto;
}

/* Text Utilities */
.text-secondary {
    color: var(--text-secondary);
}

/* Table inside Glass Card */
.glass-card .table-container {
    background: transparent;
    border: none;
    border-radius: 0;
    margin: 0;
}

.glass-card .pagination {
    margin-top: 0;
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
}

/* Settings Form inside Glass Card */
.glass-card #create-key-form {
    margin-bottom: 2rem;
}

#history-table .history-select-col {
    width: 48px;
}

#history-table .history-empty-cell {
    display: table-cell !important; /* Keep the spanning cell visible when the first column is hidden. */
    padding: 24px 8px;
    text-align: center;
    color: var(--text-secondary);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-secondary);
    opacity: 1;
}

#add-whitelist-email {
    width: auto;
}

.settings-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 12px;
}

.settings-description {
    margin-bottom: 16px;
}

.settings-hint {
    display: block;
    font-size: 0.85rem;
}

.feature-toggle-label {
    margin-bottom: 8px;
}

.feature-toggle-group {
    margin-bottom: 24px;
}

.security-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.cleanup-controls {
    align-items: center;
}

.cleanup-controls input {
    min-width: 0;
    flex: 1;
}

.cleanup-controls button {
    white-space: nowrap;
}

.retention-override {
    margin-top: 24px;
}

.retention-description {
    font-size: 0.9rem;
}

/* Settings Sections */
.security-feedback {
    margin-top: 8px;
    color: var(--text-secondary);
}

.security-feedback:empty {
    display: none;
}

.security-feedback.is-error {
    color: #ff8299;
}

.account-security-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-block: 12px;
}

.account-security-actions button,
#passkey-add-form button {
    width: auto;
}

#totp-qr {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

#totp-seed,
#recovery-code-list {
    display: block;
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

#recovery-codes {
    margin-block: 16px;
}

#recovery-done {
    margin-top: 8px;
}

.passkey-list {
    list-style: none;
}

.passkey-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding-block: 8px;
    overflow-wrap: anywhere;
}

.passkey-list button {
    width: auto;
    flex: none;
    min-height: var(--tap-size);
}

#passkey-add-form {
    gap: 8px;
    margin-top: 8px;
}

#passkey-name {
    min-width: 0;
    padding-inline: 8px;
}

#passkey-add-form button {
    flex: none;
    padding-inline: 12px;
    white-space: nowrap;
}

.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

.settings-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section > h2,
.danger-zone h2 {
    font-size: 1.17em;
}

#recovery-codes-title,
#admin-section .settings-section h3 {
    font-size: 1em;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Instagram Cookies (multiple cookie sets) */
.instagram-cookies-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.instagram-cookie-set {
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.9rem;
}

.instagram-cookie-set-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.instagram-cookie-set-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.remove-instagram-cookie-set {
    color: var(--text-secondary);
}

.remove-instagram-cookie-set:hover {
    color: var(--error-color);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Password input with reveal toggle */
.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper input {
    padding-right: 2.75rem;
}

.password-toggle {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}

.password-toggle:hover {
    color: var(--text-primary);
}

/* Danger Zone */
.danger-zone {
    border: 1px solid rgba(255, 23, 68, 0.3);
    background: rgba(255, 23, 68, 0.03);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    margin-top: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

/* Danger Zone text */
.danger-zone-text h3 {
    color: var(--error-color);
    margin: 0 0 0.5rem 0;
}

.danger-zone-text p {
    margin: 0;
}

/* Danger Zone button */
.danger-zone .btn-danger {
    width: auto;
    padding: 0.75rem 1.75rem;
}

.btn-danger {
    width: 100%;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 23, 68, 0.4);
    background: rgba(255, 23, 68, 0.1);
    color: var(--error-color);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-danger:hover {
    background: rgba(255, 23, 68, 0.2);
    border-color: var(--error-color);
    transform: translateY(-1px);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    backdrop-filter: blur(16px);
}

.confirm-backdrop {
    z-index: 980;
    background:
        radial-gradient(circle at 50% 0%, rgba(251, 177, 173, 0.14), transparent 28rem),
        rgba(0, 0, 0, 0.78);
}

.modal {
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    padding: var(--panel-padding);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    overflow: auto;
    overscroll-behavior: contain;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.story-modal {
    max-width: 600px;
}

.story-item-count {
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.story-modal .selection-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.story-actions button {
    min-height: var(--tap-size);
    padding-inline: 8px;
}

.confirm-modal-card {
    max-width: 460px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
        rgba(10, 10, 10, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.74),
        0 0 80px rgba(251, 177, 173, 0.1);
    position: relative;
}

.confirm-icon-shell {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: var(--error-color);
    background: rgba(255, 23, 68, 0.12);
    border: 1px solid rgba(255, 23, 68, 0.28);
    margin-bottom: 1rem;
    position: relative;
    z-index: 1;
}

.confirm-modal-header,
.confirm-modal-body,
.confirm-modal-actions {
    position: relative;
    z-index: 1;
}

.confirm-modal-header h2 {
    font-size: 1.25rem;
    letter-spacing: -0.01em;
}

.confirm-modal-body p {
    margin-bottom: 0;
    line-height: 1.55;
}

.modal-header h2 {
    margin: 0 0 0.5rem;
}

.modal-body p {
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap; /* Allow wrapping */
}

:is(.media-actions, .history-preview-footer) > :is(.btn-primary, .btn-secondary) {
    min-width: 0;
    min-height: 44px;
    text-align: center;
}

.history-preview-footer {
    display: flex;
    gap: inherit;
}

.history-preview-footer:has(> .hidden) {
    display: contents;
}

/* In modals, buttons should be compact */
.modal-actions .btn-primary,
.modal-actions .btn-secondary,
.modal-actions .btn-danger {
    width: auto;
    white-space: nowrap;
    /* On mobile, let them grow if needed or keep auto */
}

@media (max-width: 480px) {
    .modal-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        justify-content: stretch;
    }
    
    .modal-actions .btn-primary,
    .modal-actions .btn-secondary,
    .modal-actions .btn-danger {
        width: 100%;
        margin: 0;
        justify-content: center;
    }

    /* Make the last button span full width if it's the odd one out (e.g., 3rd button) */
    .modal-actions > :last-child:nth-child(odd) {
        grid-column: span 2;
    }

    .media-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    :is(.media-actions, .history-preview-footer) > :is(.btn-primary, .btn-secondary) {
        padding-inline: 0.5rem;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .media-actions > :last-child:nth-child(odd) {
        grid-column: auto;
    }

    .media-actions:not(:has(> :not(.hidden) ~ :not(.hidden))) > :not(.hidden) {
        grid-column: 1 / -1;
    }

    .history-preview-footer:not(:has(> .hidden)) {
        display: grid;
        grid-column: 1 / -1;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* History Preview Modal (larger, media-friendly) */
.preview-modal {
    max-width: 920px;
    width: min(920px, 95vw);
    padding: 1.5rem;
}

.preview-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.preview-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* History Preview Carousel Controls (used for grouped gallery rows) */
.history-preview-media-wrapper {
    position: relative;
    width: 100%;
}

.history-preview-carousel-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* allow clicks only on buttons */
}

.history-preview-arrow {
    pointer-events: auto;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.history-preview-arrow:hover {
    background: rgba(0, 0, 0, 0.75);
    border-color: rgba(251, 177, 173, 0.45);
    color: var(--accent-color);
    transform: translateY(calc(-50% - 1px));
}

.history-preview-arrow:disabled {
    opacity: 0.35 !important;
    pointer-events: none !important;
}

.history-preview-arrow-left {
    left: 12px;
}

.history-preview-arrow-right {
    right: 12px;
}

.history-preview-counter-overlay {
    pointer-events: none;
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
    font-size: 0.85rem;
    user-select: none;
}

@media (max-width: 480px) {
    .history-preview-arrow {
        width: 40px;
        height: 40px;
    }

    .history-preview-arrow-left {
        left: 10px;
        right: auto;
    }

    .history-preview-arrow-right {
        right: 10px;
        left: auto;
    }

    .history-preview-counter-overlay {
        bottom: 10px;
        font-size: 0.8rem;
    }
}

.history-preview-content {
    width: 100%;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.history-preview-content img,
.history-preview-content video {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 12px;
    background: #000;
    display: block;
    margin-left: auto;
    margin-right: auto;
    -webkit-touch-callout: default !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    pointer-events: auto !important;
}

.history-preview-content audio {
    width: 100%;
}

/* History table title should look clickable once we wire the JS click handler */
.history-title-link {
    cursor: pointer;
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: rgba(251, 177, 173, 0.55);
    text-underline-offset: 3px;
    transition: var(--transition);
}

.history-title-link:hover {
    color: var(--accent-color);
    text-decoration-color: var(--accent-color);
}

/* Story Selection Grid */
.story-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    max-height: 500px;
    overflow-y: auto;
    padding: 0.5rem;
}

.story-item {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 0;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    transition: var(--transition);
    aspect-ratio: 9/16;
    display: flex;
    flex-direction: column;
}

@media (hover: hover) and (pointer: fine) {
    .story-item:hover {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}

.story-item.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(251, 177, 173, 0.3);
}

.story-item input[type='checkbox'] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.story-item:has(input:focus-visible) {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Custom Checkmark Overlay */
.checkmark-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 10;
}

.story-item.selected .checkmark-overlay {
    background: var(--accent-color);
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.checkmark-overlay i {
    color: #000;
    font-size: 14px;
    opacity: 0;
    transform: scale(0.5);
    transition: var(--transition);
}

.story-item.selected .checkmark-overlay i {
    opacity: 1;
    transform: scale(1);
}

/* Thumbnail and Meta */
.story-thumbnail-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.story-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #1a1a1a;
    transition: transform 0.3s ease;
}

@media (max-width: 560px) {
    .story-modal .story-list-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .story-modal .story-item {
        aspect-ratio: 1;
    }
}

.story-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
    color: #fff;
    font-size: 0.85rem;
    pointer-events: none;
}

.story-meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    font-weight: 500;
}

.story-modal .story-thumbnail {
    object-fit: contain;
}

.story-preview-placeholder:not([hidden]) {
    display: grid;
    place-items: center;
    height: 100%;
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.duration-badge {
    display: inline-block;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    margin-top: 4px;
}

/* Square Checkbox (Compact Toggle) */

/* Circular Checkbox */
.circle-checkbox-wrapper {
    position: relative;
    display: inline-block;
    width: 24px;
    height: 24px;
    cursor: pointer;
}

.circle-checkbox-wrapper input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.circle-checkbox-wrapper .checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 24px;
    width: 24px;
    background-color: transparent;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    transition: var(--transition);
}

.circle-checkbox-wrapper:hover .checkmark {
    border-color: var(--accent-color);
}

.circle-checkbox-wrapper input:checked ~ .checkmark {
    background: var(--gradient-primary);
    border-color: transparent;
}

.circle-checkbox-wrapper .checkmark:after {
    content: '';
    position: absolute;
    display: none;
}

.circle-checkbox-wrapper input:checked ~ .checkmark:after {
    display: block;
}

.circle-checkbox-wrapper .checkmark:after {
    left: 8px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
    .section, .spinner-icon, .fa-spin, .progress-fill {
        animation: none;
    }

    .btn-primary, .nav-links button {
        transition: none;
    }
}
