/* CSS Variables for Sleek Theme */
:root {
    /* Цвета по умолчанию (светлая тема) */
    --bg-color: #f1f5f9;
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-color: #0f172a;
    --text-muted: #64748b;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --border-color: rgba(226, 232, 240, 0.8);
    --shadow: 0 8px 32px 0 rgba(148, 163, 184, 0.08);
    --backdrop-blur: 12px;
    
    /* Telegram Theme Overrides (если доступны) */
    --tg-bg: var(--tg-theme-bg-color, var(--bg-color));
    --tg-text: var(--tg-theme-text-color, var(--text-color));
    --tg-hint: var(--tg-theme-hint-color, var(--text-muted));
    --tg-link: var(--tg-theme-link-color, var(--primary-color));
    --tg-btn: var(--tg-theme-button-color, var(--primary-color));
    --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-sec-bg: var(--tg-theme-secondary-bg-color, #f8fafc);
}

/* Настройки темной темы Telegram */
body.class-dark-theme,
body[theme="dark"] {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #3b82f6;
    --border-color: rgba(51, 65, 85, 0.5);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* Принудительно используем переменные темы Telegram */
body {
    background-color: var(--tg-bg);
    color: var(--tg-text);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

* {
    box-sizing: border-box;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--tg-btn);
}

.user-info h1 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.status-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 20px;
}

.status-badge.connected {
    background-color: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.btn-icon {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--tg-text);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    box-shadow: var(--shadow);
}

.btn-icon:active {
    transform: scale(0.95);
}

.btn-icon svg.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* TABS */
.app-nav {
    display: flex;
    background: var(--tg-sec-bg);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.nav-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-hint);
    cursor: pointer;
    border-radius: 8px;
    text-align: center;
}

.nav-tab.active {
    background: var(--card-bg);
    color: var(--tg-btn);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* PANES */
.tab-pane {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.tab-pane.active {
    display: flex;
}

/* CARDS */
.section-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    box-shadow: var(--shadow);
}

.section-card h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 8px 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.description-text {
    font-size: 13px;
    color: var(--tg-hint);
    margin: 0 0 16px 0;
    line-height: 1.4;
}

.counter-badge {
    background: var(--tg-sec-bg);
    color: var(--tg-text);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* EMAIL CARDS */
.email-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    box-shadow: var(--shadow);
}

.email-card:active {
    transform: scale(0.99);
}

.email-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.email-sender {
    font-weight: 600;
    font-size: 14px;
    max-width: 70%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-date {
    font-size: 11px;
    color: var(--tg-hint);
}

.email-subject {
    font-size: 13px;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-tags {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.tag {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.tag.otp {
    background-color: rgba(37, 99, 235, 0.15);
    color: #2563eb;
}

.tag.nb {
    background-color: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

/* SKELETONS */
.skeleton-card {
    height: 90px;
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--border-color) 50%, var(--card-bg) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* EMPTY STATES */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--tg-hint);
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 6px 0;
    color: var(--tg-text);
}

.empty-state p {
    font-size: 13px;
    margin: 0;
    line-height: 1.4;
}

/* ADDRESS LIST */
.address-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.address-item {
    background: var(--tg-sec-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.address-text {
    font-family: monospace;
    font-size: 13px;
    font-weight: 600;
    word-break: break-all;
    max-width: 75%;
}

.address-actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--tg-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-small:active {
    transform: scale(0.9);
}

.btn-small.delete {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.2);
}

/* BUTTONS */
.btn-primary {
    background: var(--tg-btn);
    color: var(--tg-btn-text);
    border: none;
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.btn-primary:active {
    opacity: 0.9;
    transform: scale(0.99);
}

.btn-secondary {
    background: var(--tg-sec-bg);
    color: var(--tg-text);
    border: 1px solid var(--border-color);
    padding: 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
}

.btn-secondary:active {
    transform: scale(0.98);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
}

.btn-danger:active {
    background: var(--danger-hover);
    transform: scale(0.98);
}

/* SETTINGS SWITCH */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-info h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 2px 0;
}

.setting-info p {
    font-size: 12px;
    color: var(--tg-hint);
    margin: 0;
    line-height: 1.3;
    max-width: 80%;
}

/* Switch Slider */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    flex-shrink: 0;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--tg-btn);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* MODAL */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    background: var(--tg-bg);
    width: 100%;
    max-width: 600px;
    max-height: 92vh;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title-area h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.modal-meta {
    font-size: 12px;
    color: var(--tg-hint);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.close-button {
    border-radius: 50%;
}

.modal-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* HIGHLIGHT BOXES (OTP/Track) */
.highlight-box {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.highlight-box.hidden {
    display: none;
}

.highlight-box.track-box {
    background: rgba(249, 115, 22, 0.08);
    border-color: rgba(249, 115, 22, 0.2);
}

.highlight-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--tg-hint);
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.highlight-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--tg-btn);
}

/* EMAIL BODY WEBVIEW (IFRAME) */
.email-body-container {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: white; /* Всегда белый фон для писем */
    overflow: hidden;
    height: 380px;
    display: flex;
}

#email-body-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
}

.modal-footer button {
    flex: 1;
}

/* CUSTOM ADDRESS INPUTS */
.custom-address-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.input-group {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--tg-sec-bg);
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.input-group:focus-within {
    border-color: var(--tg-btn);
}

.input-group input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--tg-text);
    outline: none;
}

.input-group input::placeholder {
    color: var(--tg-hint);
    opacity: 0.7;
}

.domain-addon {
    padding: 12px 14px;
    background: var(--border-color);
    color: var(--tg-hint);
    font-family: monospace;
    font-size: 13px;
    font-weight: 600;
    border-left: 1px solid var(--border-color);
}

/* PREMIUM TOAST NOTIFICATION */
.custom-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translate(-50%, 50px);
    background: rgba(15, 23, 42, 0.9);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 500;
    z-index: 1100;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.custom-toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* PREMIUM UNREAD BADGE */
.unread-badge {
    background-color: var(--danger-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1;
    display: inline-block;
}

.unread-badge.hidden {
    display: none;
}

/* READ EMAIL CARD STYLING */
.email-card.read {
    background: rgba(255, 255, 255, 0.45);
    border-color: rgba(226, 232, 240, 0.5);
    box-shadow: none;
}

body.class-dark-theme .email-card.read,
body[theme="dark"] .email-card.read {
    background: rgba(30, 41, 59, 0.4);
    border-color: rgba(51, 65, 85, 0.3);
}

.email-card.read .email-sender {
    color: var(--text-muted);
    font-weight: 500;
}

.email-card.read .email-subject {
    color: var(--text-muted);
    opacity: 0.8;
}

/* STAR / FAVORITE BUTTON */
.email-card-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.star-btn {
    background: none;
    border: none;
    color: var(--tg-hint);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: transform 0.2s ease, color 0.2s ease;
}

.star-btn:active {
    transform: scale(0.8);
}

.star-btn.starred {
    color: #f59e0b; /* Золотистый цвет */
}

/* SELECTION AND MULTI-DELETE TOOLBAR */
.inbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.inbox-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.selection-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--tg-sec-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.selection-actions {
    display: flex;
    gap: 8px;
}

.btn-small-text {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    width: auto;
}

.selection-toolbar.hidden {
    display: none;
}

/* EMAIL CARD IN SELECTION MODE */
.email-card {
    position: relative;
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
}

.email-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0; /* Обеспечивает работу ellipsis */
}

.selection-checkbox-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.email-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 2px solid var(--border-color);
    outline: none;
    cursor: pointer;
    accent-color: var(--tg-btn);
}

/* Красный маркер для непрочитанных писем */
.email-card:not(.read) .email-sender::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--danger-color, #ef4444);
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    box-shadow: 0 0 6px var(--danger-color);
}
