/* ═══════════════════════════════════════════════════════════
   SAGA DOORS — UI Enhancements
   Glassmorphism · Skeleton · Dark Mode · Toasts · Badges · Avatars
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS Variables (Light) ────────────────────────────── */
:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --primary: #2c2d28;
    --primary-dark: #4a4b45;
    --primary-gradient: linear-gradient(135deg, #2c2d28 0%, #4a4b45 100%);

    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --bg-card-glass: rgba(255, 255, 255, 0.72);
    --border: rgba(44, 45, 40, 0.12);
    --border-glass: rgba(255, 255, 255, 0.55);
    --text: #2c2d28;
    --text-muted: #6b7280;
    --shadow-sm: 0 2px 8px rgba(44, 45, 40, 0.08);
    --shadow-md: 0 8px 32px rgba(44, 45, 40, 0.12);
    --shadow-lg: 0 20px 60px rgba(44, 45, 40, 0.18);
    --radius: 14px;
    --radius-sm: 8px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── CSS Variables (Dark Mode) ────────────────────────── */
[data-theme="dark"] {
    --primary: #b8b9b3;           /* светлый антрацит для тёмного фона */
    --primary-dark: #d0d1cb;
    --bg: #0f1117;
    --bg-card: #1a1b23;
    --bg-card-glass: rgba(26, 27, 35, 0.82);
    --border: rgba(255, 255, 255, 0.08);
    --border-glass: rgba(255, 255, 255, 0.10);
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ─── Global Font Override ──────────────────────────────── */
body {
    font-family: var(--font-main) !important;
}

/* ─── Custom Scrollbar ──────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #2c2d28, #4a4b45);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #3d3e38, #4a4b45);
}

/* ─── Glassmorphism Cards ───────────────────────────────── */
.glass-card,
.stat-card,
.info-card,
.dashboard-card {
    background: var(--bg-card-glass) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid var(--border-glass) !important;
    box-shadow: var(--shadow-md) !important;
    transition: transform var(--transition), box-shadow var(--transition) !important;
}
.glass-card:hover,
.stat-card:hover {
    transform: translateY(-3px) !important;
    box-shadow: var(--shadow-lg) !important;
}

/* ─── Gradient Text ─────────────────────────────────────── */
.gradient-text {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ─── Animated Counter ──────────────────────────────────── */
.counter-value {
    display: inline-block;
    transition: transform 0.1s;
}

/* ─── Status Pulse Badge ────────────────────────────────── */
.status-pulse {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.status-pulse::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    animation: pulseDot 2s ease-in-out infinite;
}
.status-pulse.active  { color: #22c55e; }
.status-pulse.pending { color: #f59e0b; }
.status-pulse.error   { color: #ef4444; }
.status-pulse.info    { color: #2c2d28; }

@keyframes pulseDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(1.4); }
}

/* ─── Skeleton Loading ──────────────────────────────────── */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e4e4e4 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeletonShimmer 1.6s infinite;
    border-radius: 6px;
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}
[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        #2a2b35 25%,
        #32333f 50%,
        #2a2b35 75%
    );
    background-size: 200% 100%;
}
@keyframes skeletonShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-row {
    height: 16px;
    margin: 10px 0;
    border-radius: 4px;
}
.skeleton-row.short  { width: 40%; }
.skeleton-row.medium { width: 70%; }
.skeleton-row.full   { width: 100%; }
.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.skeleton-table-row {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.skeleton-table-row > span {
    flex: 1;
    height: 14px;
    border-radius: 4px;
}

/* ─── Empty State ───────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 56px;
    margin-bottom: 16px;
    opacity: 0.7;
    animation: float 3s ease-in-out infinite;
}
.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}
.empty-state p {
    font-size: 14px;
    max-width: 300px;
    line-height: 1.6;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

/* ─── Ripple Effect ─────────────────────────────────────── */
.btn-ripple {
    position: relative;
    overflow: hidden;
}
.btn-ripple .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0);
    animation: rippleAnim 0.6s linear;
    pointer-events: none;
}
@keyframes rippleAnim {
    to { transform: scale(4); opacity: 0; }
}

/* ─── Dark Mode Toggle Button ───────────────────────────── */
.dark-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    white-space: nowrap;
}
.dark-mode-toggle:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}
.dark-mode-toggle .toggle-icon {
    font-size: 15px;
    line-height: 1;
}

/* ─── Dark Mode — Main Content Adjustments ──────────────── */
[data-theme="dark"] body {
    background: var(--bg) !important;
    color: var(--text) !important;
}
[data-theme="dark"] .main-content,
[data-theme="dark"] .cabinet-main,
[data-theme="dark"] .content-area {
    background: var(--bg) !important;
}
[data-theme="dark"] .card,
[data-theme="dark"] .profile-card,
[data-theme="dark"] .order-card,
[data-theme="dark"] .news-card,
[data-theme="dark"] .section-block,
[data-theme="dark"] .form-section {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] label {
    color: var(--text) !important;
}
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background: #252630 !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}
[data-theme="dark"] table thead tr {
    background: #252630 !important;
}
[data-theme="dark"] table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.03) !important;
}
[data-theme="dark"] table tbody tr:hover {
    background: rgba(44, 45, 40, 0.1) !important;
}
[data-theme="dark"] td, [data-theme="dark"] th {
    border-color: var(--border) !important;
    color: var(--text) !important;
}

/* ─── Avatar Upload UI ──────────────────────────────────── */
.avatar-upload-wrapper {
    position: relative;
    width: 96px;
    height: 96px;
    cursor: pointer;
    flex-shrink: 0;
}
.avatar-upload-wrapper:hover .avatar-overlay {
    opacity: 1;
}
.avatar-img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(44, 45, 40, 0.35);
    box-shadow: 0 4px 16px rgba(44, 45, 40, 0.2);
    display: block;
}
.avatar-initials-large {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    font-size: 32px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid rgba(255,255,255,0.3);
    box-shadow: 0 4px 16px rgba(44, 45, 40, 0.3);
    letter-spacing: 1px;
}
.avatar-overlay {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.avatar-overlay .overlay-icon {
    font-size: 22px;
    line-height: 1;
}
.avatar-overlay .overlay-text {
    font-size: 9px;
    color: white;
    font-weight: 600;
    text-align: center;
    margin-top: 3px;
    line-height: 1.2;
}
#avatarFileInput {
    display: none;
}

/* Header avatar (small) */
.user-avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.4);
}

/* ─── Toast Notifications ───────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 380px;
    width: calc(100vw - 40px);
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: 12px;
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    color: white;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    pointer-events: all;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.2);
    animation: toastSlideIn 0.35s cubic-bezier(0.4,0,0.2,1) forwards;
    max-width: 100%;
    word-break: break-word;
}
.toast.hiding {
    animation: toastSlideOut 0.3s cubic-bezier(0.4,0,0.2,1) forwards;
}
.toast.success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.toast.error   { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast.warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.toast.info    { background: linear-gradient(135deg, #2c2d28, #4a4b45); }

.toast-icon { font-size: 18px; flex-shrink: 0; line-height: 1; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; opacity: 0.9; }
.toast-message { font-size: 13px; opacity: 0.95; }
.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 16px;
    cursor: pointer;
    padding: 0 0 0 4px;
    line-height: 1;
    transition: color 0.2s;
}
.toast-close:hover { color: white; }
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255,255,255,0.45);
    border-radius: 0 0 12px 12px;
    animation: toastProgress linear forwards;
}
.toast { position: relative; }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(110%) scale(0.9); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to   { opacity: 0; transform: translateX(110%) scale(0.9); }
}
@keyframes toastProgress {
    from { width: 100%; }
    to   { width: 0%; }
}

/* ─── Telegram-style Message Input Bar ─────────────────── */
.tg-input-bar {
    padding: 10px 20px 12px;
    background: #fff;
    border-top: 1px solid rgba(44, 45, 40, 0.08);
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.tg-attachment-preview {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    padding: 0 2px;
}

.tg-input-form {
    display: flex;
    align-items: center;
    gap: 3px;
    width: 100%;
}

/* Пилюля: содержит emoji, поле ввода, скрепку */
.tg-input-pill {
    flex: 1;
    display: flex;
    align-items: center;
    background: #f2f2f0;
    border-radius: 26px;
    padding: 0 6px;
    min-height: 50px;
    transition: box-shadow 0.2s;
}
.tg-input-pill:focus-within {
    box-shadow: 0 0 0 2px rgba(44, 45, 40, 0.18);
}

/* Кнопки внутри пилюли (emoji, скрепка) */
.tg-pill-btn {
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9a9b95;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}
.tg-pill-btn:hover {
    background: rgba(44, 45, 40, 0.08);
    color: #2c2d28;
}

/* Само поле ввода текста */
.tg-msg-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 15px;
    line-height: 1.5;
    color: #2c2d28;
    padding: 10px 6px;
    font-family: var(--font-main, 'Inter', sans-serif);
    resize: none;
    min-height: 20px;
    max-height: 120px;
    overflow-y: auto;
}
.tg-msg-input::placeholder {
    color: #b0b0aa;
}

/* Кнопка отправки — снаружи пилюли */
.tg-send-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #2c2d28;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 2px 10px rgba(44, 45, 40, 0.3);
}
.tg-send-btn:hover {
    background: #4a4b45;
    transform: scale(1.06);
    box-shadow: 0 4px 16px rgba(44, 45, 40, 0.4);
}
.tg-send-btn:active {
    transform: scale(0.94);
}

/* Тёмная тема */
[data-theme="dark"] .tg-input-bar {
    background: #1a1b23;
    border-top-color: rgba(255, 255, 255, 0.07);
}
[data-theme="dark"] .tg-input-pill {
    background: #252630;
}
[data-theme="dark"] .tg-msg-input {
    color: #e2e8f0;
}
[data-theme="dark"] .tg-msg-input::placeholder {
    color: #5a6070;
}
[data-theme="dark"] .tg-pill-btn {
    color: #6b7280;
}
[data-theme="dark"] .tg-pill-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #e2e8f0;
}
[data-theme="dark"] .tg-send-btn {
    background: #4a4b45;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .tg-send-btn:hover {
    background: #5c5d56;
}

/* ─── Confetti Canvas ───────────────────────────────────── */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99998;
}

/* ─── Mobile: reduce input bar padding so send button is not clipped ─── */
@media (max-width: 900px) {
    .tg-input-bar {
        padding: 8px 8px 8px;
    }
    .tg-send-btn {
        width: 44px;
        height: 44px;
    }
}
