/* ============================================
   Telegram Chat UI — extends ui-theme.css
   ============================================ */

/* Inbox list */
.tg-inbox-list {
    display: flex;
    flex-direction: column;
}

.tg-inbox-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f5;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.tg-inbox-item:hover {
    background: #f9fafb;
    text-decoration: none;
}

.tg-inbox-item.has-unread {
    background: #f0f4ff;
}

.tg-inbox-item.has-unread:hover {
    background: #e6edff;
}

.tg-inbox-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tg-inbox-avatar .material-icons {
    font-size: 24px;
}

.tg-inbox-content {
    flex: 1;
    min-width: 0;
}

.tg-inbox-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.tg-inbox-name {
    font-weight: 600;
    color: #1a1a2e;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-name-handle {
    font-size: 12px;
    font-weight: 500;
    color: #2563eb;
    margin-left: 4px;
}

.tg-view-handle {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 4px;
    margin-left: 10px;
}

.tg-view-handle:hover {
    color: #FFFFFF;
    text-decoration-style: solid;
}

.tg-inbox-time {
    font-size: 12px;
    color: #8892a0;
    flex-shrink: 0;
    margin-left: 8px;
}

.tg-inbox-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.tg-inbox-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 13px;
}

.tg-inbox-unread {
    background: #ef4444;
    color: white;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    padding: 0 6px;
}

/* Chat messages container */
.tg-chat-messages {
    max-height: calc(100vh - 400px);
    min-height: 400px;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tg-chat-messages::-webkit-scrollbar {
    width: 8px;
}

.tg-chat-messages::-webkit-scrollbar-track {
    background: #f0f0f5;
}

.tg-chat-messages::-webkit-scrollbar-thumb {
    background: #c4c9d4;
    border-radius: 4px;
}

/* Message bubble */
.tg-message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
}

.tg-message-student {
    align-self: flex-start;
    background: white;
    border-bottom-left-radius: 4px;
}

.tg-message-curator {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.tg-message-curator .tg-message-sender,
.tg-message-curator .tg-message-time {
    color: rgba(255, 255, 255, 0.8);
}

.tg-message-bot {
    align-self: flex-end;
    background: #f0f4ff;
    border: 1px dashed #667eea;
    color: #667eea;
    font-style: italic;
}

.tg-message-parent {
    align-self: flex-start;
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
}

.tg-message-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
    font-size: 11px;
}

.tg-message-sender {
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
}

.tg-message-time {
    color: #8892a0;
}

.tg-message-body {
    font-size: 14px;
    line-height: 1.5;
}

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

.tg-message-attachment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 6px;
}

.tg-message-curator .tg-message-attachment {
    background: rgba(255, 255, 255, 0.2);
}

.tg-message-attachment .material-icons {
    font-size: 16px;
}

/* Composer (message input area) */
.tg-chat-composer {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
}

.tg-chat-composer form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.tg-chat-composer textarea {
    flex: 1;
    resize: vertical;
    min-height: 42px;
    max-height: 150px;
}

.tg-chat-composer button {
    flex-shrink: 0;
}

/* Overdue task row highlight */
.row-overdue {
    background: #fef2f2 !important;
}

.row-overdue:hover {
    background: #fee2e2 !important;
}

/* Quick reply template chips */
.tg-templates-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    min-height: 40px;
    align-items: center;
}

.tg-template-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    font-size: 13px;
    color: #1a1a2e;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.tg-template-chip:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-1px);
}

.tg-template-chip:active {
    transform: translateY(0);
}

/* Clickable attachment link */
.tg-attachment-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.tg-attachment-link:hover {
    background: rgba(102, 126, 234, 0.15);
    text-decoration: none;
    transform: translateY(-1px);
}

.tg-attachment-link:hover .material-icons {
    color: #667eea;
}

.tg-attachment-link .material-icons:last-child {
    font-size: 16px;
    opacity: 0.7;
}

.tg-message-curator .tg-attachment-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   Inline Telegram username input (student table)
   ============================================ */
.ui-tbl-telegram-cell {
    min-width: 180px;
}

.ui-tg-username-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ui-tg-username-input {
    padding: 6px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.2s;
    width: 140px;
    outline: none;
}

.ui-tg-username-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.ui-tg-username-input.ui-tg-saving {
    background: #fef9c3;
    border-color: #eab308;
}

.ui-tg-username-input.ui-tg-saved {
    background: #dcfce7;
    border-color: #10b981;
}

.ui-tg-username-input.ui-tg-error {
    background: #fee2e2;
    border-color: #ef4444;
}

.ui-tg-status {
    display: inline-flex;
    align-items: center;
    cursor: help;
}

.ui-tg-status .material-icons {
    font-size: 18px;
}

.ui-tg-status.linked .material-icons {
    color: #10b981;
}

.ui-tg-status.pending .material-icons {
    color: #f59e0b;
}

/* Индикатор группового чата (без текста, цветной иконкой) */
.ui-tg-status.has-group .material-icons {
    color: #10b981;
}

.ui-tg-status.no-group .material-icons {
    color: #9ca3af;
}

/* ============================================
   Audio / voice message bubble
   ============================================ */
.tg-message-audio {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 4px;
    min-width: 260px;
}

.tg-audio-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
}

.tg-message-curator .tg-audio-header {
    color: rgba(255, 255, 255, 0.85);
}

.tg-audio-header .material-icons {
    font-size: 16px;
}

.tg-audio-label {
    font-weight: 500;
}

.tg-audio-player {
    width: 100%;
    min-width: 240px;
    height: 36px;
    outline: none;
}

/* В "тёмных" пузырях куратора делаем плеер со светлой темой */
.tg-message-curator .tg-audio-player {
    filter: invert(0.85) hue-rotate(180deg);
    border-radius: 18px;
}

.tg-audio-transcript {
    background: rgba(102, 126, 234, 0.08);
    border-left: 3px solid #667eea;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
}

.tg-message-curator .tg-audio-transcript {
    background: rgba(255, 255, 255, 0.15);
    border-left-color: rgba(255, 255, 255, 0.6);
}

.tg-audio-transcript-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 4px;
}

.tg-message-curator .tg-audio-transcript-label {
    color: rgba(255, 255, 255, 0.9);
}

.tg-audio-transcript-label .material-icons {
    font-size: 14px;
}

.tg-audio-transcript-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
}

.btn-transcribe-voice {
    margin-top: 4px;
    font-size: 12px;
}

/* ============================================
   Photo preview (inline thumbnail)
   ============================================ */
.tg-photo-preview {
    display: block;
    max-width: 280px;
    max-height: 280px;
    margin-bottom: 4px;
    border-radius: 10px;
    overflow: hidden;
    background: #f0f0f5;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
}

.tg-photo-preview:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.tg-photo-preview img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 280px;
    object-fit: cover;
}

/* Если картинка не загрузилась — показываем заглушку */
.tg-photo-broken {
    min-height: 140px;
    position: relative;
    background: #f3f4f6;
}

.tg-photo-broken::after {
    content: 'Фото недоступно';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #8892a0;
    font-size: 13px;
}

.tg-photo-broken img {
    display: none;
}

/* ============================================
   Private vs group chat visual distinction
   ============================================ */
.tg-inbox-avatar.group {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.tg-inbox-avatar.private {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.tg-inbox-item.tg-inbox-private {
    border-left: 3px solid #f59e0b;
    padding-left: 17px;
}

.tg-confidential-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    margin-bottom: 16px;
    color: #78350f;
    font-size: 14px;
}

.tg-confidential-notice .material-icons {
    color: #d97706;
    font-size: 20px;
}

/* ============================================
   Kanban board (Sabaq design)
   ============================================ */

/* Tab bar */
.kb-tab-bar {
    display: flex;
    gap: 4px;
    background: white;
    border: 1px solid #E8E8EC;
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.kb-tab {
    padding: 8px 18px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    color: #8C8C9A;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.kb-tab:hover { color: #333340; background: #F5F5F8; }

.kb-tab.active {
    background: #FF5A00;
    color: #fff;
}

.kb-tab-count {
    font-size: 10px;
    background: rgba(0,0,0,0.1);
    padding: 1px 6px;
    border-radius: 10px;
}

.kb-tab.active .kb-tab-count {
    background: rgba(255,255,255,0.25);
}

/* Section header */
.kb-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.kb-section-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.kb-section-title {
    font-size: 15px;
    font-weight: 600;
    color: #1A1A2E;
}

.kb-section-count {
    font-size: 12px;
    color: #8C8C9A;
    margin-left: auto;
    background: #F1F1F5;
    padding: 3px 10px;
    border-radius: 20px;
}

/* Stats row */
.kb-stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.kb-stat-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #E8E8EC;
}

.kb-stat-num {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.kb-stat-label {
    font-size: 11px;
    color: #8C8C9A;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Kanban grid */
.kb-kanban {
    display: grid;
    gap: 10px;
}

.kb-kanban-5 { grid-template-columns: repeat(5, 1fr); }
.kb-kanban-4 { grid-template-columns: repeat(4, 1fr); }
.kb-kanban-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 1400px) {
    .kb-kanban-5 {
        overflow-x: auto;
        grid-template-columns: repeat(5, 260px);
    }
    .kb-kanban-4 {
        overflow-x: auto;
        grid-template-columns: repeat(4, 260px);
    }
}

/* Column */
.kb-column {
    background: white;
    border-radius: 12px;
    border: 1px solid #E8E8EC;
    padding: 12px;
    min-height: 200px;
}

.kb-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid #E8E8EC;
}

.kb-col-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #8C8C9A;
}

.kb-col-count {
    font-size: 11px;
    font-weight: 600;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F1F1F5;
    color: #8C8C9A;
}

.kb-empty {
    text-align: center;
    color: #8C8C9A;
    padding: 20px;
    font-size: 13px;
}

/* Card */
.kb-card {
    background: #F5F5F8;
    border: 1px solid #E8E8EC;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    transition: box-shadow 0.15s;
}

.kb-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.kb-card-link:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    text-decoration: none;
    color: inherit;
}

.kb-card-overdue {
    border-left: 3px solid #EF4444;
    background: #FEF2F2;
}

.kb-card-individual {
    border-right: 3px solid #3B82F6;
}

.kb-card-excused {
    background: #FFFBEB;
    border-color: #FCD34D;
    opacity: 0.85;
}

.kb-card-excused .kb-card-name {
    color: #92400E;
}

.kb-card-unread {
    border-left: 3px solid #8B5CF6;
    background: linear-gradient(135deg, #F5F3FF 0%, #FFFFFF 60%);
    box-shadow: 0 1px 4px rgba(139, 92, 246, 0.15);
}

.kb-card-unread.kb-card-overdue {
    border-left-color: #EF4444;
    background: linear-gradient(135deg, #FEF2F2 0%, #FFFFFF 60%);
}

.kb-card-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8B5CF6;
    margin-right: 6px;
    vertical-align: middle;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.kb-col-counts {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.kb-col-new {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    background: #8B5CF6;
    color: #FFFFFF;
    line-height: 1;
}

.kb-live-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    background: #1F2937;
    color: #FFFFFF;
    padding: 12px 18px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity .25s ease, transform .25s ease;
    z-index: 9999;
    pointer-events: none;
}

.kb-live-toast-show {
    opacity: 1;
    transform: translateY(0);
}

/* Curator filter dropdown in kanban tab bar */
.kb-tab-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.kb-curator-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6B7280;
}

.kb-curator-filter select {
    padding: 6px 10px;
    border: 1px solid #E8E8EC;
    border-radius: 8px;
    background: #FFFFFF;
    font-size: 13px;
    color: #1F2937;
    cursor: pointer;
    max-width: 220px;
}

.kb-curator-filter select:focus {
    outline: 2px solid #8B5CF6;
    outline-offset: 1px;
}

/* Excused column variant */
.kb-column-excused {
    background: linear-gradient(180deg, #FFFBEB 0%, transparent 60%);
    border-radius: 8px;
    padding: 0 6px 6px;
}

.kb-column-body {
    min-height: 60px;
}

/* Per-card actions (complete / excuse) — bottom of card */
.kb-card { position: relative; }

.kb-card-body-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.kb-card-body-link:hover { text-decoration: none; color: inherit; }

.kb-card-actions {
    display: flex;
    gap: 4px;
    padding: 4px 0 0;
    margin-top: 6px;
    border-top: 1px dashed #E8E8EC;
    opacity: 0;
    transition: opacity 0.15s;
}

.kb-card:hover .kb-card-actions {
    opacity: 1;
}

.kb-card-act {
    border: none;
    background: #F1F1F5;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
}

.kb-card-act:hover { background: #E8E8EC; }
.kb-act-complete:hover { background: #D1FAE5; }
.kb-act-excuse:hover { background: #FEF3C7; }
.kb-act-unexcuse:hover { background: #DBEAFE; }

/* Excuse modal helpers */
.kb-excuse-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Remediation modal */
.kb-rem-row2 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
}

.kb-rem-weekdays {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.kb-rem-day {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 6px 10px;
    border: 1px solid #e8e8ec;
    border-radius: 8px;
    font-size: 13px;
    color: #6b7280;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.kb-rem-day input {
    display: none;
}

.kb-rem-day input:checked + span {
    color: #ffffff;
}

.kb-rem-day:has(input:checked) {
    background: #8b5cf6;
    border-color: #8b5cf6;
    color: #ffffff;
}

.kb-act-rem-create:hover { background: #ede9fe; }
.kb-act-rem-edit:hover { background: #ede9fe; }

/* Удаление плана — слева, чтобы визуально отделить от обычных Cancel/Save */
.kb-rem-footer-left { margin-right: auto; }
.kb-rem-footer-left[style*="display: none"] + button { margin-left: auto; }

.ui-form-input-readonly {
    background: #F9FAFB;
    color: #6B7280;
    cursor: default;
}

/* Task history timeline */
.task-timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 18px;
    border-left: 2px solid #E8E8EC;
}

.task-timeline-item {
    position: relative;
    padding: 8px 0 18px 18px;
}

.task-timeline-dot {
    position: absolute;
    left: -27px;
    top: 14px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #8B5CF6;
    box-shadow: 0 0 0 3px #FFFFFF;
}

.task-timeline-dot-msg {
    background: #3B82F6;
}

.task-timeline-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 12px;
    color: #6B7280;
    margin-bottom: 4px;
}

.task-timeline-time {
    font-variant-numeric: tabular-nums;
}

.task-timeline-actor {
    font-weight: 600;
    color: #1F2937;
}

.task-timeline-text {
    font-size: 13px;
    color: #1F2937;
    line-height: 1.45;
}

.kb-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}

.kb-card-name {
    font-size: 13px;
    font-weight: 600;
    color: #1A1A2E;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kb-card-subject {
    font-size: 11px;
    color: #8C8C9A;
    margin-bottom: 6px;
}

.kb-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.kb-card-debt {
    font-size: 10px;
    font-weight: 600;
}

/* Badges */
.kb-badge {
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
}

.kb-badge-overdue { background: #FEF2F2; color: #991B1B; }
.kb-badge-ok { background: #ECFDF5; color: #166534; }
.kb-badge-green { background: #ECFDF5; color: #166534; }
.kb-badge-yellow { background: #FFFBEB; color: #92400E; }
.kb-badge-blue { background: #EFF6FF; color: #1E40AF; }
.kb-badge-gray { background: #F1F1F5; color: #8C8C9A; }

.kb-badge-time {
    font-size: 10px;
    color: #8C8C9A;
}

/* Zone grid (2 columns) */
.kb-zone-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.kb-zone-col {
    background: white;
    border-radius: 12px;
    border: 1px solid #E8E8EC;
    padding: 12px;
    min-height: 160px;
}
