/* pages.css: the rules that several pages share. Settings and Admin mount the GIF library widget
   (js/ui/gif-library.js, templates t-gif-library and t-gif-lib-card). Admin and Settings share the toggle row and
   switch; Settings and channel settings share the page shell and the form block. The danger items, the upload button,
   the not-found page and the mount rule of the pages in the chat column are here too. Each page has its own file:
   signin.css, admin.css, channel-settings.css and settings.css. css/README.md has the map of the stylesheets. */

/* ==== GIF library ==== */
/* js/ui/gif-library.js; t-gif-library, t-gif-lib-card */

.gif-library {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.gif-lib-file-input {
    display: none;
}

/* Toolbar: folder chips left, action buttons right; wraps on narrow screens */
.gif-lib-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.gif-lib-folders {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    max-width: 100%;
    padding-bottom: 2px; /* keeps the scrollbar off the chips */
}

.folder-chip {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    flex-shrink: 0;
}

.folder-chip:hover {
    color: var(--text-primary);
}

.folder-chip.active {
    background: var(--accent-primary);
    color: var(--accent-ink);
}

.gif-lib-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.gif-lib-filter {
    flex: 0 1 170px;
    min-width: 110px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.82rem;
}

.gif-lib-filter:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.gif-lib-action-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    line-height: 1.3;
}

.gif-lib-action-btn:hover {
    background: var(--bg-hover);
}

.gif-lib-action-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: auto; /* keep the tooltip explaining why */
}

/* Quota */
.gif-lib-quota {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.gif-lib-quota-track {
    flex: 1;
    max-width: 260px;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.gif-lib-quota-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 3px;
}

.gif-lib-quota-fill.hot {
    background: var(--color-warning);
}

.gif-lib-quota-label {
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* Status strips: upload progress, import progress, notices, errors */
.gif-lib-strip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.82rem;
}

.gif-lib-strip.error {
    color: var(--color-danger);
}

.gif-lib-strip.done {
    color: var(--color-success);
}

.gif-lib-strip-text {
    white-space: pre-line;
}

.gif-lib-strip-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 2px 4px;
}

.gif-lib-strip-dismiss:hover {
    color: var(--text-primary);
}

.gif-lib-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1rem 0;
}

/* Management grid: aligned cells with always-visible controls (deliberately not the
   picker's masonry — this is a workbench, not a browsing surface) */
.gif-lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.gif-lib-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 6px;
}

.gif-lib-thumb {
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gif-lib-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gif-lib-processing {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
}

/* Tag chips + inline editor (same interaction pattern as the Admin GIFs table) */
.gif-library .gif-tags-view {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    cursor: pointer;
    min-height: 20px;
    border-radius: 4px;
    padding: 2px;
}

.gif-library .gif-tags-view:hover {
    background: var(--bg-hover);
}

.gif-library .gif-tag-chip {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 8px;
    padding: 1px 7px;
    font-size: 0.72rem;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gif-library .gif-tag-chip.more {
    color: var(--text-muted);
}

.gif-library .gif-tags-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75rem;
}

.gif-library .gif-tags-edit {
    display: flex;
    align-items: center;
    gap: 3px;
}

.gif-library .gif-tags-input {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-dark);
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 0.75rem;
}

.gif-library .gif-tags-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.gif-library .gif-tags-btn {
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: none;
    border-radius: 5px;
    padding: 3px 6px;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
}

.gif-library .gif-tags-btn:hover {
    color: var(--text-primary);
}

.gif-library .gif-tags-btn.save {
    color: var(--color-success);
}

/* Per-card folder select + remove/delete row */
.gif-lib-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.gif-lib-folder-select {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-dark);
    border-radius: 5px;
    padding: 3px 4px;
    font-size: 0.72rem;
}

.gif-lib-newfolder {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--accent-primary);
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 0.72rem;
}

.gif-lib-newfolder:focus {
    outline: none;
}

.gif-lib-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 3px 5px;
    border-radius: 5px;
    flex-shrink: 0;
}

.gif-lib-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.gif-lib-btn.danger:hover {
    color: var(--color-danger);
}

/* Phones: two columns is the sweet spot for thumbnails + controls.
   minmax(0, 1fr), not bare 1fr — 1fr's auto minimum lets a long nowrap tag chip or
   folder option inflate a track past the viewport, making the whole page wobble
   sideways on touch scroll. With the track clamped, chips ellipsize instead. */
@media (max-width: 600px) {
    .gif-lib-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ==== Toggle row and switch of Admin and Settings ==== */
/* js/pages/admin.js, js/pages/settings.js; t-toggle-row, t-settings */

/* Toggle switch (shared pattern with Admin) */
:is(.page-admin, .page-settings) .toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

:is(.page-admin, .page-settings) .toggle-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

:is(.page-admin, .page-settings) .toggle-label {
    color: var(--text-white);
    font-size: 0.9375rem;
    font-weight: 500;
}

:is(.page-admin, .page-settings) .toggle-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
}

:is(.page-admin, .page-settings) .toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

:is(.page-admin, .page-settings) .toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

:is(.page-admin, .page-settings) .toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 12px;
    transition: background-color 0.2s;
}

:is(.page-admin, .page-settings) .toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.2s, background-color 0.2s;
}

:is(.page-admin, .page-settings) .toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
}

:is(.page-admin, .page-settings) .toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

/* ==== Page shell and form block of channel settings and Settings ==== */
/* js/pages/channel-settings.js, js/pages/settings.js; t-channel-settings, t-settings */

:is(.page-channel, .page-settings) .settings-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1.5rem;
    overflow-y: auto;
}

:is(.page-channel, .page-settings) .settings-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

:is(.page-channel, .page-settings) .settings-header h2 {
    color: var(--text-white);
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

:is(.page-channel, .page-settings) .back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-sidebar);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

:is(.page-channel, .page-settings) .back-button:hover {
    background: var(--bg-hover);
    color: var(--text-white);
}

:is(.page-channel, .page-settings) .settings-content {
    max-width: 600px;
    width: 100%;
}

:is(.page-channel, .page-settings) .settings-section {
    background: var(--bg-sidebar);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

:is(.page-channel, .page-settings) .settings-section h3 {
    color: var(--text-white);
    font-size: 1.125rem;
    font-weight: 600;
}

/* Form elements */
:is(.page-channel, .page-settings) .form-group {
    margin-bottom: 1.25rem;
}

:is(.page-channel, .page-settings) .form-group:last-child {
    margin-bottom: 0;
}

:is(.page-channel, .page-settings) .form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0.5rem;
}

:is(.page-channel, .page-settings) .form-input,
:is(.page-channel, .page-settings) .form-textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

:is(.page-channel, .page-settings) .form-input:focus,
:is(.page-channel, .page-settings) .form-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

:is(.page-channel, .page-settings) .form-input::placeholder,
:is(.page-channel, .page-settings) .form-textarea::placeholder {
    color: var(--text-placeholder);
}

:is(.page-channel, .page-settings) .form-textarea {
    min-height: 80px;
    resize: vertical;
}

:is(.page-channel, .page-settings) .form-hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.form-counter {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: right;
    margin-top: 0.25rem;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    :is(.page-channel, .page-settings) .settings-container {
        padding: 1rem;
    }

    :is(.page-channel, .page-settings) .settings-section {
        padding: 1rem;
    }
}

/* ==== Danger items of Admin and channel settings ==== */
/* js/pages/admin.js, js/pages/channel-settings.js; t-channel-settings */

/* Danger zone */
.danger-section {
    border: 1px solid color-mix(in srgb, var(--color-danger) 30%, transparent);
}

.danger-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.danger-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.danger-title {
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
}

.danger-desc {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.delete-button {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--color-danger);
    border-radius: 4px;
    color: var(--color-danger);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
    white-space: nowrap;
}

.delete-button:hover {
    background: color-mix(in srgb, var(--color-danger) 15%, transparent);
}

.delete-button.confirm {
    background: var(--color-danger);
    color: var(--text-white);
    border-color: var(--color-danger);
}

.delete-button.confirm:hover {
    background: #c03537;
}

@media (max-width: 600px) {
    .danger-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .delete-button {
        width: 100%;
        text-align: center;
    }
}

/* ==== Upload button of Admin and Settings ==== */
/* js/pages/admin.js, js/pages/settings.js; t-settings */

.upload-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;      /* a <button> keeps the browser's border and font without these; .danger-btn next to it has neither */
    font: inherit;
    padding: 0.5rem 1rem;
    background: var(--accent-primary);
    color: var(--accent-ink);
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

.upload-button:hover {
    background: var(--accent-hover);
}

/* ==== Not found page and page mount ==== */
/* js/main.js; t-not-found */

.page-not-found { padding: 3rem 1rem; text-align: center; color: var(--text-secondary); }

/* The settings and channel pages mount in the chat column, a flex column. They take its height, so their
   container (height: 100%, overflow-y: auto) scrolls. Without this the page overflows the clipped frame. */
.messages-container > .page-settings, .messages-container > .page-channel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages-container > .page-settings > .settings-container, .messages-container > .page-channel > .settings-container { flex: 1; min-height: 0; }
