:root {
    --bg-page: #101318;
    --bg-panel: #181d24;
    --bg-panel-soft: #202733;
    --bg-input: #252d39;
    --border: #313b49;
    --text-main: #f4f7fb;
    --text-muted: #9aa7b7;
    --primary: #2f80ed;
    --primary-hover: #1f6ed4;
    --success: #1fa971;
    --danger: #e25555;
    --danger-hover: #c94040;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
    width: 100%;
    height: 100%;
    background: var(--bg-page);
    color: var(--text-main);
    overflow: hidden;
}

button,
input {
    font: inherit;
}

.hidden {
    display: none !important;
}

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    flex-shrink: 0;
    background: rgba(24, 29, 36, 0.98);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
    z-index: 10;
}

.topbar {
    width: min(1500px, calc(100% - 32px));
    margin: 0 auto;
    padding: 14px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: nowrap;
}

.brand-block {
    min-width: 180px;
    flex: 0 0 auto;
}

.brand-block h1 {
    font-size: 1.25rem;
    font-weight: 750;
    letter-spacing: 0;
}

.brand-block span,
.selection-status span {
    color: var(--text-muted);
    font-size: 0.84rem;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px;
    background: var(--bg-panel-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.tool-btn,
.selection-btn,
.album-btn,
.clear-album-btn,
.modal-btn {
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-main);
    transition: background 0.18s, border-color 0.18s, color 0.18s, opacity 0.18s;
}

.tool-btn {
    min-height: 34px;
    padding: 0 12px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.86rem;
    font-weight: 650;
}

.tool-btn:hover,
.tool-btn.active {
    color: var(--text-main);
    background: #303948;
}

.icon-tool {
    width: 36px;
    padding: 0;
    font-size: 1.08rem;
}

.selection-status {
    display: flex;
    align-items: baseline;
    flex: 0 0 auto;
}

.selection-status strong {
    min-width: 82px;
    font-size: 0.95rem;
}

.selection-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
}

#bulk-delete-form {
    display: flex;
}

.selection-btn {
    min-height: 34px;
    padding: 0 13px;
    background: #27303d;
    color: var(--text-main);
    font-weight: 650;
    font-size: 0.86rem;
}

.selection-btn:hover {
    background: #343f50;
}

.selection-btn.muted {
    color: var(--text-muted);
}

.selection-btn.danger {
    background: rgba(226, 85, 85, 0.14);
    color: #ff9b9b;
    border-color: rgba(226, 85, 85, 0.24);
}

.selection-btn.danger:hover:not(:disabled) {
    background: var(--danger);
    color: white;
}

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

.gallery-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px 180px;
    scroll-behavior: smooth;
}

.toast-message {
    position: fixed;
    top: 86px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    width: min(760px, calc(100% - 32px));
    padding: 14px 18px;
    border-radius: 8px;
    text-align: center;
    font-weight: 750;
    box-shadow: var(--shadow);
    animation: toast-in 0.22s ease-out;
}

.toast-message.success {
    background: #12372b;
    color: #8df0c2;
    border: 1px solid rgba(31, 169, 113, 0.55);
}

.toast-message.error {
    background: #3b2024;
    color: #ffabab;
    border: 1px solid rgba(226, 85, 85, 0.55);
}

.toast-message.hide {
    opacity: 0;
    transform: translate(-50%, -8px);
    transition: opacity 0.28s, transform 0.28s;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, -8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.gallery-shell {
    width: min(1500px, 100%);
    margin: 0 auto;
}

.alert {
    padding: 13px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-weight: 650;
    text-align: center;
}

.alert.success {
    background: rgba(31, 169, 113, 0.14);
    color: #75e1b2;
    border: 1px solid rgba(31, 169, 113, 0.35);
}

.alert.error {
    background: rgba(226, 85, 85, 0.14);
    color: #ff9b9b;
    border: 1px solid rgba(226, 85, 85, 0.35);
}

.empty-state {
    min-height: 44vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--text-muted);
    text-align: center;
}

.gallery-content {
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.gallery-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-header,
.album-header {
    min-height: 42px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-main);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.section-title {
    font-weight: 750;
    font-size: 0.98rem;
}

.section-count {
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 650;
}

.album-header {
    cursor: pointer;
    padding: 0 2px;
}

.accordion-arrow {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-panel-soft);
    color: var(--text-muted);
    transition: transform 0.18s, background 0.18s;
}

.gallery-section.collapsed .accordion-arrow {
    transform: rotate(-90deg);
}

.gallery-section.collapsed .gallery-grid {
    display: none;
}

.gallery-grid {
    display: grid;
    gap: 16px;
}

.layout-4 .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.layout-6 .gallery-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.layout-8 .gallery-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 12px;
}

.layout-random .gallery-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-auto-rows: 92px;
    grid-auto-flow: dense;
}

.image-card {
    position: relative;
    min-width: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.image-card:hover {
    transform: translateY(-2px);
    border-color: #536071;
    box-shadow: var(--shadow);
}

.image-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(47, 128, 237, 0.36), var(--shadow);
}

.select-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 3;
    width: 28px;
    height: 28px;
    cursor: pointer;
}

.select-overlay input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.select-overlay span {
    width: 28px;
    height: 28px;
    display: block;
    border-radius: 7px;
    background: rgba(10, 13, 18, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.42);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.select-overlay input:checked + span {
    background: var(--primary);
    border-color: var(--primary);
}

.select-overlay input:checked + span::after {
    content: "";
    position: absolute;
    left: 9px;
    top: 5px;
    width: 8px;
    height: 14px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.card-image-wrapper {
    width: 100%;
    aspect-ratio: 1 / 0.76;
    background: #07090c;
    overflow: hidden;
}

.layout-8 .card-image-wrapper {
    aspect-ratio: 1 / 0.88;
}

.card-image-wrapper a,
.card-image-wrapper img {
    width: 100%;
    height: 100%;
    display: block;
}

.card-image-wrapper img {
    object-fit: cover;
    transition: opacity 0.18s, transform 0.18s;
}

.image-card:hover .card-image-wrapper img {
    opacity: 0.9;
    transform: scale(1.02);
}

.card-footer {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.img-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.album-pill {
    width: fit-content;
    max-width: 100%;
    padding: 4px 8px;
    border-radius: 6px;
    background: #26313f;
    color: #c5d0df;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.btn {
    min-height: 34px;
    border: 0;
    border-radius: 6px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    transition: background 0.18s, color 0.18s;
}

.copy-btn {
    flex: 1;
    background: var(--bg-input);
}

.copy-btn:hover {
    background: #364252;
}

.copy-btn.success {
    background: var(--success);
    color: white;
}

.delete-form {
    display: flex;
}

.delete-btn {
    width: 38px;
    padding: 0;
    background: rgba(226, 85, 85, 0.12);
    color: #ff9b9b;
}

.delete-btn:hover {
    background: var(--danger);
    color: white;
}

.layout-random .image-card {
    min-height: 100%;
}

.layout-random .card-image-wrapper {
    aspect-ratio: auto;
    flex: 1;
}

.layout-random .card-footer {
    padding: 10px;
}

.layout-random .random-large {
    grid-column: span 3;
    grid-row: span 4;
}

.layout-random .random-wide {
    grid-column: span 4;
    grid-row: span 3;
}

.layout-random .random-tall {
    grid-column: span 2;
    grid-row: span 4;
}

.layout-random .random-small {
    grid-column: span 2;
    grid-row: span 3;
}

.chat-composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: rgba(24, 29, 36, 0.98);
    border-top: 1px solid var(--border);
    padding: 12px 16px 16px;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.28);
}

.composer-container {
    width: min(980px, 100%);
    margin: 0 auto;
}

#upload-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preview-strip {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.preview-strip:empty {
    display: none;
}

.preview-item {
    position: relative;
    width: 76px;
    height: 76px;
    flex: 0 0 auto;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--primary);
    background: #07090c;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.remove-preview {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.72);
    color: white;
    cursor: pointer;
}

.remove-preview:hover {
    background: var(--danger);
}

.album-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
}

.album-btn,
.clear-album-btn {
    min-height: 30px;
    padding: 0 10px;
    background: #26313f;
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 700;
}

.album-btn:hover,
.clear-album-btn:hover {
    background: #344153;
}

.album-chip {
    max-width: 360px;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(47, 128, 237, 0.16);
    border: 1px solid rgba(47, 128, 237, 0.34);
    color: #9fc7ff;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clear-album-btn {
    color: var(--text-muted);
}

.input-bar {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 8px;
}

.input-bar:focus-within {
    border-color: var(--primary);
}

.icon-btn {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    flex: 0 0 auto;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.paste-area {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    display: flex;
    align-items: center;
    outline: none;
    color: var(--text-main);
    cursor: text;
}

.placeholder-text {
    color: var(--text-muted);
    pointer-events: none;
}

.send-btn {
    min-height: 42px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 750;
    flex: 0 0 auto;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.6);
}

.album-modal {
    width: min(420px, 100%);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.album-modal h2 {
    font-size: 1.12rem;
    margin-bottom: 8px;
}

.album-modal p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 14px;
}

.album-modal input {
    width: 100%;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg-input);
    color: var(--text-main);
    outline: none;
    padding: 0 12px;
}

.album-modal input:focus {
    border-color: var(--primary);
}

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

.modal-btn {
    min-height: 36px;
    padding: 0 13px;
    font-weight: 750;
}

.modal-btn.muted {
    background: #28313f;
    color: var(--text-muted);
}

.modal-btn.primary {
    background: var(--primary);
    color: white;
}

@media (max-width: 1180px) {
    .layout-6 .gallery-grid,
    .layout-8 .gallery-grid,
    .layout-random .gallery-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .layout-random .random-large,
    .layout-random .random-wide,
    .layout-random .random-tall,
    .layout-random .random-small {
        grid-column: span 2;
        grid-row: span 3;
    }
}

@media (max-width: 820px) {
    .topbar {
        width: min(100% - 20px, 1500px);
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar,
    .selection-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .toolbar-group {
        overflow-x: auto;
    }

    .layout-4 .gallery-grid,
    .layout-6 .gallery-grid,
    .layout-8 .gallery-grid,
    .layout-random .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .layout-random .gallery-grid {
        grid-auto-rows: auto;
    }

    .layout-random .random-large,
    .layout-random .random-wide,
    .layout-random .random-tall,
    .layout-random .random-small {
        grid-column: span 1;
        grid-row: auto;
    }
}

@media (max-width: 560px) {
    .gallery-scroll-area {
        padding: 16px 10px 198px;
    }

    .layout-4 .gallery-grid,
    .layout-6 .gallery-grid,
    .layout-8 .gallery-grid,
    .layout-random .gallery-grid {
        grid-template-columns: 1fr;
    }

    .selection-status,
    .selection-actions,
    .album-row,
    .input-bar {
        flex-wrap: wrap;
    }

    .paste-area {
        flex-basis: 100%;
        order: 3;
    }

    .send-btn {
        margin-left: auto;
    }
}
