:root {
    --bg: #f6f6f4;
    --surface: #ffffff;
    --ink: #1c1c1a;
    --ink-soft: #6b6b66;
    --line: #e6e5e1;
    --accent: #e8721c;
    --accent-hover: #d0630f;
    --accent-soft: #fdf0e6;
    --fte: #fff6ec;
    --total: #f3f1ec;
    --danger: #c0392b;
    --success: #2e7d5b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.4;
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; color: var(--accent); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
    padding: 8px 14px;
    text-decoration: none;
    color: var(--ink-soft);
    border-radius: 6px;
    font-weight: 500;
}
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }

.user-box { position: relative; }
.user-trigger {
    display: flex; align-items: center; gap: 10px;
    background: none; border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 12px; cursor: pointer; font-family: inherit; font-size: 13px;
}
.user-trigger:hover { background: var(--bg); }
.user-email { color: var(--ink-soft); }
.chevron { color: var(--ink-soft); font-size: 10px; }
.user-role {
    font-size: 11px; text-transform: uppercase; font-weight: 700;
    padding: 2px 8px; border-radius: 4px;
}
.role-admin { background: var(--accent); color: #fff; }
.role-viewer { background: var(--line); color: var(--ink-soft); }

.user-menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,0.14);
    min-width: 200px; padding: 6px; display: none; z-index: 100;
}
.user-menu.open { display: block; }
.menu-item {
    display: block; padding: 10px 12px; text-decoration: none;
    color: var(--ink); border-radius: 6px; font-size: 14px;
}
.menu-item:hover { background: var(--bg); }
.menu-item.logout { color: var(--danger); }
.menu-divider { height: 1px; background: var(--line); margin: 6px 0; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.last-update { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }

.btn-refresh-data, .btn-visualize {
    border: 1px solid var(--line); background: var(--surface);
    padding: 6px 12px; border-radius: 6px; cursor: pointer;
    color: var(--accent); font-weight: 600; font-size: 12px; font-family: inherit;
}
.btn-refresh-data:hover, .btn-visualize:hover { background: var(--accent-soft); }
.btn-refresh-data:disabled { opacity: 0.5; cursor: default; }
.btn-visualize { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn-visualize:hover { background: var(--accent-hover); }

/* ---------- Модалка визуализации ---------- */
.viz-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center; z-index: 500;
}
.viz-overlay.open { display: flex; }
.viz-modal {
    background: var(--surface); border-radius: 14px; width: 90%; max-width: 900px;
    max-height: 90vh; overflow-y: auto; padding: 24px;
}
.viz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.viz-head h2 { font-size: 18px; }
.viz-close {
    background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-soft);
}
.viz-close:hover { color: var(--ink); }
.viz-settings { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.viz-field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 180px; }
.viz-field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.viz-field select {
    border: 1px solid var(--line); border-radius: 6px; padding: 8px;
    font-size: 13px; font-family: inherit;
}
.viz-hint { font-size: 11px; color: var(--ink-soft); }
.viz-canvas-wrap { height: 380px; margin-bottom: 16px; }
.viz-actions { display: flex; justify-content: flex-end; }

/* ---------- Прелоадер ---------- */
.loader-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,0.85);
    backdrop-filter: blur(2px);
    display: none; align-items: center; justify-content: center; z-index: 900;
}
.loader-overlay.show { display: flex; }
.loader-box {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 14px; padding: 32px 40px; text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.12); max-width: 340px;
}
.spinner {
    width: 36px; height: 36px; margin: 0 auto 16px;
    border: 3px solid var(--line); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-weight: 600; margin-bottom: 6px; }
.loader-hint { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

/* ---------- Скелетон (каркас при загрузке) ---------- */
.skeleton-page { padding: 8px 0; }
.skeleton-title, .skeleton-bar, .skeleton-table {
    background: linear-gradient(90deg, #eeece8 25%, #f6f5f2 50%, #eeece8 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 8px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-title { height: 28px; width: 320px; margin-bottom: 20px; }
.skeleton-bar { height: 56px; margin-bottom: 16px; }
.skeleton-table { height: 420px; }

/* ---------- Личный кабинет ---------- */
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.account-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; padding: 20px;
}
.account-card h2 { font-size: 15px; margin-bottom: 14px; }
.profile-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.profile-row:last-child { border-bottom: none; }
.profile-label { color: var(--ink-soft); }
.account-action {
    display: inline-block; color: var(--accent); text-decoration: none;
    font-weight: 600; font-size: 14px;
}
.account-action:hover { text-decoration: underline; }
.account-hint { color: var(--ink-soft); font-size: 12px; margin-top: 6px; }

/* ---------- Toast-уведомления ---------- */
#toast-container {
    position: fixed; top: 70px; right: 20px; z-index: 1000;
    display: flex; flex-direction: column; gap: 10px;
    max-width: 360px;
}
.toast {
    background: var(--surface); border-left: 4px solid var(--ink-soft);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 14px 18px; border-radius: 8px; font-size: 14px;
    opacity: 0; transform: translateX(20px); transition: all 0.3s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }

/* ---------- Кабинет админа ---------- */
.admin-add {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 8px; padding: 20px; margin-bottom: 20px;
}
.admin-add h2 { font-size: 15px; margin-bottom: 12px; }
.add-form { display: flex; gap: 10px; flex-wrap: wrap; }
.add-form input, .add-form select {
    border: 1px solid var(--line); border-radius: 6px;
    padding: 8px 12px; font-size: 14px; font-family: inherit;
}
.add-form input[type=email] { flex: 1; min-width: 220px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-role, .btn-remove {
    border: 1px solid var(--line); background: var(--surface);
    padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
    font-weight: 600;
}
.btn-role { color: var(--accent); }
.btn-role:hover { background: var(--accent-soft); }
.btn-remove { color: var(--danger); }
.btn-remove:hover { background: #fdecea; }
.locked { color: var(--ink-soft); font-size: 12px; }
.muted { color: var(--ink-soft); font-size: 13px; }

/* ---------- Страница ошибки ---------- */
.error-box {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: 48px; text-align: center;
    max-width: 520px; margin: 60px auto;
}
.error-icon { font-size: 48px; margin-bottom: 16px; }
.error-box h1 { font-size: 20px; margin-bottom: 12px; }
.error-detail {
    color: var(--danger); background: #fdecea; padding: 12px;
    border-radius: 8px; margin-bottom: 16px; font-size: 13px; word-break: break-word;
}
.error-hint { color: var(--ink-soft); font-size: 13px; margin-bottom: 24px; line-height: 1.5; }

/* ---------- Content ---------- */
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }

.dash-header {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 16px;
}
.dash-header h1 { font-size: 20px; font-weight: 700; }
.dash-meta { color: var(--ink-soft); font-size: 13px; }
.header-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.btn-export {
    border: 1px solid var(--line); background: var(--surface);
    color: var(--accent); text-decoration: none; font-weight: 600;
    font-size: 12px; padding: 6px 12px; border-radius: 6px;
}
.btn-export:hover { background: var(--accent-soft); }

/* ---------- Filters ---------- */
.filter-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 8px; padding: 12px 16px; margin-bottom: 16px;
}
.filter-label { color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.filter-bar select, .filter-bar input {
    border: 1px solid var(--line); border-radius: 6px;
    padding: 6px 10px; font-size: 13px; font-family: inherit;
}
.btn-apply {
    background: var(--accent); color: #fff; border: none;
    padding: 7px 16px; border-radius: 6px; cursor: pointer;
    font-weight: 600; font-size: 13px;
}
.btn-apply:hover { opacity: 0.9; }

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 8px; overflow: auto;
}
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th {
    background: var(--accent); color: #fff; font-weight: 600;
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px;
    position: sticky; top: 0;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-head { font-weight: 600; }
.total-col { font-weight: 700; background: var(--accent-soft); }

.pivot tbody tr:hover { background: #fafbfc; }
.fte-row { background: var(--fte); font-weight: 600; }
.fte-row:hover { background: #ffeecb !important; }
.total-row { background: var(--total); font-weight: 700; border-top: 2px solid var(--accent); }
.total-row:hover { background: #dde dd !important; }

.grp-employee_group .row-head { padding-left: 24px; color: var(--ink-soft); }
.section-row td {
    background: var(--total); font-weight: 700; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft);
    padding: 6px 14px;
}

.data-table tbody tr:hover { background: #fafbfc; }
.empty { text-align: center; color: var(--ink-soft); padding: 32px; }

.dash-footer { color: var(--ink-soft); font-size: 12px; margin-top: 12px; }

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #e8721c 0%, #b85410 100%);
}
.login-card {
    background: #fff; padding: 40px; border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center; max-width: 380px; width: 100%;
}
.login-logo {
    width: 56px; height: 56px; background: var(--accent); color: #fff;
    border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800; margin: 0 auto 20px;
}
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-sub { color: var(--ink-soft); margin-bottom: 24px; }
.btn-login {
    display: block; background: var(--accent); color: #fff;
    text-decoration: none; padding: 12px; border-radius: 8px;
    font-weight: 600; margin-bottom: 16px;
}
.btn-login:hover { opacity: 0.92; }
.login-note { color: var(--ink-soft); font-size: 12px; }

.login-divider {
    display: flex; align-items: center; gap: 10px;
    color: var(--ink-soft); font-size: 12px; margin: 16px 0;
}
.login-divider::before, .login-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--line);
}
.local-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.local-form input {
    border: 1px solid var(--line); border-radius: 8px;
    padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.btn-local {
    background: var(--ink); color: #fff; border: none;
    padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn-local:hover { opacity: 0.9; }
.login-error {
    background: #fdecea; color: var(--danger); padding: 12px;
    border-radius: 8px; margin-bottom: 16px; font-size: 13px;
}

@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 12px; }
    .nav { order: 3; width: 100%; overflow-x: auto; }
    .dash-header { flex-direction: column; gap: 4px; }
}
