/* ── Feedback Admin - clean minimal, no dependencies ── */

/* Native cross-page transition (fade/cross-fade on navigate + back) where supported */
@view-transition { navigation: auto; }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* Author display:flex/inline-flex rules override the browser's default
   [hidden]{display:none} regardless of specificity - restore it explicitly
   wherever an element with a forced display type can also be hidden. */
[hidden] { display: none !important; }

/* ── Индикация за зареждане (лента отгоре + спинър в бутон) ── */
#page-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--sky);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
}
button.is-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}
button.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(127,127,127,.3);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
button[type="submit"].is-loading::after,
.btn-danger.is-loading::after {
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.fade-up { animation: fadeUp .35s ease both; }

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

:root {
    --navy:      #0b1220;
    --navy-soft: #16213a;
    --sky:       #38bdf8;
    --text:      #1e293b;
    --muted:     #64748b;
    --border:    #e2e8f0;
    --bg:        #f6f8fb;
    --card:      #ffffff;
    --red:        #dc2626;
    --green:      #16a34a;
    --orange:     #d97706;
    --blue:       #2563eb;
    --gray:       #64748b;
    --nav-accent: #3b82f6;
    --nav-height: 56px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    animation: fadeIn .25s ease both;
}
/* Докато модал или лайтбокс е отворен - страницата отдолу не бива да скролва. */
body.scroll-locked { overflow: hidden; }

a { color: var(--blue); text-decoration: none; }

.icon { width: 17px; height: 17px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }

.muted { color: var(--muted); }
.anon  { color: var(--muted); font-style: italic; }

/* Metallic silver plate - same in both themes, per the logo's own artwork */
.login-logo {
    background: linear-gradient(150deg, #f4f5f6 0%, #d7d9dc 45%, #eef0f1 100%);
    border: 1px solid rgba(0,0,0,.08);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow:
        0 1px 3px rgba(0,0,0,.18),
        inset 0 1px 1px rgba(255,255,255,.9),
        inset 0 -1px 2px rgba(0,0,0,.15);
}

/* ── Долна навигация (заменя старата горна лента) ── */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--nav-height);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 0 16px calc(env(safe-area-inset-bottom));
    box-shadow: 0 -2px 4px rgba(0,0,0,.06), 0 -8px 20px rgba(0,0,0,.06);
    box-sizing: content-box;
}
:root[data-theme="dark"] .bottom-nav { box-shadow: 0 -2px 4px rgba(0,0,0,.4), 0 -8px 24px rgba(0,0,0,.35); }
.bottom-nav-left,
.bottom-nav-right { display: flex; align-items: center; gap: 6px; }
.bottom-nav-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 10px 16px;
    border-radius: 10px;
    touch-action: manipulation;
    transition: transform .1s, background .1s, color .1s, box-shadow .15s;
}
/* Сиянието е върху самата икона (drop-shadow), не box-shadow върху целия
   линк-контейнер - той е прозрачен без фон, box-shadow там изглежда като
   странен светещ правоъгълник вместо сияние около иконата. */
.bottom-nav-item:active { transform: scale(.88); }
.bottom-nav-item:active .icon { filter: drop-shadow(0 0 4px rgba(59,130,246,1)) drop-shadow(0 0 12px rgba(59,130,246,.9)); }
.bottom-nav-item.active { color: var(--nav-accent); }
.bottom-nav-item.active .icon { filter: drop-shadow(0 0 3px rgba(59,130,246,1)) drop-shadow(0 0 9px rgba(59,130,246,.8)); }
.nav-icon-wrap { position: relative; display: inline-flex; }
.nav-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    padding: 3px 5px;
    min-width: 15px;
    text-align: center;
}

/* Допълнително долно отстояние, за да не пада съдържанието зад bottom-nav */
.container-with-nav { padding-bottom: 90px; }

/* ── Плъзгащ се панел отляво (детайл/настройки) - на цяла ширина, спира
   над долната навигация, за да остане тя видима и достъпна ── */
.side-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
    background: rgba(0,0,0,.5);
    z-index: 45;
    opacity: 0;
    transition: opacity .25s ease;
}
.side-panel-overlay.open { opacity: 1; }
.side-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
    width: 100%;
    background: var(--bg);
    z-index: 46;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.2,.8,.2,1);
    box-shadow: 8px 0 30px rgba(0,0,0,.3);
    padding: 20px 16px 20px;
}
.side-panel.open { transform: translateX(0); }

.back-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    background: none;
    border: none;
    padding: 4px;
    margin-bottom: 12px;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s, background .1s;
}
.back-link:active { transform: scale(.85); background: rgba(0,0,0,.06); }
:root[data-theme="dark"] .back-link:active { background: rgba(255,255,255,.08); }
.back-link .icon { width: 22px; height: 22px; }

/* ── Layout ── */
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.filter-selects {
    display: flex;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
}
.filter-bar select {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    font-size: 13px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.05);
    text-overflow: ellipsis;
    touch-action: manipulation;
    transition: transform .1s;
}
.filter-bar select:active { transform: scale(.98); }
.filter-clear {
    font-size: 13px;
    touch-action: manipulation;
    transition: transform .1s;
    display: inline-block;
}
.filter-clear:active { transform: scale(.92); }
.filter-count { margin-left: auto; font-size: 13px; color: var(--muted); }

/* ── Feedback card list (no horizontal scroll on any screen) ── */
.feedback-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.list-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.list-divider::before,
.list-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}
.fb-card {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    text-decoration: none;
    box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 10px 24px rgba(0,0,0,.08);
    touch-action: manipulation;
    transition: transform .1s, box-shadow .15s, background .1s;
}
.fb-card:active { transform: scale(.98); box-shadow: inset 0 1px 4px rgba(0,0,0,.12); }
:root[data-theme="dark"] .fb-card { box-shadow: 0 4px 14px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4); }
:root[data-theme="dark"] .fb-card:active { box-shadow: inset 0 1px 4px rgba(0,0,0,.4); }
.fb-card-new { border-left-color: var(--sky); }
/* Клиентът е писал последен - чака отговор от нас, различимо от "new". */
.fb-card-awaiting { border-left-color: var(--orange); }
.fb-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.fb-card-top-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cat-chip-sm { font-size: 12px; padding: 2px 10px; }
.brand-icon { width: 15px; height: 15px; flex-shrink: 0; fill: var(--muted); }
.brand-icon-android { fill: #3ddc84; }
.fb-card-msg {
    font-size: 14px;
    color: var(--text);
    word-break: break-word;
    margin-bottom: 6px;
}
.fb-card-new .fb-card-msg { font-weight: 600; }
.fb-card-meta {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.fb-dot { opacity: .6; }
.meta-icon { display: inline-flex; align-items: center; gap: 3px; }
.meta-icon-reply { color: var(--green); }
.meta-icon-awaiting { color: var(--orange); font-weight: 700; }

/* ── Status badges ── */
.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 10px;
    white-space: nowrap;
}
.badge-new         { background: #f1f5f9; color: var(--gray);   border: 1px solid #cbd5e1; }
.badge-seen        { background: #dbeafe; color: var(--blue);   }
.badge-in_progress { background: #fef3c7; color: var(--orange); }
.badge-resolved    { background: #dcfce7; color: var(--green);  }

.empty-state {
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
}

/* ── Alerts ── */
.alert {
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error   { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ── Cards / detail ── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,.07), 0 12px 28px rgba(0,0,0,.09);
    animation: fadeUp .3s ease both;
}
:root[data-theme="dark"] .card { box-shadow: 0 4px 16px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.03); }
.card:nth-of-type(1) { animation-delay: 0ms; }
.card:nth-of-type(2) { animation-delay: 50ms; }
.card:nth-of-type(3) { animation-delay: 100ms; }
.card:nth-of-type(4) { animation-delay: 150ms; }
.card h2 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    margin-bottom: 12px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
    align-items: start;
}
.card-sticky { position: sticky; top: 16px; }
/* Панелът е тесен по дизайн, независимо от viewport ширината - винаги
   една колонка вътре в него, а не 2-колонния desktop изглед. */
.side-panel .detail-grid { grid-template-columns: 1fr; }
.side-panel .card-sticky { position: static; }

.detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.cat-chip {
    background: var(--border);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    padding: 4px 12px;
}

.meta-list { display: grid; grid-template-columns: 130px 1fr; row-gap: 8px; font-size: 14px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { word-break: break-word; }
.device-list { grid-template-columns: 170px 1fr; }

.device-highlight {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.device-highlight-item {
    flex: 1 1 160px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.device-highlight-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
}
.device-highlight-value { font-size: 16px; font-weight: 700; word-break: break-word; }

.ua-raw { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.ua-raw summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.ua-raw-text {
    margin-top: 8px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
    word-break: break-word;
    white-space: pre-wrap;
}

.message-text { white-space: pre-wrap; word-break: break-word; }

/* ── Media ── */
.media-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.media-thumb {
    display: inline-block;
    touch-action: manipulation;
    transition: transform .1s;
}
.media-thumb:active { transform: scale(.95); }
.media-thumb img {
    width: 130px;
    height: 130px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    display: block;
}
.media-video {
    max-width: 100%;
    width: 280px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #000;
}

/* ── Forms ── */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
label:first-of-type { margin-top: 0; }
select, textarea, input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.06);
    transition: box-shadow .15s, border-color .15s;
}
textarea { resize: vertical; }
select:focus, textarea:focus, input:focus {
    outline: 2px solid var(--sky);
    outline-offset: -1px;
    border-color: var(--sky);
}
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] input[type="password"] { box-shadow: inset 0 1px 4px rgba(0,0,0,.3); }
button[type="submit"] {
    width: 100%;
    margin-top: 14px;
    background: var(--navy);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.08), 0 0 14px rgba(59,130,246,.35);
    touch-action: manipulation;
    transition: transform .1s, box-shadow .1s, background .15s;
}
/* В тъмна тема --navy вече е почти черен (колора на логото), еднакъв с фона
   на страницата - бутонът изчезваше, оставаше само сиянието. Затова тук
   ползваме синия акцент вместо --navy - и по-светло сияние, защото
   тъмносиньото сияние се сливаше с плътния син фон на самия бутон. */
:root[data-theme="dark"] button[type="submit"] {
    background: var(--nav-accent);
    box-shadow: 0 2px 6px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.15), 0 0 22px rgba(147,197,253,.7);
}
button[type="submit"]:active { transform: scale(.98); box-shadow: inset 0 2px 4px rgba(0,0,0,.3), 0 0 20px rgba(59,130,246,.6); }
:root[data-theme="dark"] button[type="submit"]:active { box-shadow: inset 0 2px 4px rgba(0,0,0,.3), 0 0 26px rgba(147,197,253,.85); }

/* ── Danger zone (delete) ── */
.btn-danger-outline {
    width: 100%;
    margin-top: 20px;
    padding: 11px;
    background: transparent;
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s, background .15s, box-shadow .15s;
}
.btn-danger-outline:active { transform: scale(.98); box-shadow: 0 0 18px rgba(220,38,38,.4); }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
    animation: fadeIn .15s ease both;
}
.modal-box {
    background: var(--card);
    border-radius: 14px;
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
    animation: fadeUp .2s ease both;
}
.modal-box h3 { font-size: 17px; margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions form { display: flex; flex: 1; }
/* button.btn-X (не само .btn-X) - за да надвие по специфичност
   генеричния button[type="submit"] (navy фон, margin-top, различен padding). */
button.btn-secondary,
button.btn-danger {
    width: 100%;
    margin: 0;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s, box-shadow .15s;
    box-shadow: none;
}
button.btn-secondary:active { transform: scale(.96); box-shadow: none; }
button.btn-danger:active { transform: scale(.96); box-shadow: 0 0 20px rgba(220,38,38,.6); }
button.btn-secondary {
    flex: 1;
    background: var(--border);
    border: 1px solid var(--border);
    color: var(--text);
}
button.btn-danger {
    background: var(--red);
    border: none;
    color: #fff;
    box-shadow: 0 0 14px rgba(220,38,38,.4);
}

/* ── Reply history ── */
.note-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}
.note-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--sky);
    border-radius: 8px;
    padding: 8px 10px;
}
.note-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.note-stamp { font-size: 12px; color: var(--muted); }
.note-text  { font-size: 14px; white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.note-edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(59,130,246,.12);
    border: none;
    padding: 5px;
    border-radius: 7px;
    color: var(--nav-accent);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s;
    flex-shrink: 0;
}
.note-edit-btn:active { transform: scale(.85); background: rgba(59,130,246,.22); }
.note-edit-form { margin-top: 8px; }
.note-edit-form textarea {
    width: 100%;
    font-size: 13px;
    padding: 6px 8px;
    resize: none;
    overflow: hidden;
}
.note-edit-actions { display: flex; gap: 8px; margin-top: 6px; }
/* button.note-X (не само .note-X) - за да надвие по специфичност
   генеричния button[type="submit"] (navy фон, margin-top, различен padding). */
button.note-save-btn,
button.note-cancel-btn {
    flex: 1;
    width: auto;
    margin: 0;
    padding: 7px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: none;
}
button.note-save-btn { background: var(--navy); color: #fff; border: none; }
:root[data-theme="dark"] button.note-save-btn { background: var(--nav-accent); }
button.note-cancel-btn { background: var(--border); color: var(--text); border: 1px solid var(--border); }

/* ── Chat thread (app_feedback_replies) ── */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}
.chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.4;
}
.chat-bubble-client {
    align-self: flex-start;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-bubble-admin {
    align-self: flex-end;
    background: var(--nav-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-bubble-text { white-space: pre-wrap; word-break: break-word; }
.chat-bubble-media {
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
    display: block;
    margin-bottom: 4px;
}
.chat-media-wrap {
    position: relative;
    display: block;
    cursor: pointer;
    touch-action: manipulation;
}
.chat-media-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: rgba(0,0,0,.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.chat-media-play svg { width: 20px; height: 20px; margin-left: 2px; }

/* ── Лайтбокс за снимки/видео от разговора (js/lightbox.js) ──
   .open се добавя един кадър след hidden=false (виж requestAnimationFrame в
   lightbox.js), за да прихване transition-а, а не да скочи направо в крайно
   състояние - същия трик като .side-panel.open. */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    transition: opacity .2s ease;
}
.lightbox-overlay.open { opacity: 1; }
.lightbox-content {
    max-width: 100%;
    max-height: 100%;
    transform: scale(.9);
    transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.lightbox-overlay.open .lightbox-content { transform: scale(1); }
.lightbox-content img,
.lightbox-content video {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
}
.lightbox-close {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    z-index: 201;
    transition: transform .1s, background .1s;
}
.lightbox-close:active { transform: scale(.9); background: rgba(255,255,255,.25); }
.lightbox-close svg { width: 20px; height: 20px; }
.chat-bubble-time {
    font-size: 10px;
    opacity: .7;
    margin-top: 4px;
    text-align: right;
}

.composer-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 999px;
    background: var(--border);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s;
}
.composer-attach-btn:active { transform: scale(.9); }

/* ── Бутонът "Разговор" в детайла - отваря пълноекранния изглед thread.php ── */
.thread-open-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s, background .1s;
}
.thread-open-btn:active { transform: scale(.98); background: var(--border); }
.thread-open-btn .icon { color: var(--nav-accent); flex-shrink: 0; }
.thread-open-btn span { flex: 1; text-align: left; }
.thread-open-arrow { color: var(--muted); flex-shrink: 0; }

/* ── Пълноекранен изглед на разговора (thread.php) - фиксиран хедър горе,
   скролващи се съобщения в средата, композитор фиксиран долу. Панелът
   превключва в този flex режим само докато разговорът е отворен вътре в
   него (виж panel.classList.add('panel-thread') в app-shell.js). ── */
.side-panel.panel-thread {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
/* #side-panel-content седи между .side-panel и .thread-view - трябва и то да
   участва в тази flex верига, иначе height:100% на .thread-view няма от
   какво да се смята. */
.side-panel.panel-thread #side-panel-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
body.thread-standalone {
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.thread-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.thread-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--border);
}
.thread-header .back-link { margin-bottom: 0; flex-shrink: 0; }
.thread-header-text { min-width: 0; }
.thread-header-text h1 { font-size: 16px; font-weight: 700; margin: 0; }
.thread-sub {
    font-size: 12px;
    color: var(--muted);
    margin: 2px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-view .chat-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
    margin-bottom: 0;
}
.thread-empty { text-align: center; margin-top: 30px; }
.chat-bubble-legacy { position: relative; }
.chat-bubble-legacy .note-item-head { position: absolute; top: 4px; right: 6px; }
.chat-bubble-legacy .note-edit-btn { background: rgba(255,255,255,.18); color: #fff; }
.chat-bubble-legacy .note-edit-btn:active { background: rgba(255,255,255,.3); }
.chat-bubble-legacy .note-edit-form { margin-top: 6px; }

.thread-composer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--card);
}
.thread-composer-input {
    flex: 1;
    min-width: 0;
    border-radius: 20px;
    padding: 10px 16px;
    margin: 0;
    width: auto;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.06);
}
:root[data-theme="dark"] .thread-composer-input { box-shadow: inset 0 1px 4px rgba(0,0,0,.3); }
.thread-composer-input:focus {
    outline: 2px solid var(--sky);
    outline-offset: -1px;
    border-color: var(--sky);
}
/* button.thread-send-btn (не само .thread-send-btn) - за да надвие по
   специфичност генеричния button[type="submit"] (width:100%, margin-top). */
button.thread-send-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    margin: 0;
    padding: 0;
    border-radius: 999px;
    background: var(--nav-accent);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .1s;
    box-shadow: none;
}
button.thread-send-btn:active { transform: scale(.9); }
button.thread-send-btn svg { width: 19px; height: 19px; }

/* ── Статистика (stats.php) ── */
.stats-page-title { font-size: 20px; font-weight: 700; margin: 4px 0 2px; }
.stats-total { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

.stats-new-tile {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 10px;
    text-align: center;
}
.stats-new-count { font-size: 28px; font-weight: 700; color: var(--nav-accent); }
.stats-new-label { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ── Филтър за период (нови клиенти) ── */
.stats-range-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.stats-range-form select {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}
.stats-range-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    flex: 1 1 100%;
}
.stats-range-custom input[type="date"] {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    padding: 8px 10px;
    font-size: 13px;
}
/* button.stats-range-apply-btn (не само .stats-range-apply-btn) - за да
   надвие по специфичност генеричния button[type="submit"]. */
button.stats-range-apply-btn {
    flex-shrink: 0;
    width: auto;
    margin: 0;
    padding: 8px 14px;
    font-size: 13px;
}

/* ── Дневна графика (стълбовидна, чист CSS - без библиотека) ── */
.daily-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 130px;
    padding-top: 18px;
}
.daily-bar-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}
.daily-bar-value { font-size: 10px; font-weight: 600; color: var(--muted); margin-bottom: 3px; white-space: nowrap; }
.daily-bar {
    width: 100%;
    max-width: 26px;
    background: var(--nav-accent);
    border-radius: 4px 4px 0 0;
    transition: height .5s ease;
}
.daily-bar-label {
    font-size: 9px;
    color: var(--muted);
    margin-top: 5px;
    white-space: nowrap;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(0,0,0,.07), 0 12px 28px rgba(0,0,0,.09);
    animation: fadeUp .3s ease both;
}
:root[data-theme="dark"] .stat-card { box-shadow: 0 4px 16px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4); }

.stat-ring-wrap {
    position: relative;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
}
.stat-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.stat-ring-bg,
.stat-ring-fill {
    fill: none;
    stroke-width: 3;
}
.stat-ring-bg { stroke: var(--border); }
.stat-ring-fill {
    stroke: var(--nav-accent);
    stroke-linecap: round;
    transition: stroke-dashoffset .6s ease;
}
.stat-ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
}

.stat-card-body { flex: 1; min-width: 0; }
.stat-card-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
}
.stat-card-label-icon { color: var(--nav-accent); flex-shrink: 0; display: flex; }
.stat-card-label-icon .icon { width: 16px; height: 16px; }
.stat-card-numbers { font-size: 12px; color: var(--muted); margin-top: 3px; }

.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row {
    display: grid;
    grid-template-columns: 96px 1fr 30px;
    align-items: center;
    gap: 10px;
}
.bar-label {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bar-track {
    height: 10px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--nav-accent);
    transition: width .6s ease;
}
.bar-value { font-size: 13px; font-weight: 600; text-align: right; }

/* ── Login ── */
.login-body {
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}
.login-card {
    background: var(--card);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    animation: fadeUp .4s ease both;
}
.login-logo {
    border-radius: 18px;
    width: 84px;
    height: 84px;
    margin: 0 auto 16px;
}
.login-logo img { width: 140%; height: 140%; object-fit: contain; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card input { text-align: center; margin-bottom: 4px; }

/* ── Settings switches ── */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
}
.switch-label { font-size: 14px; font-weight: 600; }
.switch-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; touch-action: manipulation; transition: transform .1s; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch:active { transform: scale(.94); }
.switch-track {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 999px;
    transition: background .15s;
    pointer-events: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.15);
}
.switch-track::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform .15s;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .switch-track { background: var(--sky); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }
.switch input:disabled + .switch-track { opacity: .5; }
.switch input:disabled { cursor: not-allowed; }

/* ── Dark theme (near-black graphite, sampled from the app logo #18191A) ── */
:root[data-theme="dark"] {
    --navy:      #18191a;
    --navy-soft: #232426;
    --text:      #e9e9ea;
    --muted:     #9a9a9d;
    --border:    #38383b;
    --bg:        #18191a;
    --card:      #232426;
    --gray:      #9a9a9d;
}
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] input[type="password"] { background: var(--card); color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .badge-new         { background: rgba(148,163,184,.15); color: #cbd5e1; border-color: #475569; }
:root[data-theme="dark"] .badge-seen        { background: rgba(37,99,235,.22);  color: #93c5fd; }
:root[data-theme="dark"] .badge-in_progress { background: rgba(217,119,6,.22);  color: #fbbf24; }
:root[data-theme="dark"] .badge-resolved    { background: rgba(22,163,74,.22);  color: #4ade80; }
:root[data-theme="dark"] .alert-error       { background: rgba(220,38,38,.15); color: #fca5a5; }
:root[data-theme="dark"] .alert-success     { background: rgba(22,163,74,.15); color: #86efac; }

/* ── Mobile ── */
@media (max-width: 820px) {
    .detail-grid { grid-template-columns: 1fr; }
    .card-sticky { position: static; }
    .meta-list { grid-template-columns: 110px 1fr; }
    .filter-count { width: 100%; margin-left: 0; }
}
