/* =========================================
   0. ШРИФТЫ (FONTS)
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* =========================================
   1. ПЕРЕМЕННЫЕ (VARIABLES)
   ========================================= */
:root {
    /* Цветовая палитра */
    --primary-color: #3b82f6;     /* Синий */
    --primary-hover: #2563eb;
    --success-color: #10b981;     /* Зеленый */
    --danger-color: #ef4444;      /* Красный */
    --warning-color: #f59e0b;     /* Желтый */

    /* Текст и Фоны */
    --text-main: #111827;         /* Более глубокий черный */
    --text-secondary: #6b7280;    /* Серый */
    --bg-page: #f3f4f6;           /* Светло-серый фон страницы */
    --bg-card: #ffffff;
    --border-color: #e5e7eb;

    /* Размеры и Эффекты */
    --radius: 12px;               /* Чуть больше скругление */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --container-width: 1400px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================
   2. БАЗОВЫЕ СТИЛИ (BASE)
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5 { font-weight: 600; color: #111827; letter-spacing: -0.025em; }
a { text-decoration: none; color: var(--primary-color); transition: var(--transition); }
a:hover { color: var(--primary-hover); }

/* =========================================
   3. ЛЕЙАУТ (LAYOUT)
   ========================================= */
.container, .app-container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 24px;
    width: 100%;
}

.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* =========================================
   4. HEADER & NAVIGATION
   ========================================= */
.app-header {
    background: var(--bg-card);
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border: 1px solid rgba(0,0,0,0.03);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-icon {
    font-size: 24px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    color: var(--primary-color);
    width: 48px; height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
}

.header-brand h1 { font-size: 18px; margin: 0; font-weight: 700; }
.header-subtitle { color: var(--text-secondary); font-size: 12px; font-weight: 500; }

.header-profile {
    display: flex;
    align-items: center;
    gap: 20px;
}

.admin-info { text-align: right; }
#adminName { font-weight: 600; display: block; font-size: 14px; }

/* ТАБЫ (Вкладки) */
.nav-tabs-container {
    margin-bottom: 24px;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.nav-tabs-container::-webkit-scrollbar { display: none; }

.tabs {
    display: flex;
    gap: 4px;
    background: #e5e7eb;
    padding: 4px;
    border-radius: 10px;
    width: fit-content;
    white-space: nowrap;
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: #4b5563;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.tab-btn:hover { color: #111827; background: rgba(255,255,255,0.6); }
.tab-btn.active {
    background: var(--bg-card);
    color: var(--primary-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.tab-content { display: none; animation: fadeIn 0.3s ease-out; }
.tab-content.active { display: block; }

/* =========================================
   5. КАРТОЧКИ И ПАНЕЛИ УПРАВЛЕНИЯ
   ========================================= */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}
.card-header h3 { font-size: 18px; margin: 0; font-weight: 700; color: #111827; }
.hint-text { color: var(--text-secondary); font-size: 13px; font-weight: 400; margin-top: 4px; display: block; }

/* --- ПАНЕЛЬ УПРАВЛЕНИЯ В ЗАГОЛОВКЕ --- */
.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

/* Компактный блок загрузки файла */
.compact-upload {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 3px 3px 3px 10px;
    height: 38px;
    box-sizing: border-box;
    transition: var(--transition);
}
.compact-upload:hover { border-color: #9ca3af; }

.compact-upload input[type="file"] {
    font-size: 12px;
    width: 180px;
    border: none;
    background: transparent;
    padding: 0;
    color: var(--text-secondary);
    box-shadow: none;
}
.compact-upload input[type="file"]::file-selector-button { display: none; }

.compact-upload .action-btn {
    height: 30px;
    margin-left: 5px;
    border-radius: 6px;
    font-size: 12px;
    padding: 0 12px;
}

.header-controls .action-btn:not(.compact-upload .action-btn) {
    height: 38px;
    white-space: nowrap;
}
.header-controls .icon-btn {
    width: 38px; height: 38px;
    flex-shrink: 0;
}

/* --- ЗОНА ИМПОРТА --- */
.card.import-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.import-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #f9fafb;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 30px;
    margin-top: 10px;
    box-sizing: border-box;
    transition: var(--transition);
}
.import-area:hover {
    border-color: var(--primary-color);
    background-color: #eff6ff;
}

.import-icon { font-size: 48px; margin-bottom: 16px; line-height: 1; opacity: 0.8; }

.file-upload-group {
    display: flex;
    gap: 12px;
    align-items: center;
    width: 100%;
    max-width: 380px;
}

.custom-file-input {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: var(--transition);
}
.custom-file-input:hover { border-color: var(--primary-color); }
.custom-file-input::file-selector-button {
    margin-right: 12px;
    border: none;
    background: #e5e7eb;
    padding: 6px 14px;
    border-radius: 6px;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.custom-file-input::file-selector-button:hover { background: #d1d5db; }


/* =========================================
   6. КНОПКИ (BUTTONS)
   ========================================= */
.action-btn {
    padding: 9px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: white;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
}
.action-btn:active { transform: translateY(1px); box-shadow: none; }
.action-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

.primary-btn { background: var(--primary-color); }
.primary-btn:hover { background: var(--primary-hover); box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3); }

.success-btn { background: var(--success-color); }
.success-btn:hover { background: #059669; box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.3); }

.danger-btn { background: var(--danger-color); }
.danger-btn:hover { background: #dc2626; box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.3); }

.warning-btn { background: var(--warning-color); color: white; }
.warning-btn:hover { background: #d97706; box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.3); }

.secondary-btn { background: white; border: 1px solid #d1d5db; color: #374151; }
.secondary-btn:hover { background: #f9fafb; border-color: #9ca3af; color: #111827; }

.icon-btn {
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border-color);
    background: white; color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: var(--transition);
    flex-shrink: 0;
}
.icon-btn:hover { background: #f3f4f6; color: var(--primary-color); border-color: var(--primary-color); }
.icon-btn.refresh:hover { transform: rotate(180deg); }

/* Кнопки действий внутри таблицы (маленькие) */
.btn-icon {
    width: 30px; height: 30px;
    border-radius: 6px;
    display: inline-flex;
    justify-content: center; align-items: center;
    border: 1px solid transparent;
    background: transparent;
    transition: var(--transition);
    cursor: pointer;
    font-size: 14px;
}
.btn-icon:hover { background: #f3f4f6; transform: scale(1.1); }
.btn-edit { color: #3b82f6; }
.btn-edit:hover { background: #eff6ff; }
.btn-delete { color: #ef4444; }
.btn-delete:hover { background: #fef2f2; }
.btn-check { color: #10b981; }
.btn-check:hover { background: #ecfdf5; }
.btn-adjust { color: #8b5cf6; }
.btn-adjust:hover { background: #f5f3ff; }


.logout-btn {
    background: transparent; border: 1px solid #fee2e2; color: var(--danger-color); padding: 8px 16px;
    border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: var(--transition);
    white-space: nowrap; font-weight: 500;
}
.logout-btn:hover { background: #fee2e2; }

/* =========================================
   7. ТАБЛИЦЫ (TABLES)
   ========================================= */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
table { width: 100%; border-collapse: collapse; min-width: 600px; background: white; }

th {
    text-align: left; padding: 14px 16px;
    color: #4b5563; font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.05em;
    background: #f9fafb; border-bottom: 1px solid var(--border-color);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

tr:hover td { background: #f9fafb; }
tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }

/* Sticky Header */
.sticky-header-table { position: relative; width: 100%; border-collapse: separate; border-spacing: 0; }
.sticky-header-table thead th { position: sticky; top: 0; background: #f9fafb; z-index: 10; }

/* Sorting Icons */
th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 28px; transition: background 0.2s; }
th.sortable:hover { background: #f3f4f6; color: #111827; }
th.sortable::after {
    content: '↕'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    opacity: 0.3; font-size: 11px;
}
th.sortable.sort-asc::after { content: '▲'; opacity: 1; color: var(--primary-color); }
th.sortable.sort-desc::after { content: '▼'; opacity: 1; color: var(--primary-color); }

/* Toolbar */
.toolbar-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toolbar-controls input, .toolbar-controls select {
    border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; height: 38px;
}

/* =========================================
   8. ФОРМЫ (FORMS)
   ========================================= */
.styled-form .form-row { display: flex; gap: 20px; margin-bottom: 20px; }
.styled-form .form-group { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.styled-form .form-row.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; }

.form-group label { font-size: 13px; font-weight: 600; color: #374151; }

input, select, textarea {
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    transition: var(--transition);
    width: 100%;
    color: #1f2937;
    background-color: #fff;
    box-shadow: var(--shadow-sm);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.full-width { width: 100%; }

/* =========================================
   9. БЕЙДЖИ И СТАТУСЫ (BADGES)
   ========================================= */
.role-badge {
    font-size: 11px; text-transform: uppercase; font-weight: 700; padding: 4px 10px; border-radius: 20px;
    letter-spacing: 0.05em; display: inline-block;
    border: 1px solid transparent;
}
.role-badge.admin { background-color: #fef2f2; color: #991b1b; border-color: #fecaca; }
.role-badge.financier { background-color: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.role-badge.accountant { background-color: #fffbeb; color: #92400e; border-color: #fde68a; }
.role-badge.user { background-color: #ecfdf5; color: #065f46; border-color: #a7f3d0; }

.status-card { margin-bottom: 25px; }
.period-state {
    padding: 24px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: space-between;
    gap: 20px; flex-wrap: wrap;
    box-shadow: var(--shadow);
}
.period-state.open { background: linear-gradient(to right, #ecfdf5, #d1fae5); border: 1px solid #a7f3d0; }
.period-state.closed { background: linear-gradient(to right, #fef2f2, #fee2e2); border: 1px solid #fecaca; }

.state-icon { font-size: 32px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }
.state-info h2 { font-size: 18px; margin: 0 0 4px 0; color: #111827; }
.state-info p { margin: 0; color: #4b5563; }
.new-period-form { display: flex; gap: 10px; flex-wrap: wrap; }

.toolbar {
    background: #fffbeb; border: 1px solid #fcd34d; padding: 12px 16px; border-radius: 8px;
    margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 12px;
}
.checkbox-filter {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    font-weight: 600; color: #92400e; user-select: none;
}
.checkbox-filter input { width: 18px; height: 18px; cursor: pointer; accent-color: #f59e0b; }

.pagination { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;}
.page-btn {
    border: 1px solid #d1d5db; background: white; padding: 6px 12px;
    border-radius: 6px; cursor: pointer; transition: var(--transition);
    font-size: 13px; font-weight: 500;
}
.page-btn:hover:not(:disabled) { background: #f3f4f6; border-color: #9ca3af; }
.page-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #f9fafb; }

/* Тарифы */
.tariffs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 24px; }
.tariff-item {
    background: #ffffff; padding: 16px; border-radius: 10px;
    border: 1px solid #e5e7eb; transition: var(--transition);
    box-shadow: var(--shadow-sm);
}
.tariff-item:hover { border-color: var(--primary-color); }
.tariff-item.highlight { border-color: #bfdbfe; background: #eff6ff; }
.tariff-actions { grid-column: 1 / -1; margin-top: 16px; text-align: right; }

/* =========================================
   10. МОДАЛЬНЫЕ ОКНА И УВЕДОМЛЕНИЯ
   ========================================= */
#toast-container { position: fixed; bottom: 30px; right: 30px; z-index: 9999; display: flex; flex-direction: column; gap: 12px; }
.toast {
    padding: 16px 24px; border-radius: 10px; color: white; font-weight: 500;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    word-break: break-word; max-width: 400px;
    font-size: 14px;
    display: flex; align-items: center;
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px); /* Красивое размытие фона */
    z-index: 1000; display: none; justify-content: center; align-items: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}
.modal-overlay.open { display: flex; }

.modal-window {
    background: white; width: 500px; max-width: 100%;
    border-radius: 16px; /* Более скругленные углы */
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: zoomIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    display: flex; flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    background: #fff; padding: 20px 24px; border-bottom: 1px solid #f3f4f6;
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; color: #111827; }
.close-icon {
    background: none; border: none; font-size: 28px; cursor: pointer;
    color: #9ca3af; transition: color 0.2s; line-height: 1;
}
.close-icon:hover { color: #111827; }

.modal-form { padding: 24px; overflow-y: auto; }

.info-box {
    background: #eff6ff; padding: 20px; margin: 24px 0; border-radius: 10px;
    border-left: 4px solid var(--primary-color);
}
.readings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 16px; margin-top: 12px; font-weight: 600; font-size: 14px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

.modal-footer {
    padding: 20px 24px; border-top: 1px solid #f3f4f6;
    display: flex; justify-content: flex-end; gap: 12px; background: #f9fafb; flex-shrink: 0;
    flex-wrap: wrap;
}

/* =========================================
   11. СТРАНИЦЫ (PAGES)
   ========================================= */
/* Login */
#loginForm {
    background: white; padding: 48px; border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%; max-width: 420px;
    margin: 0 20px;
}
#loginForm h1 { text-align: center; color: #111827; font-size: 28px; margin-bottom: 8px; letter-spacing: -0.025em; }
#loginForm .form-group { margin-bottom: 20px; }
#loginForm button { margin-top: 12px; padding: 14px; font-size: 16px; background: var(--primary-color); width: 100%; border-radius: 10px; }
#loginForm button:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* Portal */
.portal-body {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    min-height: 100vh; display: flex; justify-content: center;
    align-items: center; font-family: 'Inter', sans-serif; margin: 0; padding: 24px;
}
.portal-container { max-width: 1100px; width: 100%; text-align: center; animation: fadeIn 0.8s ease-out; }
.portal-header h1 { font-size: 3rem; color: #111827; margin-bottom: 12px; font-weight: 800; letter-spacing: -0.05em; }
.portal-header p { color: #6b7280; font-size: 1.25rem; margin-bottom: 60px; max-width: 600px; margin-left: auto; margin-right: auto; }
.portal-grid { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; }
.portal-card {
    background: white; width: 260px; height: 260px; border-radius: 24px;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-decoration: none; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative; overflow: hidden; border: 1px solid rgba(0,0,0,0.05);
}
.portal-card:hover {
    transform: translateY(-12px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border-color: var(--primary-color);
}
.card-icon { font-size: 4.5rem; color: var(--primary-color); margin-bottom: 24px; transition: transform 0.3s; }
.portal-card:hover .card-icon { transform: scale(1.1); }
.card-title { font-size: 1.4rem; font-weight: 700; color: #111827; margin-bottom: 8px; }
.card-desc { font-size: 0.9rem; color: #6b7280; padding: 0 20px; line-height: 1.4; }
.portal-footer { margin-top: 80px; color: #9ca3af; font-size: 0.9rem; }

/* Утилиты */
.mt-20 { margin-top: 20px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideUp { from { transform: translateY(50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes zoomIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* =========================================
   12. АДАПТИВНОСТЬ (RESPONSIVE)
   ========================================= */
@media (max-width: 992px) {
    .grid-2-col { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app-container, .container { padding: 12px; }
    .card { padding: 16px; }

    /* Шапка */
    .app-header { flex-direction: column; align-items: flex-start; gap: 16px; padding: 16px; }
    .header-profile { width: 100%; justify-content: space-between; }
    .admin-info { text-align: left; }

    /* Хедер Контролы (мобильная версия) */
    .header-controls {
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-start;
    }
    .header-controls > div, .header-controls > button, .header-controls > input {
        width: 100%;
        justify-content: center;
    }
    .compact-upload { width: 100%; }
    .compact-upload input[type="file"] { flex: 1; }

    /* Формы */
    .styled-form .form-row { flex-direction: column; gap: 16px; margin-bottom: 0; }
    .styled-form .form-group { margin-bottom: 16px; }
    .styled-form .form-row.three-col { display: flex; flex-direction: column; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    input, select { font-size: 16px; } /* Анти-зум на iOS */

    /* Тулбар таблицы */
    .toolbar-controls { flex-direction: column; align-items: stretch !important; width: 100%; }
    .toolbar-controls input[type="text"] { width: 100%; }

    /* Модалки */
    .modal-window { width: 100% !important; height: auto; border-radius: 20px 20px 0 0; margin-top: auto; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-footer { flex-direction: column; gap: 12px; padding-bottom: 30px; } /* Учет Safe Area на iOS */
    .modal-footer button { width: 100%; }

    td .btn-icon { margin-bottom: 6px; }
    .portal-header h1 { font-size: 2rem; }
    .portal-card { width: 100%; height: auto; padding: 24px 0; }
}

@media (max-width: 480px) {
    .tabs { width: 100%; gap: 0; }
    .tab-btn { flex: 1; text-align: center; padding: 8px 4px; font-size: 12px; }
    .period-state { flex-direction: column; text-align: center; }
    .new-period-form input, .new-period-form button { width: 100%; }
    .tariffs-grid { grid-template-columns: 1fr; }
    .tariff-actions { text-align: stretch; }
    .tariff-actions button { width: 100%; }
}

/* =========================================
   ДОЛГИ (Импорт из 1С)
   ========================================= */
.upload-area {
    display: flex; flex-direction: column; gap: 16px;
    background: #f9fafb; padding: 24px;
    border-radius: 12px; border: 2px dashed #d1d5db;
    transition: var(--transition);
}
.upload-area:hover { border-color: var(--primary-color); background: #eff6ff; }

.upload-row { display: flex; gap: 16px; align-items: center; width: 100%; flex-wrap: wrap; }
.upload-result-box { margin-top: 16px; display: none; animation: fadeIn 0.3s ease-in-out; }
.account-selector { display: flex; gap: 24px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.radio-label { cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 600; color: #374151; }
.radio-label input { width: 18px; height: 18px; accent-color: var(--primary-color); margin: 0; }


/* =========================================
   13. ДОПОЛНИТЕЛЬНЫЕ UI-КОМПОНЕНТЫ (ФИНАЛ)
   ========================================= */

/* Анимация и состояние загрузки кнопок (из dom.js) */
.action-btn.loading-state {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    position: relative;
    color: transparent !important; /* Прячем текст, показываем спиннер */
}
.action-btn.loading-state::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 18px;
    margin-left: -9px;
    margin-top: -9px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Стили для чекбоксов массового выделения в таблицах (из table-controller.js) */
.row-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
    margin: 0;
    display: block;
}

/* Красивый скроллбар для модальных окон (результаты импорта) */
.modal-form::-webkit-scrollbar {
    width: 6px;
}
.modal-form::-webkit-scrollbar-track {
    background: transparent;
}
.modal-form::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
.modal-form::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Запрет выделения текста на элементах управления (защита от синего фона при быстрых кликах) */
.tab-btn, .close-icon, th.sortable {
    user-select: none;
    -webkit-user-select: none;
}