/* ==========================================================================
   Material 3 Expressive Design System for SaveMOD Apostle
   Tokens: #151515 bg, #1b1d22 surface, #24252B secondary, #292A30 input
   Accents: #2864E8 primary, #A8C7FA light blue, #72D99A success, #FFBE55 warning, #F3A6AE danger
   ========================================================================== */

:root {
    --md-bg: #151515;
    --md-surface-card: #1b1d22;
    --md-surface-secondary: #24252B;
    --md-surface-input: #292A30;
    --md-primary-blue: #2864E8;
    --md-primary-light: #A8C7FA;
    --md-text-primary: #F2F3F7;
    --md-text-secondary: #A2A5B0;
    --md-status-success: #72D99A;
    --md-status-warning: #FFBE55;
    --md-status-danger: #F3A6AE;
    --md-outline: rgba(255, 255, 255, 0.08);

    /* Functional aliases */
    --bg: var(--md-bg);
    --card-bg: var(--md-surface-card);
    --surface-secondary: var(--md-surface-secondary);
    --surface-input: var(--md-surface-input);
    --text: var(--md-text-primary);
    --hint: var(--md-text-secondary);
    --accent: var(--md-primary-blue);
    --accent-light: var(--md-primary-light);
    --btn-text: #FFFFFF;
    --danger: var(--md-status-danger);
    --success: var(--md-status-success);
    --warning: var(--md-status-warning);

    /* Material 3 Expressive Radii */
    --radius-btn: 20px;
    --radius-input: 18px;
    --radius-card: 26px;
    --radius-container: 30px;
    --radius-pill: 9999px;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Google Sans", "Segoe UI", Roboto, sans-serif; 
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background-color: var(--md-bg);
    color: var(--md-text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body {
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

/* ==========================================================================
   Header (App Bar)
   ========================================================================== */

.header { 
    padding: 14px 18px; 
    background: rgba(21, 21, 21, 0.88); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px);
    position: sticky; 
    top: 0; 
    z-index: 200; 
    border-bottom: 1px solid var(--md-outline); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(40, 100, 232, 0.25), rgba(168, 199, 250, 0.15));
    border: 1px solid rgba(40, 100, 232, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-light);
    flex-shrink: 0;
}

.header-title-box h1 { 
    font-size: 17px; 
    font-weight: 700; 
    letter-spacing: -0.2px; 
    color: var(--md-text-primary);
    line-height: 1.2;
}

.header-title-box .header-subtitle {
    font-size: 11px;
    color: var(--md-text-secondary);
    font-weight: 500;
}

.badge { 
    background: rgba(114, 217, 154, 0.15); 
    color: var(--md-status-success); 
    font-size: 11px; 
    padding: 4px 12px; 
    border-radius: var(--radius-pill); 
    font-weight: 600; 
    display: inline-flex; 
    align-items: center; 
    gap: 6px; 
    border: 1px solid rgba(114, 217, 154, 0.28);
}

.badge::before { 
    content: ""; 
    width: 6px; 
    height: 6px; 
    background: var(--md-status-success); 
    border-radius: 50%; 
    box-shadow: 0 0 8px rgba(114, 217, 154, 0.6);
}

/* ==========================================================================
   Material 3 Expressive Navigation Bar (Mobile Floating Bottom Bar)
   ========================================================================== */

.nav-tabs { 
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(68px + env(safe-area-inset-bottom, 0px));
    padding: 6px 16px calc(6px + env(safe-area-inset-bottom, 0px)) 16px;
    background: rgba(21, 21, 25, 0.94);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--md-outline);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 500;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
}

.nav-tab { 
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    color: var(--md-text-secondary);
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    padding: 2px 4px;
    max-width: 90px;
}

.nav-tab-pill {
    width: 56px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1);
    color: var(--md-text-secondary);
}

.nav-tab svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
}

.nav-tab-label {
    font-size: 11px;
    font-weight: 600;
    margin-top: 3px;
    white-space: nowrap;
    transition: color 0.2s ease;
    letter-spacing: -0.1px;
}

.nav-tab.active .nav-tab-pill {
    background: rgba(40, 100, 232, 0.22);
    color: var(--accent-light);
    border: 1px solid rgba(40, 100, 232, 0.4);
}

.nav-tab.active .nav-tab-label {
    color: var(--accent-light);
    font-weight: 700;
}

.nav-tab:active .nav-tab-pill {
    transform: scale(0.92);
}

/* ==========================================================================
   Container & Cards
   ========================================================================== */

.container { 
    padding: 16px 14px 20px; 
    max-width: 640px; 
    margin: 0 auto; 
}

.tab-content { 
    display: none; 
    animation: fadeIn 0.25s ease-out;
}

.tab-content.active { 
    display: block; 
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.card { 
    background: var(--card-bg); 
    border-radius: var(--radius-card); 
    padding: 18px 20px; 
    margin-bottom: 16px; 
    border: 1px solid var(--md-outline); 
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35); 
    transition: transform 0.15s, box-shadow 0.15s;
}

.card-header { 
    font-size: 13px; 
    font-weight: 700; 
    color: var(--hint); 
    margin-bottom: 14px; 
    text-transform: uppercase; 
    letter-spacing: 0.8px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 14px 0; 
    border-bottom: 1px solid var(--md-outline); 
}

.setting-row:last-child { 
    border-bottom: none; 
}

.setting-label { 
    font-size: 15px; 
    font-weight: 600; 
    color: var(--md-text-primary); 
}

.setting-desc { 
    font-size: 12.5px; 
    color: var(--hint); 
    margin-top: 3px; 
    line-height: 1.4; 
}

/* ==========================================================================
   Material 3 Expressive Switches
   ========================================================================== */

.switch { 
    position: relative; 
    width: 52px; 
    height: 32px; 
    flex-shrink: 0; 
    margin-left: 14px; 
}

.switch input { 
    opacity: 0; 
    width: 0; 
    height: 0; 
}

.slider { 
    position: absolute; 
    cursor: pointer; 
    top: 0; left: 0; right: 0; bottom: 0; 
    background-color: var(--surface-input); 
    border: 2px solid rgba(255, 255, 255, 0.2); 
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1); 
    border-radius: var(--radius-pill); 
}

.slider:before { 
    position: absolute; 
    content: ""; 
    height: 16px; 
    width: 16px; 
    left: 6px; 
    top: 6px; 
    background-color: var(--md-text-secondary); 
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1); 
    border-radius: 50%; 
}

input:checked + .slider { 
    background-color: var(--md-primary-blue); 
    border-color: var(--md-primary-blue); 
}

input:checked + .slider:before { 
    width: 22px; 
    height: 22px; 
    left: 4px; 
    top: 3px; 
    transform: translateX(20px); 
    background-color: #FFFFFF; 
}

/* ==========================================================================
   Pills & Segmented Controls
   ========================================================================== */

.pills { 
    display: flex; 
    gap: 8px; 
    margin-top: 10px; 
}

.pill { 
    flex: 1; 
    text-align: center; 
    padding: 10px 12px; 
    font-size: 12.5px; 
    font-weight: 600; 
    border-radius: var(--radius-pill); 
    background: var(--surface-input); 
    cursor: pointer; 
    border: 1px solid var(--md-outline); 
    color: var(--hint);
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.pill:hover { 
    color: white; 
    border-color: rgba(255, 255, 255, 0.2); 
}

.pill.active { 
    background: var(--md-primary-blue); 
    color: #FFFFFF; 
    border-color: var(--md-primary-blue); 
    box-shadow: 0 2px 10px rgba(40, 100, 232, 0.4);
    font-weight: 700;
}

/* ==========================================================================
   Inputs & Buttons
   ========================================================================== */

input[type="text"], input[type="password"], select { 
    background: var(--surface-input); 
    border: 1px solid var(--md-outline); 
    border-radius: var(--radius-input); 
    padding: 12px 16px; 
    color: var(--md-text-primary); 
    font-size: 14px; 
    outline: none; 
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

input[type="text"]:focus, input[type="password"]:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(40, 100, 232, 0.25);
    background: #30323a;
}

button { 
    background: var(--accent); 
    color: var(--btn-text); 
    border: none; 
    border-radius: var(--radius-btn); 
    padding: 12px 20px; 
    font-weight: 600; 
    font-size: 14px;
    cursor: pointer; 
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
}

button:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--surface-input);
    color: var(--md-text-primary);
    border: 1px solid var(--md-outline);
}

.btn-danger { 
    background: rgba(243, 166, 174, 0.15); 
    color: var(--danger); 
    padding: 8px 16px; 
    font-size: 12.5px; 
    border-radius: var(--radius-pill); 
    border: 1px solid rgba(243, 166, 174, 0.3);
}

.btn-danger:active {
    background: rgba(243, 166, 174, 0.25);
}

/* ==========================================================================
   Search Box & Filter Scroll Pills
   ========================================================================== */

.search-box {
    position: relative;
    width: 100%;
    margin-bottom: 12px;
}

.search-box input {
    width: 100%;
    height: 44px;
    padding: 0 36px 0 42px;
    border-radius: var(--radius-pill);
    background: var(--surface-input);
    border: 1px solid var(--md-outline);
    color: white;
    font-size: 13.5px;
    outline: none;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    box-sizing: border-box;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(40, 100, 232, 0.25);
    background: #30323a;
}

.search-box .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    color: var(--hint);
    pointer-events: none;
    display: flex;
    align-items: center;
}

.search-box .clear-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--hint);
    cursor: pointer;
    padding: 4px;
    display: none;
    user-select: none;
}

.search-box .clear-btn:hover { color: white; }

.filter-scroll-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 8px 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.filter-scroll-pills::-webkit-scrollbar { display: none; }

.filter-pill {
    white-space: nowrap;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-pill);
    background: var(--surface-input);
    border: 1px solid var(--md-outline);
    color: var(--hint);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.filter-pill:hover { color: white; border-color: rgba(255, 255, 255, 0.25); }

.filter-pill.active {
    background: var(--md-primary-blue);
    color: #FFFFFF;
    border-color: var(--md-primary-blue);
    box-shadow: 0 2px 8px rgba(40, 100, 232, 0.35);
    font-weight: 700;
}

.filter-pill.disabled-pill {
    opacity: 0.4;
    cursor: default;
}

/* ==========================================================================
   Telegram Chat View & Message Bubbles
   ========================================================================== */

.tg-avatar { 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 700; 
    font-size: 16px; 
    color: white; 
    flex-shrink: 0; 
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35); 
}

.tg-chat-item { 
    display: flex; 
    align-items: center; 
    gap: 14px; 
    padding: 14px 16px; 
    background: var(--card-bg); 
    border: 1px solid var(--md-outline); 
    border-radius: 22px; 
    margin-bottom: 10px; 
    cursor: pointer; 
    transition: background 0.15s, transform 0.1s; 
}

.tg-chat-item:active { 
    background: var(--surface-secondary); 
    transform: scale(0.99);
}

.tg-chat-info { flex: 1; min-width: 0; }
.tg-chat-name { font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: center; color: var(--md-text-primary); }
.tg-chat-preview { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }

.tg-badge-count { 
    background: var(--accent-light); 
    color: #04315a; 
    font-size: 11px; 
    font-weight: 800; 
    border-radius: var(--radius-pill); 
    padding: 3px 9px; 
    min-width: 22px; 
    text-align: center; 
}

.chat-bubbles-container { 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    padding: 6px 0; 
}

.tg-bubble { 
    max-width: 92%; 
    background: var(--surface-secondary); 
    border: 1px solid var(--md-outline); 
    border-radius: 22px 22px 22px 6px; 
    padding: 14px 16px; 
    position: relative; 
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); 
}

.tg-bubble-deleted { 
    border-left: 4px solid var(--danger); 
}

.tg-bubble-edited { 
    border-left: 4px solid var(--warning); 
}

.tg-bubble-meta { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 11px; 
    color: var(--hint); 
    margin-bottom: 8px; 
}

.tg-bubble-text { 
    font-size: 14.5px; 
    line-height: 1.5; 
    word-break: break-word; 
    color: var(--md-text-primary); 
}

.tg-bubble-time { 
    font-size: 11px; 
    color: var(--hint); 
    text-align: right; 
    margin-top: 8px; 
}

/* Material 3 Expressive Diff Tags for Message Edits */
.diff-old { 
    color: var(--danger); 
    text-decoration: line-through; 
    background: rgba(243, 166, 174, 0.1); 
    padding: 6px 12px; 
    border-radius: 10px; 
    margin-bottom: 6px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    border-left: 2px solid var(--danger);
}

.diff-new { 
    color: var(--success); 
    background: rgba(114, 217, 154, 0.1); 
    padding: 6px 12px; 
    border-radius: 10px; 
    font-weight: 500; 
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    border-left: 2px solid var(--success);
}

/* ==========================================================================
   Media Containers & Lightbox
   ========================================================================== */

.media-container {
    margin: 10px 0;
    border-radius: 16px;
    overflow: hidden;
}

.photo-container {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--md-outline);
}

.media-preview-img {
    width: 100%;
    max-height: 280px;
    object-fit: contain;
    border-radius: 16px;
    display: block;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.media-preview-img:hover {
    transform: scale(1.01);
}

.voice-container {
    background: var(--surface-input);
    border: 1px solid var(--md-outline);
    padding: 12px 14px;
}

.media-header-label {
    font-size: 12px;
    color: var(--hint);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.media-audio {
    width: 100%;
    height: 38px;
    outline: none;
}

.video-note-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
}

.media-round-video {
    width: 190px;
    height: 190px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
    background: #000;
}

.video-container {
    background: #000;
    border: 1px solid var(--md-outline);
}

.media-video {
    width: 100%;
    max-height: 260px;
    border-radius: 16px;
    display: block;
}

.media-download-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-input);
    padding: 9px 14px;
    border-radius: var(--radius-btn);
    color: var(--accent-light);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--md-outline);
}

.media-error-badge {
    font-size: 12px;
    color: var(--hint);
    padding: 12px;
    text-align: center;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
}

/* ==========================================================================
   Modals & Dialogs (Material 3 Expressive)
   ========================================================================== */

.m3-modal-backdrop { 
    display: none; 
    position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0; 
    background: rgba(12, 13, 16, 0.88); 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px);
    z-index: 1000; 
    align-items: center; 
    justify-content: center; 
    padding: 20px; 
}

.m3-modal-card { 
    background: var(--surface-secondary); 
    border-radius: var(--radius-container); 
    padding: 28px 24px; 
    max-width: 380px; 
    width: 100%; 
    border: 1px solid var(--md-outline); 
    text-align: center; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.75); 
    animation: modalPop 0.25s cubic-bezier(0.2, 0, 0, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.auth-icon { 
    font-size: 44px; 
    margin-bottom: 12px; 
}

.auth-title { 
    font-size: 20px; 
    font-weight: 700; 
    margin-bottom: 8px; 
    color: var(--md-text-primary); 
}

.auth-desc { 
    font-size: 13.5px; 
    color: var(--hint); 
    margin-bottom: 22px; 
    line-height: 1.45; 
}

.auth-input { 
    width: 100%; 
    margin-bottom: 14px; 
}

.auth-btn { 
    width: 100%; 
    height: 48px; 
    font-size: 15px; 
    font-weight: 700; 
}

.auth-err { 
    color: var(--danger); 
    font-size: 13px; 
    margin-top: 10px; 
    display: none; 
    font-weight: 500; 
}

/* Lightbox Photo Modal */
#img-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.94);
    backdrop-filter: blur(12px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 16px;
    animation: fadeIn 0.2s ease-out;
}

#img-modal-src {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px;
    object-fit: contain;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
}

.lightbox-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Confirmation Modal Buttons */
.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 22px;
}

.modal-actions button {
    flex: 1;
    height: 44px;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 360px) {
    .header h1 { font-size: 15px; }
    .badge { font-size: 10px; padding: 3px 8px; }
    .nav-tab-pill { width: 48px; height: 28px; }
    .nav-tab-label { font-size: 10px; }
    .card { padding: 14px 14px; border-radius: 20px; }
    .pills { flex-wrap: wrap; }
    .pill { font-size: 11.5px; padding: 8px 10px; }
}

@media (min-width: 768px) {
    .container { max-width: 680px; }
    .nav-tabs { 
        max-width: 640px; 
        left: 50%; 
        transform: translateX(-50%); 
        border-radius: 36px 36px 0 0;
        border: 1px solid var(--md-outline);
    }
}
