/* =========================================
   1. GLOBAL RESET & VARIABLES
   ========================================= */
* {
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-page: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* На десктопе не скроллим body */
}

/* =========================================
   2. LAYOUT & HEADER
   ========================================= */
.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* --- Шапка (Header) UPDATED --- */
.app-header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
    position: relative;
    padding-top: 10px;
    padding-left: 50px;  /* Место для левой кнопки */
    padding-right: 50px; /* Симметрия справа */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}
.logo span { color: var(--primary); }

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 5px;
}

/* Кнопка меню в шапке */
.header-btn-menu {
    position: absolute;
    left: 0;
    top: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
}
.header-btn-menu:hover {
    background-color: #f3f4f6;
    color: var(--primary);
}

/* Кнопка "О проекте" */
.btn-about {
    background: transparent;
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 15px;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.2s;
    display: inline-block;
}
.btn-about:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* =========================================
   3. MAIN CONTENT & CARDS
   ========================================= */
.main-content {
    display: flex;
    gap: 20px;
    flex-grow: 1;
    /* overflow: hidden;  <--- ЭТУ СТРОКУ УДАЛИТЬ ИЛИ ЗАКОММЕНТИРОВАТЬ */
    height: auto;      /* <--- ДОБАВИТЬ ЭТО */
    min-height: 0;     /* <--- И ЭТО (на всякий случай) */
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.input-card {
    flex: 1;
    min-width: 350px;
    max-width: 450px;
}

.output-card {
    flex: 2;
    position: relative;
}

/* =========================================
   4. INPUT CONTROLS
   ========================================= */

/* Переключатель режимов */
.mode-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.mode-option { position: relative; cursor: pointer; }
.mode-option input { position: absolute; opacity: 0; }
.mode-content {
    display: block;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
    text-align: center;
}
.mode-title { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.mode-desc { display: block; font-size: 0.75rem; color: var(--text-muted); }

.mode-option input:checked + .mode-content {
    border-color: var(--primary);
    background-color: #eff6ff;
    color: var(--primary);
}
.mode-option input:checked + .mode-content .mode-desc { color: #60a5fa; }

/* Элегантное поле ввода (Container) */
.textarea-container {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 12px;
    /* overflow: hidden; <--- УДАЛИ ЭТУ СТРОКУ, ЧТОБЫ ВЕРНУЛСЯ УГОЛОК */
    transition: box-shadow 0.2s, border-color 0.2s;
    margin-bottom: 20px;
    background: #fff;
    flex-grow: 1;
}

.textarea-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Шапка поля ввода */
.textarea-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: #f9fafb;
    border-bottom: 1px solid var(--border);
}
.header-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.header-actions { display: flex; gap: 5px; }

/* Мини-кнопки (иконки в шапке поля) */
.mini-chip {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: transform 0.1s;
    opacity: 0.7;
}
.mini-chip:hover { background-color: #e5e7eb; opacity: 1; transform: scale(1.1); }

/* Само поле textarea */
.textarea-container textarea {
    width: 100%;
    min-height: 150px; /* Сделали выше по умолчанию */
    border: none;
    border-radius: 0;
    box-shadow: none !important;
    padding: 15px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    background: transparent;
    outline: none;
    resize: vertical; /* <--- ВЕРНУЛИ ВОЗМОЖНОСТЬ РАСТЯГИВАТЬ */
}

/* Тумблер (iOS Style) */
.compare-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    margin-bottom: 25px;
    padding: 0 5px;
}
.ios-switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.ios-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e5e7eb;
    transition: .3s;
    border-radius: 34px;
    border: 1px solid #d1d5db;
}
.slider:before {
    position: absolute;
    content: "";
    height: 24px; width: 24px; left: 2px; bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: #34c759; border-color: #34c759; }
input:checked + .slider:before { transform: translateX(22px); }
.toggle-label { font-size: 0.95rem; color: var(--text-main); font-weight: 500; cursor: pointer; }

/* Tooltip (Подсказка) */
.tooltip-container {
    position: relative;
    display: flex;
    align-items: center;
    cursor: help;
    margin-left: 4px;
    z-index: 10;
}
.info-icon-svg { color: var(--text-muted); opacity: 0.7; transition: color 0.2s; }
.tooltip-container:hover .info-icon-svg { color: var(--primary); opacity: 1; }

.tooltip-text {
    visibility: hidden; opacity: 0;
    width: 240px;
    background-color: #1f2937;
    color: #fff;
    text-align: left;
    border-radius: 8px;
    padding: 12px;
    position: absolute;
    bottom: 135%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    font-size: 0.75rem; line-height: 1.4;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    transition: all 0.3s;
    pointer-events: none;
}
.tooltip-text::after {
    content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px;
    border-width: 5px; border-style: solid; border-color: #1f2937 transparent transparent transparent;
}
.tooltip-container:hover .tooltip-text { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(0); }

/* Кнопка Отправить */
.btn-submit {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: background 0.2s;
}
.btn-submit:hover { background: var(--primary-hover); }

/* Предупреждение о токенах */
.token-warning {
    margin-top: 12px;
    padding: 8px 12px;
    background-color: #fff1f2;
    border: 1px solid #fecdd3;
    border-radius: 8px;
    color: #881337;
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.4;
}
.token-warning span { font-weight: 600; display: block; margin-bottom: 2px; }

/* =========================================
   5. OUTPUT & SIDEBAR & FOOTER
   ========================================= */
.output-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(--border);
}
.output-header h3 { margin: 0; font-size: 1.1rem; }

#result-container {
    flex-grow: 1;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #374151;
}
.placeholder-text { color: var(--text-muted); text-align: center; margin-top: 100px; }

/* Status Dot */
.status-dot { width: 10px; height: 10px; border-radius: 50%; background-color: #e5e7eb; display: inline-block; }
.status-dot.loading { background-color: #f59e0b; box-shadow: 0 0 8px #f59e0b; }
.status-dot.success { background-color: #10b981; box-shadow: 0 0 8px #10b981; }
.status-dot.error { background-color: #ef4444; }

/* Spinner */
.spinner { margin: 50px auto; width: 70px; text-align: center; }
.spinner > div { width: 12px; height: 12px; background-color: var(--primary); border-radius: 100%; display: inline-block; animation: sk-bouncedelay 1.4s infinite ease-in-out both; }
.spinner .bounce1 { animation-delay: -0.32s; }
.spinner .bounce2 { animation-delay: -0.16s; }
@keyframes sk-bouncedelay { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }

/* Sidebar */
.sidebar {
    position: fixed; top: 0; left: 0; height: 100%; width: 320px;
    background: white; box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 300; padding: 20px; display: flex; flex-direction: column;
}
.sidebar.visible { transform: translateX(0); }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
#close-sidebar { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
#history-list li { padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 0.85rem; color: var(--text-main); transition: background 0.2s; }
#history-list li:hover { background: #f9fafb; }
.sidebar-footer { margin-top: auto; padding-top: 15px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }

/* Footer (Credits) */
.app-footer {
    text-align: center; padding: 30px 0 15px; margin-top: auto;
    font-size: 0.75rem; font-family: 'JetBrains Mono', monospace; color: var(--text-muted);
    opacity: 0.6; transition: opacity 0.2s ease;
}
.app-footer:hover { opacity: 1; }
.app-footer a { color: inherit; text-decoration: none; border-bottom: 1px dotted transparent; transition: all 0.2s; }
.app-footer a:hover { color: var(--primary); border-bottom-color: var(--primary); }
.divider { margin: 0 8px; color: #d1d5db; }

/* =========================================
   6. MODAL & DIFF STYLES
   ========================================= */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(4px); align-items: center; justify-content: center; }
.modal.open { display: flex; animation: fadeIn 0.2s ease-out; }
.modal-content { background-color: #fff; padding: 30px; border-radius: 16px; width: 90%; max-width: 500px; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto; }
.close-modal { position: absolute; top: 15px; right: 20px; font-size: 28px; font-weight: bold; color: #aaa; cursor: pointer; line-height: 1; }
.close-modal:hover { color: #000; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* Diff View */
.diff-added { background-color: #d1fae5; color: #065f46; border-bottom: 2px solid #10b981; text-decoration: none; padding: 2px 4px; border-radius: 4px; font-weight: 600; }
.diff-removed { background-color: #fee2e2; color: #b91c1c; text-decoration: line-through; opacity: 0.6; padding: 2px 4px; margin-right: 4px; }

/* Easter Egg */
body.rich-mode { --primary: #16a34a; --primary-hover: #15803d; }
body.rich-mode .logo span { color: #16a34a; }
.money-emoji { position: fixed; top: -50px; z-index: 9999; font-size: 24px; animation: fall linear forwards; pointer-events: none; }
@keyframes fall { 0% { transform: translateY(0) rotate(0deg); opacity: 1; } 100% { transform: translateY(110vh) rotate(360deg); opacity: 0; } }

/* =========================================
   7. MOBILE ADAPTATION (В самом низу)
   ========================================= */
/* Header adjustments - Mobile */
    .app-header {
        margin-bottom: 15px;
        /* Убрали лишние флекс-свойства, они теперь есть в основном классе */
    }
    
    /* Кнопку держим в углу, но чуть поправим позицию */
    .header-btn-menu {
        top: 15px; /* Чуть ниже, чтобы ровно стояла */
        left: 10px;
    }

/* =========================================
   7. MOBILE ADAPTATION
   ========================================= */

/* 1. СКРЫВАЕМ НИЖНЕЕ МЕНЮ НА ПК (Глобально) */
.mobile-nav {
    display: none;
}

/* 2. НАСТРОЙКИ ДЛЯ МОБИЛОК */
@media (max-width: 768px) {
    
    /* Тут включаем меню обратно */
    .mobile-nav {
        display: flex; /* <--- ВАЖНО: показываем на мобиле */
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--border);
        z-index: 1000;
        justify-content: space-around;
        align-items: center;
        padding-bottom: env(safe-area-inset-bottom);
        box-sizing: content-box;
    }

    /* Остальные мобильные стили... */
    body {
        padding-bottom: 80px; 
        height: auto; 
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .container { display: block; padding: 15px; height: auto; }
    .main-content { display: block; height: auto; overflow: visible; }
    .input-card, .output-card { width: 100%; margin-bottom: 20px; min-width: 0; }
    #result-container { overflow: visible; height: auto; }

    /* Скрываем верхние кнопки на мобиле */
    .header-btn-menu, .btn-about { display: none; }

    .app-header {
        padding-top: 10px;
        margin-bottom: 20px;
        padding-left: 10px;
        padding-right: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .nav-item {
        background: none;
        border: none;
        color: var(--text-muted);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 0.65rem;
        font-weight: 500;
        width: 100%;
        height: 100%;
        cursor: pointer;
        padding: 5px 0;
    }

    .nav-item svg {
        width: 24px;
        height: 24px;
        flex-shrink: 0;
        stroke: var(--text-muted);
        margin-bottom: 4px;
        transition: stroke 0.2s;
    }

    .nav-item:active, .nav-item:hover { color: var(--primary); }
    .nav-item:active svg, .nav-item:hover svg { stroke: var(--primary); }
    
    .tooltip-text { width: 200px; left: auto; right: -10px; transform: translateY(10px); }
    .tooltip-container:hover .tooltip-text { transform: translateY(0); }
    .tooltip-text::after { left: auto; right: 15px; }
}