@font-face {
    font-family: "Noto Sans Devanagari Local";
    src: url("/fonts/noto-sans-devanagari-400.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Noto Sans Devanagari Local";
    src: url("/fonts/noto-sans-devanagari-500.ttf") format("truetype");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Noto Sans Devanagari Local";
    src: url("/fonts/noto-sans-devanagari-700.ttf") format("truetype");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* Telegram-inspired dark theme (refined) */
:root {
    --tg-bg: #0E141B;
    --tg-secondary: #17212B;
    --tg-accent: #5AA1E3;
    --tg-bubble-out: #2B5278;
    --tg-bubble-in: rgb(0 0 0);
    --tg-bubble-out-border: rgba(255, 255, 255, 0.16);
    --tg-bubble-in-border: rgba(255, 255, 255, 0.12);
    --tg-text: #F4F7FB;
    --tg-hint: #8FA0B2;
    --tg-border: #0E1621;
    /* Ambient glows behind the app — themes can flatten these to none. */
    --tg-ambient-1: radial-gradient(900px 600px at 15% -10%, rgba(90, 161, 227, 0.08), transparent 60%);
    --tg-ambient-2: radial-gradient(700px 500px at 85% 0%, rgba(42, 60, 80, 0.12), transparent 55%);
    --app-vh: 100dvh;
    --touch-target: 44px;
    --sidebar-width: min(84vw, 340px);
    --composer-pad-x: 8px;
    --composer-pad-y: 8px;
}

body {
    background-color: var(--tg-bg);
    background-image: var(--tg-ambient-1), var(--tg-ambient-2);
    color: var(--tg-text);
    font-family: "Manrope", "Noto Sans Devanagari Local", "Nirmala UI", "Mangal", "Kohinoor Devanagari", "Segoe UI", system-ui, sans-serif;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: none;
    min-height: var(--app-vh);
}

:focus-visible {
    outline: 2px solid rgba(90, 161, 227, 0.9);
    outline-offset: 2px;
}

html,
body {
    height: var(--app-vh);
}

body.sidebar-open {
    overflow: hidden;
}

#chat-view {
    height: var(--app-vh);
}

#chat-main {
    min-width: 0;
}

#sidebar {
    width: var(--sidebar-width);
    max-width: 340px;
}

#chat-header {
    min-height: 56px;
    padding-left: clamp(10px, 2.5vw, 16px);
    padding-right: clamp(10px, 2.5vw, 16px);
    /* Separation: the old `border-b border-black/20` was a black hairline on a
       near-black surface, so the header read as part of the message list.
       A light hairline + soft drop shadow gives it real elevation. */
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 20px -16px rgba(0, 0, 0, 0.95);
}

/* Default dark theme only: a faint top sheen makes the bar read as its own
   raised surface. Skipped under AMOLED so pure black stays pure black. */
:root:not([data-theme="amoled"]) #chat-header {
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
}

#messages-container {
    overscroll-behavior: contain;
    overflow-anchor: none;
    padding: 10px clamp(8px, 2.4vw, 16px);
}

.message-row {
    width: min(100%, 760px);
    margin-left: auto;
    margin-right: auto;
    content-visibility: visible;
    contain-intrinsic-size: auto;
}

.message-row.message-row-grouped {
    margin-bottom: 0.35rem;
}

.message-day-row {
    width: min(100%, 760px);
    margin: 0.85rem auto 0.7rem;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.message-day-chip {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(23, 33, 43, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(244, 247, 251, 0.72);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.message-album {
    width: min(86vw, 40rem);
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0.55rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row dense;
    align-items: stretch;
    gap: 6px;
}

.message-album-3 .message-row-album-item:first-child {
    grid-column: span 2;
}

.message-row.message-row-album-item {
    width: auto;
    margin: 0;
    min-width: 0;
    display: block !important;
    content-visibility: visible;
    contain-intrinsic-size: auto;
}

.message-album .message-row {
    width: 100%;
    max-width: none;
    margin: 0;
    min-width: 0;
}

.message-album .msg-bubble {
    max-width: none;
}

.message-row.message-row-album-item .msg-bubble {
    width: 100%;
}

#chat-composer {
    padding:
        var(--composer-pad-y)
        calc(var(--composer-pad-x) + env(safe-area-inset-right, 0px))
        calc(var(--composer-pad-y) + var(--composer-safe-bottom, env(safe-area-inset-bottom, 0px)))
        calc(var(--composer-pad-x) + env(safe-area-inset-left, 0px));
}

/* Keyboard open: the system-nav inset that env() keeps reporting is already
   covered by the keyboard itself, so it must not lift the composer or a
   50-100px void appears above the keyboard. The class is toggled from JS
   (visualViewport shrink + focused text field); no hardcoded offsets. */
body.keyboard-open #chat-composer {
    --composer-safe-bottom: 0px;
}

#input-bar {
    gap: 8px;
    padding: 6px;
    border-radius: 6px;
    max-width: min(980px, 100%);
}

#input-extras {
    display: none;
}

#input-extras-popover {
    z-index: 95;
}

.category-dialog-panel {
    background:
        linear-gradient(180deg, rgba(23, 33, 43, 0.98), rgba(15, 23, 32, 0.98));
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.category-picker-item {
    border: 1px solid transparent;
}

.category-picker-item:hover,
.category-picker-item:focus-visible {
    border-color: rgba(90, 161, 227, 0.24);
    background: rgba(255, 255, 255, 0.05);
}

#toast-root {
    align-items: stretch;
}

.toast-card {
    pointer-events: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(23, 33, 43, 0.96);
    color: var(--tg-text);
    border-radius: 6px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    animation: slideUp 0.18s ease-out;
}

.toast-card.toast-success {
    border-color: rgba(34, 197, 94, 0.28);
}

.toast-card.toast-warning {
    border-color: rgba(245, 158, 11, 0.28);
}

.toast-card.toast-error {
    border-color: rgba(239, 68, 68, 0.28);
}

.toast-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 14px 10px;
}

.toast-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
}

.toast-success .toast-icon {
    color: #22c55e;
}

.toast-warning .toast-icon {
    color: #f59e0b;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-body {
    min-width: 0;
    flex: 1;
}

.toast-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.toast-message {
    margin-top: 4px;
    font-size: 12px;
    color: var(--tg-hint);
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.toast-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-hint);
    background: transparent;
    border: 0;
}

.toast-close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.toast-list {
    margin: 0;
    padding: 0 14px 14px 62px;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast-list li {
    font-size: 12px;
    color: #d8dee8;
    padding: 7px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    word-break: break-word;
}

.toast-actions {
    display: flex;
    gap: 8px;
    padding: 0 14px 14px 62px;
    flex-wrap: wrap;
}

.toast-action-btn {
    appearance: none;
    border: 1px solid rgba(90, 161, 227, 0.28);
    background: rgba(90, 161, 227, 0.16);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.toast-action-btn:hover {
    background: rgba(90, 161, 227, 0.24);
    border-color: rgba(90, 161, 227, 0.4);
}

.toast-action-btn.is-secondary {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
    color: #d8dee8;
}

.toast-action-btn.is-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.upload-placeholder-card {
    position: relative;
    overflow: hidden;
}

.upload-placeholder-card.is-active {
    border-color: rgba(90, 161, 227, 0.26);
    box-shadow: inset 0 0 0 1px rgba(90, 161, 227, 0.08);
}

.upload-placeholder-card.is-failed {
    border-color: rgba(239, 68, 68, 0.28);
}

.upload-placeholder-icon {
    position: relative;
}

.upload-placeholder-card.is-active .upload-placeholder-icon {
    animation: uploadPulse 1.3s ease-in-out infinite;
}

.upload-placeholder-meta {
    position: relative;
}

.upload-placeholder-sub {
    position: relative;
    z-index: 1;
}

.upload-placeholder-progress {
    position: relative;
    z-index: 1;
}

.upload-placeholder-progress-bar {
    background: linear-gradient(90deg, rgba(255,255,255,0.7), rgba(255,255,255,0.95));
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.16);
}

.upload-placeholder-shimmer {
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,0.05) 35%, rgba(255,255,255,0.14) 50%, rgba(255,255,255,0.05) 65%, transparent 100%);
    transform: translateX(-120%);
    animation: uploadShimmer 1.4s linear infinite;
    pointer-events: none;
}

.upload-placeholder-action i.fa-spinner {
    animation: placeholderSpin 0.85s linear infinite;
}

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

@keyframes uploadPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.92;
    }
    50% {
        transform: scale(1.08);
        opacity: 1;
    }
}

@keyframes uploadShimmer {
    0% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(120%);
    }
}

.debug-panel-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: #d8dee8;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}

.debug-panel-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.debug-entry {
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.debug-entry + .debug-entry {
    margin-top: 8px;
}

.debug-entry-head {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 4px;
}

.debug-entry-type {
    font-weight: 800;
    color: #8ad4ff;
}

.debug-entry-time {
    color: var(--tg-hint);
    margin-left: auto;
}

.debug-entry-body {
    color: #d8dee8;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

#action-sheet {
    transition: transform 0.16s ease-out;
}

#action-sheet .context-btn {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
}

#action-sheet .context-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

#focus-exit-btn {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#find-bar {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.find-scope-toggle {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.find-scope-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--tg-hint);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.find-scope-btn.is-active {
    background: rgba(90, 161, 227, 0.16);
    color: #fff;
}

.find-bar-btn {
    appearance: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: #d8dee8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.find-bar-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.filter-chip-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: #d8dee8;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.filter-chip-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.filter-chip-btn.is-active {
    background: rgba(245, 158, 11, 0.16);
    border-color: rgba(245, 158, 11, 0.34);
    color: #fff3c4;
}

.filter-chip-btn.is-primary {
    background: rgba(90, 161, 227, 0.18);
    border-color: rgba(90, 161, 227, 0.34);
    color: #fff;
}

.filter-chip-btn.is-primary:hover {
    background: rgba(90, 161, 227, 0.26);
}

.find-mark {
    background: rgba(245, 158, 11, 0.3);
    color: #fff4d4;
    border-radius: 4px;
    padding: 0 1px;
}

.find-mark-current {
    background: rgba(245, 158, 11, 0.95);
    color: #1a1206;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.9);
}

.message-row {
    scroll-margin-top: 90px;
    scroll-margin-bottom: 90px;
}

.message-row.find-current-match .msg-bubble {
    box-shadow:
        0 0 0 2px rgba(245, 158, 11, 0.75),
        0 10px 30px rgba(245, 158, 11, 0.14);
}

.message-row.message-row-jump-highlight .msg-bubble {
    box-shadow:
        0 0 0 2px rgba(90, 161, 227, 0.88),
        0 12px 28px rgba(90, 161, 227, 0.16);
}

#bulk-selection-bar,
#pinned-strip {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.bulk-selection-inner {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bulk-selection-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.message-row.is-bulk-selected .msg-bubble {
    box-shadow:
        0 0 0 2px rgba(90, 161, 227, 0.88),
        0 12px 28px rgba(90, 161, 227, 0.18);
}

body.bulk-selecting .message-row .msg-bubble {
    cursor: pointer;
}

.pinned-strip-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.82);
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

#pinned-strip-list {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

#pinned-strip-list::-webkit-scrollbar {
    display: none;
}

.pinned-chip {
    appearance: none;
    min-width: 0;
    max-width: min(72vw, 260px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.045);
    color: #eef4fb;
    padding: 8px 11px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    text-align: left;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    flex-shrink: 0;
}

.pinned-chip:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(90, 161, 227, 0.26);
}

.pinned-chip i {
    color: var(--tg-accent);
    flex-shrink: 0;
}

.pinned-chip-text {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.focus-mode #chat-header {
    display: none;
}

body.focus-mode #sidebar {
    transform: translateX(-100%) !important;
}

body.focus-mode #sidebar-overlay {
    opacity: 0 !important;
    pointer-events: none !important;
}

body.focus-mode #chat-main {
    padding-top: env(safe-area-inset-top, 0px);
}

body.focus-mode #messages-container {
    padding-top: 8px;
}

#input-extras-popover button {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
}

#input-extras-popover button:hover {
    background: rgba(255, 255, 255, 0.08);
}

#input-extras-btn,
#send-btn,
#attach-btn,
#attach-btn-popover,
#storage-toggle,
#telegram-toggle,
#upload-url-btn,
#storage-toggle-popover,
#telegram-toggle-popover,
#upload-url-btn-popover {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
}

#mobile-menu-btn,
#sidebar-close-btn,
#logout-btn,
#global-fullscreen-btn {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
}

#message-input {
    min-height: var(--touch-target);
    max-height: 7.5rem;
    font-size: 16px;
    line-height: 1.35;
    padding: 10px 8px;
}

#composer-meta-bar {
    padding-top: 8px;
    padding-bottom: 8px;
}

.composer-meta-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: rgba(90, 161, 227, 0.14);
    color: #dceeff;
    margin-bottom: 2px;
}

.msg-ref {
    width: 100%;
    padding: 7px 9px;
    border-left: 2px solid rgba(255, 255, 255, 0.22);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.045);
}

button.msg-ref {
    appearance: none;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    cursor: pointer;
    color: inherit;
    text-align: left;
}

button.msg-ref:hover {
    background: rgba(255, 255, 255, 0.08);
}

.msg-ref-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.82);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.msg-ref-text {
    margin-top: 3px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.68);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-state-icons {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 2px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 11px;
}

#jump-latest-btn {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#send-btn {
    background: rgba(90, 161, 227, 0.18);
    border: 1px solid rgba(90, 161, 227, 0.35);
}

#send-btn:hover {
    background: rgba(90, 161, 227, 0.28);
}

.msg-bubble {
    max-width: min(86vw, 40rem);
}

/* Glassmorphism Login */
.glass-panel {
    background: rgba(23, 33, 43, 0.9);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.09);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 5px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-enter {
    animation: slideUp 0.2s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}

/* Message Bubbles */
.msg-bubble {
    /* Auto width: shrinks to text, but capped by max-width */
    width: auto;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
    max-width: min(86vw, 40rem);
    padding: 8px 12px;
    border-radius: 6px;
    position: relative;
    /* A black shadow on a near-black surface is invisible — this pairs a tight
       contact shadow with a wider ambient one so bubbles read as raised. */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 5px 14px -8px rgba(0, 0, 0, 0.55);
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.4;
    text-align: left;
    word-break: break-word;
}

.msg-bubble.msg-group-start {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.msg-bubble.msg-group-middle {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.msg-bubble.msg-group-end {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.msg-bubble.msg-album-bubble {
    width: 100%;
    max-width: none;
    padding: 4px;
    gap: 4px;
    border-radius: 6px;
}

.msg-bubble p {
    margin: 0;
    white-space: pre-wrap;
}

.msg-text-wrap {
    position: relative;
    width: 100%;
}

.msg-text-wrap.is-collapsed {
    max-height: calc(1.4em * 8);
    overflow: hidden;
}

.msg-text-content {
    margin: 0;
    white-space: pre-wrap;
}

.msg-text-fade {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2.8em;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(23, 33, 43, 0.96));
    pointer-events: none;
}

.msg-in .msg-text-fade {
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.96));
}

.msg-text-toggle {
    appearance: none;
    border: 0;
    background: transparent;
    color: #8ec5ff;
    padding: 0;
    margin-top: 2px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.msg-text-toggle:hover {
    text-decoration: underline;
}

.msg-file {
    max-width: 340px;
}

@media (max-width: 640px) {
    .msg-file {
        max-width: 85%;
    }

    .message-row {
        width: 100%;
    }

    .message-album {
        width: 100%;
        gap: 5px;
    }

    .message-day-row {
        width: 100%;
        margin-top: 0.75rem;
    }
}

@media (min-width: 768px) {
    .msg-bubble {
        max-width: min(68%, 44rem);
    }

    .message-album {
        width: min(72%, 46rem);
    }
}

/* My Messages (Right) */
.msg-out {
    background-color: #17212B;
    color: white;
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.16);
}

/* Peer Messages (Left) */
.msg-in {
    background-color: rgb(0 0 0);
    color: white;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.msg-hidden {
    opacity: 0.55;
    filter: saturate(0.75);
}

/* Timestamp */
.msg-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    text-align: right;
}

.msg-time-main {
    color: rgba(255, 255, 255, 0.78);
}

.msg-time-date {
    color: rgba(255, 255, 255, 0.52);
}

.msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: flex-end;
    margin-left: 8px;
    margin-top: 2px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.msg-badges {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.msg-badge {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.msg-badge-local {
    background: rgba(255, 255, 255, 0.85);
}

.msg-badge-r2 {
    background: #22c55e;
}

.msg-badge-tg {
    background: #2AABEE;
}

.msg-category-badge {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    box-shadow: none;
    cursor: pointer;
}

/* Media Styling */
.media-container img,
.media-container video {
    border-radius: 6px;
    max-height: 350px;
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
    cursor: pointer;
    /* Indication it's clickable */
}

.file-card {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #ffffff;
    text-decoration: none;
    max-width: 100%;
}

.file-card:hover {
    background: rgba(0, 0, 0, 0.32);
}

.file-icon {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: var(--tg-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-meta {
    min-width: 0;
    flex: 1;
}

.file-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-sub {
    font-size: 11px;
    color: var(--tg-hint);
}

.file-action {
    color: var(--tg-hint);
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-container {
    position: relative;
}

.message-row-album-item .media-container {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 6px;
}

.message-row-album-item .media-container img,
.message-row-album-item .media-container video {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 6px;
}

.message-row-album-item .msg-meta {
    margin: 0 4px 2px auto;
}

.message-row-album-item .msg-bubble p {
    padding: 0 4px 4px;
    font-size: 13px;
}

.modal-nav-btn {
    position: absolute;
    top: 50%;
    z-index: 55;
    transform: translateY(-50%);
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.42);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background 0.18s ease, transform 0.18s ease;
}

#modal-stage {
    cursor: default;
    touch-action: pan-y;
}

#modal-stage.modal-stage-grouped {
    cursor: grab;
}

#modal-stage.modal-stage-grouped.is-dragging {
    cursor: grabbing;
}

.modal-nav-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

.modal-nav-prev {
    left: 16px;
}

.modal-nav-next {
    right: 16px;
}

/* iOS Safe Area for Input */
.pb-safe {
    padding-bottom: env(safe-area-inset-bottom, 10px);
}

/* Small screens: prioritize text input space */
@media (max-width: 640px) {
    #input-bar {
        gap: 7px;
        padding: 6px;
    }

    #message-input {
        padding-left: 4px;
        padding-right: 4px;
    }

    .modal-nav-btn {
        width: 42px;
        height: 42px;
    }

    .modal-nav-prev {
        left: 10px;
    }

    .modal-nav-next {
        right: 10px;
    }

}

@media (max-width: 640px) {
    #global-fullscreen-btn,
    #header-search-btn {
        display: none !important;
    }
}

@media (max-width: 480px) {
    :root {
        --sidebar-width: min(88vw, 320px);
    }

    #chat-header {
        gap: 10px;
    }

    #chat-header .ml-auto > a,
    #chat-header .ml-auto > button {
        width: 38px;
        height: 38px;
    }

    #messages-container {
        padding: 8px 8px 10px;
    }

    #input-extras-btn,
    #send-btn {
        min-width: 42px;
        min-height: 42px;
        width: 42px;
        height: 42px;
    }
}

@media (min-width: 1024px) {
    #input-extras {
        display: flex;
    }

    #input-extras-btn {
        display: none;
    }

    #input-extras-popover {
        display: none !important;
    }

    #message-input {
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .message-enter,
    .animate-bounce,
    .animate-pulse,
    .animate-scale-in {
        animation: none !important;
    }
}

.password-modal-panel {
    background: linear-gradient(180deg, rgba(23, 33, 43, 0.98), rgba(14, 20, 27, 0.98));
}

.password-generator-input {
    width: 100%;
    min-height: 104px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: #fff;
    border-radius: 6px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.45;
    resize: vertical;
}

.password-generator-input:focus {
    outline: none;
    border-color: rgba(90, 161, 227, 0.6);
    box-shadow: 0 0 0 2px rgba(90, 161, 227, 0.18);
}

#generator-mode-toggle {
    display: flex;
    flex-wrap: wrap;
}

.password-generator-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.password-strength-chip {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.14);
    color: #d8ffe7;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.password-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 180px;
    overflow-y: auto;
}

.password-history-item {
    appearance: none;
    width: 100%;
    text-align: left;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.035);
    color: #f3f7fb;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.4;
    word-break: break-all;
}

.password-history-item:hover {
    background: rgba(255, 255, 255, 0.07);
}

#delete-undo-bar {
    pointer-events: auto;
}

/* ---- Delete undo alerts: shadcn-sonner style, top-right ---- */
#delete-undo-bar:not(.hidden) {
    animation: toast-in-right 0.22s cubic-bezier(0.2, 0, 0.2, 1);
}
@keyframes toast-in-right {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

.delete-undo-item {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 3px solid rgba(239, 68, 68, 0.7);
    background: #17212b;
    color: #fff;
    border-radius: 6px;
    padding: 8px 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.delete-undo-head-icon,
.delete-undo-item-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background: rgba(239, 68, 68, 0.14);
    color: #fca5a5;
}

.delete-undo-title {
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.3;
    word-break: break-word;
}

.delete-undo-by {
    font-weight: 600;
    color: #9fb3c8;
    white-space: nowrap;
}
.delete-undo-by i {
    font-size: 10px;
    margin-right: 3px;
}

.delete-undo-remaining {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #8fa1b3;
    font-variant-numeric: tabular-nums;
}
.delete-undo-remaining i {
    font-size: 10px;
}

.delete-undo-undo-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    border-radius: 6px;
    padding: 7px 10px;
    background: rgba(90, 161, 227, 0.18);
    color: #dceeff;
    font-size: 12px;
    font-weight: 700;
}
.delete-undo-undo-btn i {
    font-size: 11px;
}

.delete-undo-dismiss-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.delete-undo-dismiss-btn:hover,
.delete-undo-undo-btn:hover {
    filter: brightness(1.08);
}

/* ---- Category top bar: collapsible quick navigation ---- */
#category-topbar-list {
    scrollbar-width: thin;
}
.cat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: #9aa4b2;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.12s, color 0.12s;
}
.cat-chip:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}
.cat-chip-active {
    background: rgba(90, 161, 227, 0.18);
    color: #dceeff;
}
.cat-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cat-star-ico {
    font-size: 10px;
}
.cat-chip-label {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cat-count {
    font-size: 10px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    padding: 1px 6px;
    font-variant-numeric: tabular-nums;
}
.cat-chip-active .cat-count {
    background: rgba(255, 255, 255, 0.14);
}

/* Context Menu */
.context-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 14px;
    color: white;
    transition: background-color 0.1s;
}

/* Desktop right-click menu: compact + never taller than the viewport. */
#context-menu:not(.hidden) {
    display: flex;
    flex-direction: column;
    max-height: min(72vh, 430px);
}
#context-menu > div {
    overflow-y: auto;
    min-height: 0;
}
#context-menu .context-btn {
    gap: 10px;
    padding: 7px 12px;
    font-size: 13px;
}
#context-menu .context-btn i {
    width: 18px;
    font-size: 14px;
}

.context-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.context-btn i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    opacity: 0.8;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animate-scale-in {
    animation: scaleIn 0.1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Media Modal */
.modal-backdrop {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
}

.modal-content {
    max-width: 95vw;
    max-height: 85vh;
    object-fit: contain;
    transition: transform 0.2s ease-out;
}

.modal-counter {
    position: absolute;
    top: 18px;
    left: 50%;
    z-index: 55;
    transform: translateX(-50%);
    min-width: 64px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.38);
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-carousel {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.24s ease;
    will-change: transform;
}

.modal-carousel.dragging {
    transition: none;
}

.modal-slide {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 72px 92px;
    box-sizing: border-box;
    user-select: none;
}

.modal-slide img {
    max-width: 95vw;
    max-height: 85vh;
    object-fit: contain;
    transition: transform 0.2s ease-out;
    user-select: none;
    -webkit-user-drag: none;
}

.zoom-controls {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
    z-index: 50;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@media (max-width: 640px) {
    .modal-slide {
        padding: 16px 56px 88px;
    }

    .pinned-strip-label {
        display: none;
    }

    .pinned-chip {
        max-width: 72vw;
        padding: 7px 10px;
    }

    .filter-chip-btn {
        min-height: 34px;
        padding: 7px 10px;
    }

    .bulk-selection-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .bulk-selection-actions {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .bulk-selection-actions::-webkit-scrollbar {
        display: none;
    }

    .bulk-selection-actions .filter-chip-btn {
        min-width: max-content;
    }

    #generator-mode-toggle {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    #generator-mode-toggle::-webkit-scrollbar {
        display: none;
    }
}

/* Background image tuning */
.chat-bg {
    background-image:
        radial-gradient(circle at 20% 10%, rgba(90, 161, 227, 0.35), transparent 45%),
        radial-gradient(circle at 80% 0%, rgba(143, 160, 178, 0.18), transparent 40%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
        linear-gradient(225deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
        linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
        linear-gradient(315deg, rgba(255, 255, 255, 0.08) 25%, rgba(0, 0, 0, 0) 25%);
    background-position: 0 0, 0 0, 12px 0, 12px 0, 0 0, 0 0;
    background-size: auto, auto, 24px 24px, 24px 24px, 24px 24px, 24px 24px;
    filter: saturate(0.8) brightness(0.9);
}

/* Image Studio - Strict Split Screen Redesign */
.image-editor-modal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2000 !important;
    background: #0a0f16 !important;
    display: flex;
    overflow: hidden;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.image-editor-shell {
    width: 100%;
    height: 100%;
}

.image-editor-main {
    display: flex;
    width: 100%;
    height: 100%;
    flex-direction: column; /* Mobile Default */
}

@media (min-width: 1024px) {
    .image-editor-main {
        flex-direction: row; /* Desktop Split */
    }
}

/* LEFT SIDE: STAGE */
.image-editor-stage {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    min-height: 0;
}

@media (max-width: 1023px) {
    .image-editor-stage {
        height: 45vh;
        flex: none;
    }
}

#image-editor-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
}

/* RIGHT SIDE: SIDEBAR */
.image-editor-controls-sidebar {
    width: 100%;
    background: #131e28;
    border-left: 1px solid #2a3948;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 20;
}

@media (min-width: 1024px) {
    .image-editor-controls-sidebar {
        width: 400px;
        height: 100%;
    }
}

@media (max-width: 1023px) {
    .image-editor-controls-sidebar {
        flex: 1;
        border-left: 0;
        border-top: 1px solid #2a3948;
    }
}

.sidebar-section {
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-label {
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    color: #5aa1e3;
    letter-spacing: 0.1em;
    margin-bottom: 16px;
    display: block;
}

.settings-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 12px;
}

/* TOOLS GRID */
.image-editor-tools-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.nav-item {
    appearance: none;
    border: 0;
    background: rgba(255, 255, 255, 0.03);
    color: rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-item i { font-size: 18px; }
.nav-item span { font-size: 9px; font-weight: 800; text-transform: uppercase; }

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-item.is-active {
    background: #5aa1e3;
    color: #fff;
    box-shadow: 0 4px 12px rgba(90, 161, 227, 0.3);
}

/* BUTTONS */
.image-editor-close-btn {
    appearance: none;
    border: 0;
    background: rgba(255, 87, 87, 0.1);
    color: #ff6b6b;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
}

.image-editor-close-btn:hover {
    background: #ff5757;
    color: #fff;
}

.image-editor-ghost-btn {
    appearance: none;
    border: 0;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.image-editor-ghost-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.image-editor-primary-btn {
    appearance: none;
    border: 0;
    background: #5aa1e3;
    color: #fff;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(90, 161, 227, 0.2);
}

.image-editor-primary-btn:hover {
    background: #7bbff5;
    transform: translateY(-1px);
}

/* SETTINGS COMPONENTS */
.image-editor-chip {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-editor-chip:hover { background: rgba(255, 255, 255, 0.08); }
.image-editor-chip.is-active { background: #5aa1e3; border-color: #5aa1e3; color: #fff; }

.image-editor-button-row { display: flex; gap: 8px; }

.image-editor-select {
    background: #1a2635;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

/* SLIDERS */
.slider-group { display: flex; flex-direction: column; gap: 8px; }
.slider-group label { font-size: 10px; font-weight: 700; color: rgba(255, 255, 255, 0.5); text-transform: uppercase; }

input[type="range"] {
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    background: #fff;
    border: 4px solid #5aa1e3;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* SETTINGS CARDS VISIBILITY */
.floating-settings-panel { display: block; }
.settings-card { display: none; }

.image-editor-shell[class*="tool-"] .settings-card[data-editor-section="shared"] { display: none; } /* Default hide shared */

/* Logic to show correct cards based on shell class (managed by JS) */
.tool-crop .settings-card[data-editor-section="crop"],
.tool-crop .settings-card[data-editor-section="shared"],
.tool-adjust .settings-card[data-editor-section="adjust"],
.tool-draw .settings-card[data-editor-section="draw"],
.tool-text .settings-card[data-editor-section="text"],
.tool-text .settings-card[data-editor-section="layers"],
.tool-design .settings-card[data-editor-section="design"],
.tool-design .settings-card[data-editor-section="layers"] {
    display: block;
    animation: sidebarFadeIn 0.3s ease;
}

@keyframes sidebarFadeIn {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* LAYERS */
.image-editor-layer-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
}

.image-editor-layer-row.is-selected {
    background: rgba(90, 161, 227, 0.15);
    border-color: #5aa1e3;
}

.image-editor-layer-main { flex: 1; display: flex; align-items: center; gap: 10px; color: #fff; font-size: 13px; font-weight: 600; }
.image-editor-layer-icon { width: 32px; height: 32px; background: rgba(255,255,255,0.05); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* CROP OVERLAY */
.image-editor-crop-overlay, .image-editor-text-layer { position: absolute; inset: 0; pointer-events: none; }
.image-editor-crop-box { position: absolute; pointer-events: auto; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,0.7); cursor: move; }
.image-editor-crop-handle { position: absolute; width: 28px; height: 28px; background: #fff; border: 4px solid #5aa1e3; border-radius: 50%; pointer-events: auto; }
.handle-nw { top: -14px; left: -14px; cursor: nw-resize; }
.handle-ne { top: -14px; right: -14px; cursor: ne-resize; }
.handle-sw { bottom: -14px; left: -14px; cursor: sw-resize; }
.handle-se { bottom: -14px; right: -14px; cursor: se-resize; }

.image-editor-stage-layer {
    position: absolute;
    transform-origin: center;
    cursor: move;
    pointer-events: auto;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.image-editor-stage-layer.is-selected {
    outline: 2px solid #5aa1e3;
    outline-offset: 4px;
}

/* =====================================================================
   CHAT UI REDESIGN — layout, spacing & hierarchy only.
   Palette and type are untouched. ID-scoped selectors outrank utilities
   so rhythm is controlled here, not by space-y/mb mixes.
   ===================================================================== */

/* ---- 1. Message rhythm: own the gaps, kill the space-y + mb double gap ---- */
#messages-container > :not([hidden]) ~ :not([hidden]) {
    margin-top: 0;
}
#messages-container .message-row {
    margin-bottom: 12px;
}
#messages-container .message-row.message-row-grouped {
    margin-bottom: 4px;
}
#messages-container .message-day-row {
    margin: 16px auto 12px;
}
#messages-container #load-more-row {
    margin: 4px auto 12px;
}

/* ---- 2. Day separators scroll with history (sticky made day chips
   stack/overlap each other at the same top offset while scrolling) ---- */
#messages-container .message-day-row {
    position: static;
}

/* ---- 3. Bubbles: a touch roomier, meta cleanly separated, clearer quotes ---- */
.msg-bubble {
    padding: 9px 13px;
    border-radius: 6px;
}
.msg-meta {
    margin-top: 4px;
}
.msg-ref {
    border-left-width: 3px;
}

/* ---- 4. Composer: send button wakes up when there is text to send ---- */
#message-input:not(:placeholder-shown) ~ #send-btn {
    transform: scale(1.08);
}
#chat-composer #send-btn:active {
    transform: scale(0.94);
}
#composer-cat-chip {
    margin-bottom: 6px;
    align-self: center;
}
#composer-meta-bar {
    margin-bottom: 8px;
}

/* ---- 5. Header: breathe on small screens without losing any action ---- */
@media (max-width: 640px) {
    #chat-header {
        gap: 8px;
    }
    #chat-header .ml-auto {
        gap: 2px;
    }
    #chat-header .text-xs.text-tg-hint {
        display: none;
    }
}

/* ---- 6. Sidebar: labeled action tiles instead of mystery icons ---- */
#sidebar .grid > button,
#sidebar .grid > a {
    flex-direction: column;
    gap: 5px;
    height: auto;
    min-height: 60px;
    padding-top: 10px;
    padding-bottom: 8px;
}
.action-tile-label {
    font-size: 10px;
    line-height: 1.25;
    font-weight: 600;
    white-space: nowrap;
}

/* ---- 7. Category filter: comfortable touch targets ---- */
#category-filter-list > button {
    min-height: 36px;
}

/* ---- 8. Login card never clips on short screens ---- */
#login-view .glass-panel {
    max-height: calc(var(--app-vh) - 32px);
    overflow-y: auto;
}

/* ---- 9. Bubble tails on standalone messages (grouped/album rows excluded) ---- */
#messages-container .message-row:not(.message-row-grouped):not(.message-row-album-item) > .msg-out:not(.msg-album-bubble)::after,
#messages-container .message-row:not(.message-row-grouped):not(.message-row-album-item) > .msg-in:not(.msg-album-bubble)::after {
    content: '';
    position: absolute;
    bottom: -1px;
    width: 0;
    height: 0;
}
#messages-container .message-row:not(.message-row-grouped):not(.message-row-album-item) > .msg-out:not(.msg-album-bubble)::after {
    right: -6px;
    border-left: 7px solid #17212B;
    border-bottom: 7px solid transparent;
}
#messages-container .message-row:not(.message-row-grouped):not(.message-row-album-item) > .msg-in:not(.msg-album-bubble)::after {
    left: -6px;
    border-right: 7px solid rgb(0, 0, 0);
    border-bottom: 7px solid transparent;
}

/* ---- 10. Swipe-to-reply/copy progress hint (revealed as the bubble slides) ---- */
.swipe-hint {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.07);
    color: #d8dee8;
    font-size: 14px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 0;
}
.swipe-hint.show {
    opacity: 1;
}
.swipe-hint.side-left {
    left: 6px;
}
.swipe-hint.side-right {
    right: 6px;
}

/* ---- 11. Compact mode: denser rows/bubbles, wider column (body.compact) ---- */
body.compact #messages-container .message-row {
    margin-bottom: 6px;
}
body.compact #messages-container .message-row.message-row-grouped {
    margin-bottom: 2px;
}
body.compact .msg-bubble {
    padding: 6px 10px;
    gap: 4px;
}
body.compact #messages-container .message-row {
    width: min(100%, 860px);
}
body.compact .msg-bubble {
    max-width: min(88vw, 44rem);
}
@media (min-width: 768px) {
    body.compact .msg-bubble {
        max-width: min(76%, 48rem);
    }
}
body.compact #messages-container .message-day-row {
    margin: 10px auto 8px;
}
body.compact .media-container img,
body.compact .media-container video {
    max-height: 220px;
}

/* ---- 12. Composer refresh (layout only): roomier bar, taller field ---- */
#input-bar {
    border-radius: 6px;
    padding: 8px;
    gap: 8px;
}
#message-input {
    min-height: 46px;
}
#composer-meta-bar {
    margin-bottom: 8px;
}

/* ==========================================================================
   AMOLED theme — true black. Opt-in via <html data-theme="amoled">.
   Overrides three layers that would otherwise stay dark-grey:
     1. the --tg-* custom properties,
     2. Tailwind's generated tg-* color classes (hex-baked by the CDN config),
     3. Tailwind arbitrary-value classes like bg-[#17212B]/95 used in markup.
   Pure black (#000) for page + panels; structure comes from hairline borders.
   ========================================================================== */
[data-theme="amoled"] {
    --tg-bg: #000000;
    --tg-secondary: #000000;
    --tg-accent: #4F9DFF;              /* brighter so it reads on pure black */
    --tg-bubble-out: #0A0A0A;
    --tg-bubble-in: #000000;
    --tg-bubble-out-border: rgba(255, 255, 255, 0.22);
    --tg-bubble-in-border: rgba(255, 255, 255, 0.18);
    --tg-text: #F2F2F2;
    --tg-hint: #9AA0A6;
    --tg-border: #1A1A1A;
    --tg-ambient-1: none;              /* no blue glow — kills the grey lift */
    --tg-ambient-2: none;
}

[data-theme="amoled"] body {
    background-color: #000;
    background-image: none;
}

/* (2) Tailwind tg-* color utilities — baked hex, so override by class. */
[data-theme="amoled"] .bg-tg-bg,
[data-theme="amoled"] .bg-tg-secondary,
[data-theme="amoled"] .bg-tg-input { background-color: #000 !important; }
[data-theme="amoled"] .text-tg-hint { color: #9AA0A6 !important; }
[data-theme="amoled"] .text-tg-accent { color: #4F9DFF !important; }
[data-theme="amoled"] .border-tg-accent\/50 { border-color: rgba(79, 157, 255, 0.5) !important; }
[data-theme="amoled"] .bg-tg-accent\/15 { background-color: rgba(79, 157, 255, 0.15) !important; }
[data-theme="amoled"] .bg-tg-accent\/10 { background-color: rgba(79, 157, 255, 0.10) !important; }

/* (3) Arbitrary-value surfaces used inline in index.html. Both hex cases. */
[data-theme="amoled"] .bg-\[\#0F0F0F\],
[data-theme="amoled"] .bg-\[\#0F0F0F\]\/90,
[data-theme="amoled"] .bg-\[\#0f1720\],
[data-theme="amoled"] .bg-\[\#0f1720\]\/96,
[data-theme="amoled"] .bg-\[\#17212B\],
[data-theme="amoled"] .bg-\[\#17212B\]\/90,
[data-theme="amoled"] .bg-\[\#17212B\]\/95,
[data-theme="amoled"] .bg-\[\#17212B\]\/96,
[data-theme="amoled"] .bg-\[\#17212B\]\/97,
[data-theme="amoled"] .bg-\[\#111923\],
[data-theme="amoled"] .bg-\[\#111827\],
[data-theme="amoled"] .bg-\[\#101821\]\/60,
[data-theme="amoled"] .bg-\[\#101821\]\/88,
[data-theme="amoled"] .bg-\[\#101821\]\/92 { background-color: #000 !important; }

/* Chat wallpaper: the white grid lines glare on pure black — flatten it. */
[data-theme="amoled"] .chat-bg {
    background-image: none;
    filter: none;
    opacity: 0 !important;
}

/* Hairlines instead of fills, so panels stay separable on black. */
[data-theme="amoled"] .border-white\/8,
[data-theme="amoled"] .border-white\/10 { border-color: #1A1A1A !important; }
[data-theme="amoled"] .border-gray-800\/60 { border-color: #1A1A1A !important; }
[data-theme="amoled"] .bg-white\/5 { background-color: rgba(255, 255, 255, 0.04) !important; }
[data-theme="amoled"] .bg-white\/10 { background-color: rgba(255, 255, 255, 0.07) !important; }

/* Modals / menus: opaque black, no translucent grey wash. */
[data-theme="amoled"] #context-menu,
[data-theme="amoled"] #message-actions-sheet,
[data-theme="amoled"] #input-extras-popover,
[data-theme="amoled"] #category-dropdown,
[data-theme="amoled"] .modal-card,
[data-theme="amoled"] .category-dialog-panel,
[data-theme="amoled"] #debug-panel,
[data-theme="amoled"] #find-bar { background-color: #000 !important; }

/* Delete-undo sonar cards + toasts. */
[data-theme="amoled"] .delete-undo-item,
[data-theme="amoled"] #delete-undo-bar > div { background-color: #000 !important; }

/* Theme toggle button in the header. */
#theme-toggle-btn.is-amoled { color: #4F9DFF; background-color: rgba(79, 157, 255, 0.10); }

/* ==========================================================================
   Tighter radii — 6px cap.
   Tailwind is loaded from the CDN and injects its stylesheet after this file,
   so these need !important to win. Genuine circles (rounded-full) and pill
   shapes (999px in the rules above) are intentionally left alone.
   ========================================================================== */
.rounded-lg,
.rounded-xl,
.rounded-2xl,
.rounded-3xl { border-radius: 6px !important; }

.rounded-t {
    border-top-left-radius: 6px !important;
    border-top-right-radius: 6px !important;
}
.rounded-b {
    border-bottom-left-radius: 6px !important;
    border-bottom-right-radius: 6px !important;
}
.rounded-l {
    border-top-left-radius: 6px !important;
    border-bottom-left-radius: 6px !important;
}
.rounded-r {
    border-top-right-radius: 6px !important;
    border-bottom-right-radius: 6px !important;
}
