:root {
    --bg-base: #1e1f22;
    --bg-panel: #2b2d31;
    --bg-elevated: #313338;
    --bg-input: #1e1f22;
    --bg-hover: rgba(79,84,92,.32);
    --bg-active: rgba(79,84,92,.48);
    --text: #dbdee1;
    --text-dim: #949ba4;
    --text-bright: #f2f3f5;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --border: #3f4147;
    --green: #23a559;
    --radius: 8px;
    --list-width: 340px;
    --font: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg-base); color: var(--text); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* Login */
.login-page { min-height: 100vh; background: var(--bg-base); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 420px; background: var(--bg-panel); border-radius: var(--radius); padding: 32px; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 22px; color: var(--text-bright); margin: 12px 0 6px; }
.login-brand p { color: var(--text-dim); font-size: 14px; }
.login-form label { display: block; font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; margin: 14px 0 6px; }
.login-form input { width: 100%; padding: 10px 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 15px; outline: none; }
.login-form input:focus { border-color: var(--accent); }
.login-form button { width: 100%; margin-top: 20px; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 15px; font-weight: 600; cursor: pointer; }
.login-form button:hover:not(:disabled) { background: var(--accent-hover); }
.login-error { color: #f23f43; font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; }

/* Layout */
.app { display: flex; height: 100vh; }
.panel-list { width: var(--list-width); background: var(--bg-panel); display: flex; flex-direction: column; border-right: 1px solid var(--border); flex-shrink: 0; }
.panel-chat { flex: 1; display: flex; flex-direction: column; background: var(--bg-elevated); min-width: 0; }

.panel-top { display: flex; align-items: flex-start; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.panel-brand { display: flex; gap: 12px; align-items: center; }
.brand-icon { width: 40px; height: 40px; background: var(--accent); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.panel-brand h1 { font-size: 16px; font-weight: 700; color: var(--text-bright); }
.brand-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.btn-icon { background: transparent; border: none; color: var(--text-dim); padding: 8px; border-radius: var(--radius); cursor: pointer; }
.btn-icon:hover { background: var(--bg-hover); color: #f23f43; }

/* Filters */
.filter-block { padding: 12px 16px 0; flex-shrink: 0; }
.filter-block + .filter-block { padding-top: 10px; }
.filter-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.filter-label { display: block; font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.filter-field .filter-label { margin-bottom: 6px; }

.search-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.search-tab { flex: 1; padding: 6px 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; }
.search-tab:hover { color: var(--text); }
.search-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.search-field { position: relative; display: flex; align-items: center; }
.search-field svg { position: absolute; left: 10px; color: var(--text-dim); pointer-events: none; }
.search-field input { width: 100%; padding: 9px 32px 9px 34px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none; }
.search-field input:focus { border-color: var(--accent); }
.search-field input::placeholder { color: var(--text-dim); }
.search-clear { position: absolute; right: 8px; background: var(--bg-hover); border: none; color: var(--text); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1; }

.date-display { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.btn-nav { width: 32px; height: 32px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 18px; cursor: pointer; flex-shrink: 0; }
.btn-nav:hover { background: var(--bg-hover); }
.date-display-text { flex: 1; text-align: center; padding: 6px 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; position: relative; }
.date-display-text:hover { border-color: var(--accent); }
#date-label { font-size: 14px; font-weight: 600; color: var(--text-bright); display: block; }
.date-picker-hidden { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

.chip-row { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 5px 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 20px; color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; }
.chip:hover { color: var(--text); border-color: var(--text-dim); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.select-input { width: 100%; padding: 8px 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none; cursor: pointer; }
.select-input:focus { border-color: var(--accent); }

/* Ticket list */
.list-header { padding: 10px 16px 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); flex-shrink: 0; }
.ticket-list { flex: 1; overflow-y: auto; padding: 0 10px 8px; }

.ticket-card {
    display: block; width: 100%; text-align: left;
    padding: 12px; margin-bottom: 6px;
    background: var(--bg-input); border: 1px solid transparent;
    border-radius: var(--radius); cursor: pointer;
    transition: background .12s, border-color .12s;
}
.ticket-card:hover { background: var(--bg-hover); border-color: var(--border); }
.ticket-card.active { background: var(--bg-active); border-color: var(--accent); }
.ticket-card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ticket-card-hash { color: var(--text-dim); font-size: 14px; font-weight: 600; }
.ticket-card-name { flex: 1; font-size: 14px; font-weight: 600; color: var(--text-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-card-badge { font-size: 11px; background: var(--bg-panel); color: var(--text-dim); padding: 2px 7px; border-radius: 10px; flex-shrink: 0; }
.ticket-card-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 8px; }

.list-empty { padding: 24px 16px; text-align: center; color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.btn-load-more { display: block; width: calc(100% - 20px); margin: 4px 10px 12px; padding: 10px; background: transparent; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--text-dim); font-size: 13px; cursor: pointer; flex-shrink: 0; }
.btn-load-more:hover { background: var(--bg-hover); color: var(--text); }

/* Chat panel */
.chat-header { padding: 16px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-breadcrumb { font-size: 12px; color: var(--accent); margin-bottom: 4px; font-weight: 500; }
.chat-header h2 { font-size: 20px; font-weight: 700; color: var(--text-bright); margin-bottom: 4px; }
.chat-sub { font-size: 13px; color: var(--text-dim); }

.chat-body { flex: 1; overflow-y: auto; padding: 16px 0; }
.chat-footer { padding: 10px 24px; border-top: 1px solid var(--border); text-align: center; flex-shrink: 0; }
.btn-secondary { padding: 8px 20px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; cursor: pointer; }
.btn-secondary:hover { background: var(--bg-hover); }

.empty-hero { max-width: 480px; margin: 48px auto; padding: 0 24px; text-align: center; }
.empty-hero-icon { font-size: 48px; margin-bottom: 16px; }
.empty-hero h3 { font-size: 20px; color: var(--text-bright); margin-bottom: 16px; }
.help-steps { text-align: left; list-style: none; margin-bottom: 16px; }
.help-steps li { padding: 8px 0; font-size: 14px; color: var(--text-dim); line-height: 1.5; border-bottom: 1px solid var(--border); }
.help-steps li:last-child { border-bottom: none; }
.help-steps strong { color: var(--text); }
.help-tip { font-size: 13px; color: var(--text-dim); background: var(--bg-panel); padding: 10px 14px; border-radius: var(--radius); }

/* Messages */
.message { display: flex; gap: 14px; padding: 4px 24px 4px 72px; margin-top: 16px; }
.message:first-child { margin-top: 0; }
.message:hover { background: var(--bg-hover); }
.message-compact { margin-top: 0; padding-top: 0; padding-bottom: 0; }
.message-compact .message-avatar-wrap { visibility: hidden; width: 40px; flex-shrink: 0; }
.message-compact .message-header { display: none; }
.message-avatar-wrap { width: 40px; flex-shrink: 0; }
.message-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.message-avatar-ph { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #fff; }
.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.message-author { font-size: 15px; font-weight: 600; }
.message-time { font-size: 11px; color: var(--text-dim); }
.message-edited { font-size: 10px; color: var(--text-dim); }
.message-content { font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.message-deleted .message-content { color: var(--text-dim); font-style: italic; }
.message-attachments { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.attachment-img-wrap { display: inline-block; padding: 0; border: none; background: none; cursor: zoom-in; border-radius: var(--radius); overflow: hidden; max-width: 480px; }
.attachment-img { display: block; max-width: 480px; max-height: 320px; border-radius: var(--radius); object-fit: contain; }
.attachment-file { display: flex; align-items: center; gap: 10px; max-width: 400px; padding: 12px 14px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: #00a8fc; font-size: 14px; }
.attachment-file:hover { background: var(--bg-hover); }
.attachment-file-icon { font-size: 22px; }
.attachment-file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { font-size: 11px; color: var(--text-dim); display: block; }
.search-tag { font-size: 11px; font-weight: 600; color: var(--accent); margin-bottom: 4px; padding: 0; border: none; background: none; cursor: pointer; text-align: left; }
.search-tag:hover { text-decoration: underline; }
.empty-state { padding: 40px 24px; text-align: center; color: var(--text-dim); font-size: 15px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.88); cursor: zoom-out; }
.lightbox-content { position: relative; z-index: 1; max-width: 95vw; max-height: 95vh; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.lightbox-close { position: absolute; top: -40px; right: 0; width: 34px; height: 34px; background: rgba(255,255,255,.15); border: none; border-radius: 50%; color: #fff; font-size: 22px; cursor: pointer; }
#lightbox-img { max-width: 90vw; max-height: 82vh; object-fit: contain; border-radius: var(--radius); }
.lightbox-footer { display: flex; align-items: center; gap: 16px; margin-top: 12px; color: #fff; font-size: 14px; }
#lightbox-download { color: #00a8fc; text-decoration: none; padding: 4px 12px; background: rgba(255,255,255,.1); border-radius: var(--radius); }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #1a1b1e; border-radius: 4px; }

@media (max-width: 768px) {
    .panel-list { width: 100%; max-width: 100%; }
    .panel-chat { display: none; }
    .app.show-chat .panel-list { display: none; }
    .app.show-chat .panel-chat { display: flex; width: 100%; }
    .message { padding-left: 16px; padding-right: 16px; }
}
