/* ===== Monochrome Slate — Light Sidebar ===== */

/* Screen-reader only — visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Self-hosted Inter font — fallback */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/inter-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/inter-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/inter-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/inter-700.woff2') format('woff2'); }
/* Nunito — rounded terminals, matches purple bus app reference */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&display=swap');

:root {
    --gray-50:  #faf9fc;
    --gray-100: #f3f1f6;
    --gray-200: #e8e5f0;
    --gray-300: #d5d1e0;
    --gray-400: #a9a3b8;
    --gray-500: #7c7591;
    --gray-600: #5c5672;
    --gray-700: #46415a;
    --gray-800: #2e2a3d;
    --gray-900: #1e1a2d;
    --gray-950: #0f0d18;

    --primary:  #9e7ae6;
    --primary-dark: #8b66d9;
    --primary-light: #b796ef;
    --accent:   #42d490;

    --bg:       #f9f9fb;
    --card:     #ffffff;
    --text:     #4a3d6b;
    --text-secondary: #6b5d8a;
    --text-muted: #8578ae;
    --text-faint: #a69dc4;
    --border:   #e8dff2;

    --danger:    #ef4444;
    --danger-bg: #fef2f2;
    --success:   #42d490;
    --success-bg:#ecfdf5;

    --font: 'Nunito', 'Inter', system-ui, -apple-system, sans-serif;
    --radius: 16px;
    --radius-sm: 12px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }
input, select, button, textarea { -webkit-appearance: none; -moz-appearance: none; appearance: none; }

body {
    font-family: var(--font);
    background: var(--bg);
    margin: 0;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    font-weight: 400;
}

h2 {
    color: var(--text);
    margin: 0 0 20px;
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--gray-300);
    text-underline-offset: 2px;
    transition: text-decoration-color 0.1s;
}
a:hover { text-decoration-color: var(--text); }

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar (light) ===== */
.sidebar {
    width: 232px;
    min-width: 232px;
    background: linear-gradient(180deg, #b796ef 0%, #9e7ae6 40%, #8b66d9 100%);
    border-right: none;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 28px 20px 24px;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 8px;
    gap: 2px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: rgba(255,255,255,0.85);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.sidebar nav a.active {
    background: rgba(255,255,255,0.22);
    color: #fff;
    font-weight: 700;
}

.sidebar nav a .nav-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: transparent;
    border: none;
    transition: background 0.15s;
}
.sidebar nav a .nav-icon svg {
    opacity: 0.85;
    transition: opacity 0.15s;
}

.sidebar nav a:hover .nav-icon {
    background: rgba(255,255,255,0.1);
}
.sidebar nav a:hover .nav-icon svg {
    opacity: 1;
}

.sidebar nav a.active .nav-icon {
    background: rgba(255,255,255,0.15);
}
.sidebar nav a.active .nav-icon svg {
    opacity: 1;
}

.nav-icon-plain {
    background: none !important;
    border: none !important;
    width: auto !important;
    height: auto !important;
    border-radius: 0 !important;
}

.sidebar-logout {
    padding: 14px 20px;
    color: rgba(255,255,255,0.5) !important;
    font-size: 0.75rem;
    font-weight: 500;
    border-top: 1px solid rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    transition: color 0.15s;
    background: none;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.12);
    cursor: pointer;
    font-family: var(--font);
    width: 100%;
    box-sizing: border-box;
}

.sidebar-logout:hover {
    color: rgba(255,255,255,0.8) !important;
    background: rgba(255,255,255,0.08);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: 232px;
    min-height: 100vh;
    max-width: 100%;
    padding: 0;
}

/* Gradient banner */
.page-header {
    background: var(--bg);
    padding: 28px 40px 44px;
    margin: 0;
    border-bottom: none;
}
.page-header h2 { margin: 0; color: var(--primary-dark); font-size: 1.125rem; font-weight: 600; display: flex; align-items: center; gap: 12px; text-shadow: 0 1px 3px rgba(139,102,217,0.15); }
.page-header .page-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: transparent !important;
    border: 1.5px solid var(--primary-dark);
    box-shadow: 0 2px 6px rgba(139,102,217,0.12);
}
.page-header .page-icon svg { width: 18px; height: 18px; stroke: var(--primary-dark); stroke-width: 2; }
.page-subtitle { margin: 4px 0 0 48px; font-size: 0.8125rem; color: var(--text-muted); font-weight: 400; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: 24px;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04), 0 2px 12px rgba(0,0,0,0.03);
    padding: 28px 32px 32px;
    margin: -20px 40px 24px;
    position: relative;
    z-index: 1;
}

/* Empty state placeholder */
.empty-state {
    text-align: center;
    padding: 48px 24px 24px;
    color: #9898a6;
}
.empty-state svg { margin-bottom: 12px; opacity: .5; }
.empty-state p { margin: 0; font-size: 15px; font-weight: 500; color: #71717a; }
.empty-state .empty-state-hint { margin-top: 4px; font-size: 13px; font-weight: 400; color: #a1a1aa; }

/* Pages without .card get padding on content directly */
.main-content > *:not(.page-header):not(.card) {
    padding-left: 40px;
    padding-right: 40px;
}

/* ===== Buttons — pill-shaped, ref-style ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border: 1.5px solid var(--gray-800);
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: var(--font);
    transition: all 0.15s ease;
    line-height: 1.5;
    background: var(--card);
    color: var(--gray-800);
    text-decoration: none;
}

.btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-900);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(139,92,246,0.25);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(139,92,246,0.3);
}

.btn-danger {
    color: var(--danger);
    background: var(--card);
    border-color: #fecaca;
}
.btn-danger:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
}

.btn-success {
    color: #fff;
    background: var(--success);
    border-color: var(--success);
    box-shadow: 0 2px 8px rgba(16,185,129,0.25);
}
.btn-success:hover {
    background: #059669;
    border-color: #059669;
}

.btn-info,
.btn-secondary {
    color: var(--gray-800);
    background: var(--card);
    border-color: var(--gray-800);
}
.btn-info:hover,
.btn-secondary:hover {
    background: var(--gray-100);
    border-color: var(--gray-900);
}

/* Icon buttons — filled circles */
.btn-icon {
    padding: 0;
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    font-size: 0.9375rem;
    line-height: 1;
    border: none;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover { transform: scale(1.08); filter: brightness(1.1); }
.btn-icon.btn-info { background: var(--primary); color: #fff; border: none; }
.btn-icon.btn-info:hover { background: var(--primary-dark); }
.btn-icon.btn-danger { background: #fee2e2; color: #ef4444; border: none; box-shadow: none; }
.btn-icon.btn-danger:hover { background: #fecaca; color: #dc2626; }
.btn-icon.btn-success { background: var(--success); color: #fff; border: none; box-shadow: none; }
.btn-icon.btn-success:hover { background: #059669; }
.btn-icon.btn-danger.cancel-btn { background: var(--gray-100); color: var(--gray-500); border: none; }
.btn-icon.btn-danger.cancel-btn:hover { background: var(--gray-200); color: var(--gray-700); }

/* ===== Tables ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 4px;
    margin-top: 8px;
}

th, td {
    padding: 4px 16px;
    text-align: left;
    vertical-align: middle;
}

/* Card-row: each tbody row is a floating mini-card */
tbody tr {
    background: var(--card);
    border: none;
    box-shadow: 0 1px 6px rgba(109,78,212,0.06);
    transition: box-shadow 0.2s, transform 0.2s;
}
tbody tr:hover {
    box-shadow: 0 6px 20px rgba(109,78,212,0.12);
    transform: translateY(-1px);
}
tbody tr td:first-child { border-radius: 16px 0 0 16px; }
tbody tr td:last-child  { border-radius: 0 16px 16px 0; }

/* Accent bar on first cell */
tbody tr[data-accent] > td:first-child {
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

/* thead — invisible, just labels */
thead tr {
    background: transparent !important;
    box-shadow: none !important;
}
th {
    border: none;
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    background: transparent;
    padding-bottom: 4px;
    padding-top: 8px;
}

/* tfoot — header style with accent bg */
tfoot tr {
    background: var(--bg) !important;
    box-shadow: none !important;
}
tfoot tr td {
    border: none;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding-top: 8px;
    padding-bottom: 8px;
}

.actions { white-space: nowrap; text-align: right; padding-left: 0; }
.actions button { margin-left: 2px; }
.actions button:first-child { margin-left: 0; }

/* Desktop progress bar — absolute positioned, zero layout impact */
.data-cell { position: relative; }
.desktop-progress {
    position: absolute;
    bottom: 2px;
    left: 14px;
    right: 14px;
    height: 3px;
    background: var(--gray-200);
    border-radius: 2px;
    overflow: hidden;
}
.desktop-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Percentage badge — pill */
.pct-badge {
    display: inline-block;
    padding: 3px 0;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
    width: 44px;
    text-align: center;
    letter-spacing: 0.02em;
}
.pct-badge-good { background: #7ec882; color: #fff; }
.pct-badge-warn { background: #ffc333; color: #fff; }
.pct-badge-bad  { background: #f07e7c; color: #fff; }
.pct-badge-none { color: var(--text-faint); background: transparent; }

/* Role badges — pill */
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    padding: 4px 14px;
    border-radius: 50px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1;
    text-transform: uppercase;
    box-sizing: border-box;
}
.role-badge-admin { background: #dbeafe; color: #2563eb; }
.role-badge-user  { background: #fce7f3; color: #db2777; }
.role-badge-tv    { background: #fef3c7; color: #b45309; }

td.editable { cursor: pointer; }
/* ── Custom select dropdown ── */
.custom-select { position: relative; width: 100%; }
.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 32px;
    padding: 4px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--gray-50);
    font-family: var(--font);
    font-size: 0.8125rem;
    color: var(--text);
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    text-align: left;
}
.custom-select-trigger:hover { border-color: var(--gray-400); }
.custom-select-trigger:focus,
.custom-select.open .custom-select-trigger {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
    background: var(--card);
}
.custom-select-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-chevron {
    flex-shrink: 0;
    margin-left: 6px;
    transition: transform 0.2s;
    color: var(--gray-400);
}
.custom-select.open .custom-select-chevron { transform: rotate(180deg); }
.custom-select-dropdown {
    position: fixed;
    z-index: 9999;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    padding: 4px;
    list-style: none;
    margin: 0;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s, transform 0.15s;
}
.custom-select-dropdown.visible {
    opacity: 1;
    transform: translateY(0);
}
.custom-select-option {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.custom-select-option:hover,
.custom-select-option.highlighted { background: var(--gray-100); }
.custom-select-option.selected { color: var(--primary-dark); font-weight: 600; }
td.editable input,
td.editable select {
    width: 100%;
    height: 34px;
    padding: 4px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    background: var(--gray-50);
    color: var(--text);
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

td.editable input:focus,
td.editable select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
    background: var(--card);
}

.new-row { background-color: #faf8ff; }

/* Color picker — popover on icon */
.ref-icon-cell { position: relative; }
.color-popover {
    position: fixed;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    z-index: 9999;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: none;
}
.color-popover.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.color-dot {
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
    box-sizing: border-box;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: var(--gray-700); }

/* Number input spinners — subtle */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    opacity: 0.4;
    margin-left: 5px;
}

.data-cell { text-align: right; font-variant-numeric: tabular-nums; cursor: pointer; }
td.data-cell input[type] {
    width: 100%;
    min-width: 0;
    padding: 4px 6px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-family: var(--font);
    font-size: inherit;
    text-align: right;
    color: var(--text);
    box-sizing: border-box;
    outline: none;
    -moz-appearance: textfield;
}
.data-cell input::-webkit-outer-spin-button,
.data-cell input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
td.data-cell input[type]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
}

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; }

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="month"],
select {
    width: 100%;
    padding: 8px 28px 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--text);
    background: var(--card);
    transition: border-color 0.1s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="month"]:focus,
select:focus {
    outline: none;
    border-color: var(--gray-400);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

input::placeholder { color: var(--text-faint); }

.help-block {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ===== Alerts ===== */
.alert {
    padding: 10px 14px;
    margin-bottom: 16px;
    border-radius: 16px;
    font-size: 0.8125rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: var(--danger-bg);
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* ===== Controls ===== */
.controls {
    display: flex;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    display: block;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.controls select,
.controls input[type="month"] {
    width: auto;
    padding: 6px 32px 6px 16px;
    font-size: 0.8125rem;
    height: 36px;
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--card);
    transition: border-color 0.15s;
}
.controls input[type="month"] { width: 155px; padding-right: 8px; }
.controls select:focus,
.controls input[type="month"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
    outline: none;
}

.controls .controls-btn {
    height: 34px;
    box-sizing: border-box;
}

.controls label {
    display: inline;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.month-nav,
.dept-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    flex-shrink: 1;
}

.month-nav .btn,
.dept-nav .btn { padding: 0; font-size: 0.75rem; height: 34px; width: 34px; box-sizing: border-box; background: var(--primary); color: #fff; border: none; border-radius: 50%; }
.month-nav .btn:hover,
.dept-nav .btn:hover { background: var(--primary-dark); }

.dept-nav .custom-select { width: 195px; }
.dept-nav .custom-select-trigger { height: 36px; background: var(--card); border-color: var(--border); }

/* Labels align above select/input, not above arrow buttons */
.dept-nav + .dept-nav,
.month-nav + .month-nav { /* placeholder */ }
.controls .control-group:has(.dept-nav) label,
.controls .control-group:has(.month-nav) label { padding-left: 38px; }

/* ===== Toolbar Row (button + inline message) ===== */
.toolbar-row {
    display: flex;
    align-items: center;
    height: 34px;
}

.toolbar-row .btn { flex-shrink: 0; }

/* Message area — anchored to top-right of the card */
.card { position: relative; }

.card > #message-area {
    position: absolute;
    top: 16px;
    right: 24px;
    z-index: 5;
}

.card > #message-area .alert,
.toolbar-row .alert {
    margin-bottom: 0;
    padding: 6px 12px;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ===== Login ===== */
/* Login — everything on purple gradient with decorative shapes */
/* ===== Login Page ===== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #b796ef 0%, #8b66d9 100%);
    position: relative;
    overflow: hidden;
}



.login-content {
    width: 400px;
    max-width: calc(100vw - 32px);
    background: var(--card);
    border-radius: 20px;
    padding: 40px 36px 36px;
    box-shadow: 0 8px 40px rgba(60,30,120,0.18), 0 2px 12px rgba(0,0,0,0.06);
    position: relative;
    z-index: 1;
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-icon {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #b796ef 0%, #8b66d9 100%);
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    box-shadow: 0 4px 16px rgba(139,102,217,0.25);
}
.login-icon svg { stroke: #fff !important; }
.login-icon svg rect,
.login-icon svg path,
.login-icon svg circle { stroke: #fff; fill: none; }

.login-app-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
}

.login-welcome {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 24px;
    line-height: 1.3;
    text-align: center;
}

.login-field {
    margin-bottom: 16px;
}
.login-field--submit {
    margin-top: 32px;
}

.login-field input[type="text"],
.login-field input[type="password"] {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 0.9375rem;
    font-family: var(--font);
    font-weight: 500;
    background: var(--gray-50);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
}
.login-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
    background: var(--card);
}
.login-field input::placeholder {
    color: var(--text-faint);
    font-weight: 400;
}

.login-btn {
    display: block;
    width: 100%;
    padding: 13px;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    background: linear-gradient(135deg, #b796ef 0%, #8b66d9 100%);
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    font-family: var(--font);
    -webkit-appearance: none;
    appearance: none;
    margin-top: 24px;
    box-shadow: 0 2px 12px rgba(139,102,217,0.3);
    -webkit-tap-highlight-color: transparent;
}
.login-btn:hover {
    box-shadow: 0 4px 20px rgba(139,102,217,0.4);
    transform: translateY(-1px);
}
.login-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(139,102,217,0.25);
    background: linear-gradient(135deg, #a07de0 0%, #7a58c4 100%);
    color: #fff;
}
.login-btn:focus {
    color: #fff;
    outline: none;
}

.login-forgot {
    margin: 16px 0 0;
    font-size: 0.75rem;
    color: var(--text-faint);
    font-weight: 500;
    text-align: center;
}

.login-alert {
    background: var(--danger-bg) !important;
    color: #b91c1c !important;
    border: 1px solid #fecaca !important;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 16px;
    padding: 10px 16px;
    font-size: 0.8125rem;
}

.login-field .help-block {
    text-align: left;
    color: var(--text-faint);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ===== Reference-style table elements ===== */
.ref-icon-cell { width: 44px; padding-right: 0 !important; }
.ref-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ref-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    display: inline-block;
    min-width: 200px;
}

.ref-badge {
    display: inline-block;
    width: 100%;
    padding: 4px 14px;
    border-radius: 50px;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
    box-sizing: border-box;
}


/* ===== Dashboard Layout ===== */
.dashboard-page { height: 100%; padding: 0; }
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.dashboard-main {
    flex: 1;
    min-width: 0;
    margin-left: 232px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ===== Control Bar ===== */
.control-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden;
}

.controls-btn-icon { display: none; }

.control-group-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 1;
}

.control-group-inline label {
    display: inline;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.control-bar select {
    width: auto;
    padding: 5px 32px 5px 12px;
    height: 34px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: var(--font);
}

.control-bar input[type="month"] {
    width: 155px;
    min-width: 120px;
    height: 34px;
    box-sizing: border-box;
    flex-shrink: 1;
    padding: 5px 8px;
    font-size: 0.8125rem;
}

.control-bar .dept-nav { gap: 4px; }
.control-bar .dept-nav .custom-select { width: 195px; min-width: 0; flex-shrink: 1; }
.control-bar .dept-nav .custom-select-trigger { height: 34px; background: var(--card); border-color: var(--border); }

.control-bar .controls-btn {
    height: 34px;
    box-sizing: border-box;
    flex-shrink: 0;
    white-space: nowrap;
}

.control-bar .control-spacer {
    flex: 1;
}

/* ===== Dashboard Grid ===== */
.dashboard-container {
    padding: 8px;
    flex: 1;
    min-height: 0;
}

@media (min-width: 481px) and (min-height: 500px) {
    .dashboard-container {
        display: grid;
        grid-template-rows: 1fr 1fr;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 5px;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
}

/* ===== CSS Bar Charts (replaces Chart.js) ===== */
.css-chart-area {
    flex-direction: column;
    align-items: stretch !important;
    justify-content: flex-start !important;
    overflow: hidden;
}

.css-chart-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    font-family: var(--font);
    text-align: center;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.css-chart-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    min-height: 0;
    overflow: hidden;
}

.css-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 var(--bar-base, 32px);
    min-height: 14px;
    margin-block: 2px;
    position: relative;
    z-index: 1;
}

.css-bar-name {
    width: 100px;
    flex-shrink: 0;
    text-align: right;
    font-size: 0.8125rem;
    font-family: var(--font);
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.css-bar-track {
    flex: 1;
    position: relative;
    align-self: stretch;
    min-width: 0;
}


.css-bar-plan {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: visible;
}

.css-bar-fact {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    position: relative;
    overflow: visible;
    min-width: 0;
}

.css-bar-fact-label {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8125rem;
    font-family: var(--font);
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* When fact fills most of the bar, show label inside */
.css-bar-fact-label.inside {
    color: #fff;
    font-weight: 700;
}

/* Exceed bar — lighter shade extending beyond plan */
.css-bar-exceed-bar {
    position: absolute;
    top: 0;
    height: 100%;
    border-radius: 0 4px 4px 0;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
}


.css-bar-val {
    width: 65px;
    flex-shrink: 0;
    font-size: 0.8125rem;
    font-family: var(--font);
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.css-bar-val-spacer {
    width: 65px;
}

/* ===== Award Icons ===== */
.award-icon {
    flex-shrink: 0;
    margin-left: -21px;
    margin-right: 5px;
    transform: translateY(-1px);
}

/* ===== CSS Grid Lines ===== */
.css-chart-with-grid {
    position: relative;
}

.css-grid-lines {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 108px; /* css-bar-name (100px) + gap (8px) */
    right: 73px; /* css-bar-val (65px) + gap (8px) */
    pointer-events: none;
    z-index: 0;
}

.css-grid-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--gray-150, rgba(0,0,0,0.04));
}


/* ===== CSS Chart Scale ===== */
.css-chart-scale {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex-shrink: 0;
    border-top: 1px solid rgba(0,0,0,0.04);
    padding-top: 4px;
    margin-top: 4px;
}

.css-scale-track {
    flex: 1;
    position: relative;
    height: 16px;
    min-width: 0;
}

.css-scale-track span {
    position: absolute;
    transform: translateX(-50%);
    font-size: 0.5625rem;
    font-family: var(--font);
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.css-scale-track span:first-child {
    transform: translateX(0);
}

/* ===== CSS Rings (replaces Chart.js doughnuts) ===== */
/* ===== CSS Ring Row (side legends) ===== */
.css-ring-row {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 0;
    padding: 2px 0;
}

.css-ring-side {
    font-size: 9px;
    font-family: var(--font);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    display: flex;
    align-items: center;
    min-width: 0;
}

.css-ring {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    position: relative;
    visibility: hidden;
}

.css-ring-row .css-ring {
    height: 90%;
    max-height: 100px;
    width: auto;
}

.css-ring-center {
    position: absolute;
    inset: 15%;
    border-radius: 50%;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    font-weight: 700;
    font-size: clamp(10px, 2.5vw, 14px);
    font-variant-numeric: tabular-nums;
}

/* Ring inside doughnut-canvas-container — sized by JS sizeRings() */

/* Total doughnut — uses same css-ring-group sizing */

.css-ring-center-lg {
    font-size: clamp(16px, 3.5vw, 26px);
}

.total-doughnut-area .doughnut-title {
    font-size: 15px;
    margin-bottom: 6px;
}

.total-doughnut-area .doughnut-legend {
    justify-content: space-around;
}

.total-doughnut-area .doughnut-legend-item {
    font-size: 11px;
}

.total-doughnut-area .doughnut-legend-color {
    width: 8px;
    height: 8px;
    margin-right: 3px;
}

.grid-cell-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.top-left-area { grid-row: 1; grid-column: 1; }
.top-right-area { grid-row: 1; grid-column: 2; }
.total-doughnut-area { grid-row: 2; grid-column: 2; }

.doughnuts-grid-area {
    grid-row: 2;
    grid-column: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: minmax(0, 1fr);
    gap: 0;
    row-gap: 0;
    min-height: 0;
    overflow: hidden;
}

.doughnut-chart-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

.doughnut-canvas-container {
    width: 100%;
    flex: 0 0 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    overflow: hidden;
}

.doughnut-title {
    text-align: center;
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    height: 18px;
    line-height: 18px;
    flex-shrink: 0;
    margin: 0;
    letter-spacing: -0.01em;
}

/* Total doughnut ring — sized by JS sizeRings() */

.doughnut-legend {
    display: flex;
    justify-content: space-around;
    align-self: stretch;
    height: 18px;
    flex-shrink: 0;
    margin: 0;
    overflow: hidden;
}

.doughnut-legend-item {
    display: flex;
    align-items: center;
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    font-variant-numeric: tabular-nums;
}

.doughnut-legend-color {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 2px;
    flex-shrink: 0;
}

.many-employees .doughnut-legend-item { font-size: 8px; }


/* ===== Monthly data table ===== */
#monthly-table { table-layout: fixed; min-width: 972px; }
#monthly-table .pct-cell,
#monthly-table .tfoot-pct-sales,
#monthly-table .tfoot-pct-kp,
#monthly-table th:nth-child(5),
#monthly-table th:nth-child(8) {
    text-align: center;
    padding-left: 4px;
    padding-right: 4px;
}

/* ===== Responsive: dashboard ===== */
@media (min-width: 481px) and (max-width: 1400px) {
    .control-bar { gap: 10px; padding: 8px 12px; }
    .control-bar .control-group-inline label { display: none; }
    .control-bar .controls-btn { font-size: 0.75rem; padding: 6px 12px; }
}

@media (min-width: 481px) and (max-width: 992px) {
    .doughnuts-grid-area { gap: 5px; column-gap: 2px; padding: 2px; }
    .doughnut-title { font-size: 11px; height: 18px; line-height: 16px; }
    .doughnut-legend-item { font-size: 10px; }
    .doughnut-legend-color { width: 6px; height: 6px; margin-right: 2px; }
    .css-ring-center { font-size: clamp(8px, 2vw, 12px); }
    .css-ring-center-lg { font-size: clamp(16px, 3.5vw, 26px); }
    .total-doughnut-area .doughnut-title { font-size: 15px; height: 22px; line-height: 22px; }
    .total-doughnut-area .doughnut-legend-item { font-size: 13px; }
    .total-doughnut-area .doughnut-legend-color { width: 8px; height: 8px; margin-right: 3px; }
    .total-doughnut-area .doughnut-legend { height: 22px; }
}

@media (max-width: 480px), (max-height: 500px) {
    .dashboard-container {
        display: flex;
        flex-direction: column;
        min-height: calc(100vh - 48px);
        overflow-y: auto;
        gap: 15px;
        height: auto;
        padding: 5px;
    }
    .grid-cell-container { width: 100%; height: 350px; aspect-ratio: auto; flex-shrink: 0; margin-bottom: 0; padding: 10px; }
    .total-doughnut-area { width: 100%; height: auto; aspect-ratio: auto; flex-shrink: 0; padding: 10px; }
    .top-left-area { order: 2; }
    .top-right-area { order: 3; }
    .doughnuts-grid-area {
        order: 4;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        gap: 15px;
        padding: 0;
        border: none;
        background: transparent;
        height: auto;
        min-height: auto;
        overflow: visible;
    }
    .total-doughnut-area { order: 1; }
    .doughnuts-grid-area .doughnut-chart-wrapper {
        height: auto; width: 100%;
        flex-shrink: 0;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 10px;
    }
    .doughnut-canvas-container { width: 100%; flex: 0 0 auto; margin: 4px auto; min-height: auto; }
    .doughnut-title { font-size: 15px; }
    .css-ring-center { font-size: 26px; }
    .total-doughnut-area .doughnut-chart-wrapper { border: none; padding: 0; background: transparent; }
    .total-doughnut-area .doughnut-canvas-container { flex: 0 0 auto; }
    .doughnut-legend { justify-content: space-around; }
    .doughnut-legend-item { font-size: 15px; }
    .total-doughnut-area .doughnut-legend-item { font-size: 15px; }
    .total-doughnut-area .doughnut-legend-color { width: 8px; height: 8px; margin-right: 3px; }
    .doughnut-legend-color { width: 8px; height: 8px; margin-right: 3px; }
    .doughnut-legend { height: 24px; }
}

/* ===== TV ===== */
.tv-body {
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
    max-width: 100vw;
    background: var(--bg);
    font-family: var(--font);
    font-size: 12px;
}
.tv-body .css-chart-title { font-size: 13px; }
.tv-body .css-bar-name { font-size: 0.7rem; }
.tv-body .css-bar-val { font-size: 0.7rem; }
.tv-body .css-bar-fact-label { font-size: 0.7rem; }
.tv-body .css-scale-track span { font-size: 0.65rem; }
.tv-body .doughnut-title { font-size: 0.65rem; }
.tv-body .doughnut-legend-item { font-size: 0.6rem; }
.tv-body .doughnut-legend-color { width: 6px; height: 6px; }
.tv-body .css-ring-center { font-size: 0.8rem; }
.tv-body .css-ring-center-lg { font-size: 1rem; }
.tv-body .total-doughnut-area .doughnut-title { font-size: 0.75rem; }
.tv-body .total-doughnut-area .doughnut-legend-item { font-size: 0.65rem; }

.tv-exit {
    position: fixed;
    top: 10px;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: var(--text-faint);
    z-index: 10;
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.2s;
    /* Убираем focus-кольцо (Android TV при выходе из сна фокусит ссылку) */
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
.tv-exit:focus { outline: none; box-shadow: none; }
.tv-exit:hover { opacity: 1; }

.tv-body .dashboard-container { height: 100vh; padding: 4px; max-width: 100vw; overflow: hidden; }
.tv-body .grid-cell-container,
.tv-body .doughnuts-grid-area { border-radius: var(--radius); }


.tv-not-configured {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--gray-900);
    color: var(--gray-50);
    font-family: var(--font);
}
.tv-not-configured-msg { text-align: center; }

/* ===== Confirm Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.12s ease;
}

.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.modal-box p {
    margin: 0 0 20px;
    font-size: 0.875rem;
    color: var(--text);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-actions .btn { min-width: 80px; }

.btn-danger-fill {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger-fill:hover {
    background: #dc2626;
    border-color: #dc2626;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== No data ===== */
.no-data-placeholder {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.no-data-placeholder h2 { color: var(--text-muted); font-weight: 500; }
.no-data-placeholder p { color: var(--text-faint); }

/* ===== Mobile ===== */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 200;
    background: transparent;
    color: var(--primary-dark);
    border: 1.5px solid var(--primary-dark);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(139,102,217,0.15);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.2);
    z-index: 90;
}

@media (max-width: 768px), (max-height: 500px) {
    .sidebar-toggle { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.15s ease;
        padding-top: 48px;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }

    .main-content {
        margin-left: 0;
        padding: 24px 16px;
        padding-top: 56px;
    }
    .dashboard-main { margin-left: 0; }
    .dashboard-main .control-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
        padding: 0 12px 0 56px;
        flex-wrap: nowrap;
        gap: 4px;
        height: 52px;
        align-items: center;
    }
    .dashboard-main { padding-top: 52px !important; }
    .control-bar .control-group-inline label { display: none; }
    .control-bar .controls-btn { display: none; }
    .control-bar .controls-btn-icon { display: inline-flex; align-items: center; justify-content: center; height: 30px; width: 30px; flex-shrink: 0; font-size: 1.1rem; padding: 0; }
    .control-spacer { display: none; }
    .control-bar select { font-size: 0.75rem; padding: 4px 24px 4px 6px; height: 30px; flex: 1.5; min-width: 0; }
    .control-bar .month-nav .btn,
    .control-bar .dept-nav .btn { display: none; }
    .control-bar .dept-nav { flex: 1.5; }
    .control-bar .dept-nav .custom-select { width: 160px; min-width: 0; flex-shrink: 0; }
    .control-bar .dept-nav .custom-select-trigger { height: 30px; font-size: 0.75rem; padding: 4px 10px; }
    .control-bar input[type="month"] { font-size: 0.75rem; height: 30px; padding: 4px 20px 4px 6px; flex: 0 1 130px; min-width: 0; width: auto; }
    .controls {
        position: fixed;
        top: 52px;
        left: 0;
        right: 0;
        z-index: 99;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
        padding: 10px 12px;
        margin: 0;
        gap: 4px;
        flex-wrap: nowrap;
    }
    .controls .control-group { flex-direction: row; align-items: center; gap: 4px; flex: 1; }
    .controls .control-group label { display: none; }
    .controls .control-group select,
    .controls .control-group .month-nav,
    .controls .control-group .dept-nav { flex: 1; }
    .controls .month-nav .btn:not(.controls-btn-icon),
    .controls .dept-nav .btn { display: none; }
    .controls .dept-nav .custom-select { min-width: 0; width: 160px; flex-shrink: 0; }
    .controls .dept-nav .custom-select-trigger { height: 30px; font-size: 0.75rem; padding: 4px 10px; }
    .controls .controls-btn { display: none; }
    .controls .controls-btn-icon { display: inline-flex; align-items: center; justify-content: center; height: 30px; width: 30px; flex-shrink: 0; font-size: 1.1rem; padding: 0; }
    .controls select { font-size: 0.75rem; height: 30px; padding: 4px 24px 4px 6px; }
    .controls input[type="month"] { font-size: 0.75rem; height: 30px; padding: 4px 20px 4px 6px; flex: 0 1 130px; min-width: 0; width: auto; }
    .main-content .card {
        padding: 8px 0;
        margin: 0 !important;
        background: transparent;
        border: none;
        box-shadow: none;
        border-radius: 0;
        overflow: visible;
    }
    .main-content {
        padding-top: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        overflow-x: clip;
    }

    /* Toast notifications (mobile) */
    .card > #message-area {
        position: fixed;
        top: auto;
        right: auto;
        bottom: 24px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 300;
        width: auto;
        max-width: calc(100vw - 32px);
    }
    .card > #message-area .alert {
        border-radius: 12px;
        padding: 10px 20px;
        font-size: 0.8125rem;
        box-shadow: 0 4px 16px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.08);
        white-space: nowrap;
        animation: toast-in 0.25s ease-out;
    }
    @keyframes toast-in {
        from { opacity: 0; transform: translateY(12px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* Fixed top bar: burger + icon + title + add button */
    .page-header {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: #fff !important;
        margin: 0 !important;
        padding: 0 12px 0 56px !important;
        height: 52px;
        border-bottom: none !important;
        border-radius: 0 !important;
        display: flex !important;
        align-items: center;
        gap: 8px;
        box-shadow: 0 1px 6px rgba(139,102,217,0.08), 0 1px 3px rgba(0,0,0,0.04);
    }
    .main-content:has(.page-header) { padding-top: 52px !important; }
    .main-content:has(.page-header):has(.controls) { padding-top: 110px !important; }
    .page-header h2 {
        font-size: 0.95rem !important;
        font-weight: 600 !important;
        margin: 0;
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: var(--primary-dark) !important;
    }
    .page-subtitle { display: none !important; }
    .page-header .page-icon { width: 32px !important; height: 32px !important; border-radius: 10px; margin-right: 4px; background: transparent !important; border: none !important; box-shadow: none !important; }
    .page-header .page-icon svg { width: 16px !important; height: 16px !important; stroke: var(--primary-dark) !important; stroke-width: 2 !important; }

    .toolbar-row { display: none !important; }
    .header-add-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        background: var(--primary);
        color: #fff;
        font-size: 1.4rem;
        font-weight: 300;
        border: none;
        cursor: pointer;
        flex-shrink: 0;
        line-height: 1;
        box-shadow: 0 2px 8px rgba(139,92,246,0.25);
    }
    .header-add-btn:active { transform: scale(0.92); }
    .main-content .card { padding: 6px 8px !important; }
    th, td { padding: 5px 8px; font-size: 0.75rem; }
    .btn-icon { min-width: 26px; padding: 4px 5px; font-size: 0.875rem; }
    .actions button { margin-left: 2px; }
    /* h2 size set in .page-header h2 block above */
    .controls select { padding-right: 28px; }
    .controls input[type="month"] { padding-right: 24px; }

    /* ═══════ Mobile: table → cards ═══════ */
    table colgroup { display: none; }
    table { min-width: 0 !important; table-layout: auto !important; width: 100% !important; max-width: 100% !important; display: block; }
    table tbody { display: block; width: 100%; }
    table thead { display: none; }
    table tfoot { display: none; }

    /* Card (each <tr>) */
    table tbody tr {
        display: block;
        border: none;
        border-radius: 0;
        padding: 0 4px;
        margin-bottom: 12px;
        position: relative;
        overflow: visible;
        background: transparent;
        box-shadow: none;
        transition: transform 0.15s ease;
        max-width: 100%;
    }
    table tbody tr[data-accent] > td:first-child { border-left: none; padding-left: 0; }
    table tbody tr:active {
        transform: scale(0.985);
    }

    /* Cell layout */
    table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0;
        border: none !important;
        height: auto;
        font-size: 0.8125rem;
        line-height: 1.4;
    }

    /* Label (::before) */
    table tbody td:before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.625rem;
        color: var(--text-faint);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        flex-shrink: 0;
        margin-right: 16px;
    }

    /* Hide cells */
    table tbody td[data-label=""] { display: none; }
    table tbody td:not([data-label]):not(.actions):not(.pct-cell) { display: none; }
    table tbody td.actions { display: none !important; }
    table tbody td.pct-cell { display: none; }
    .desktop-progress { display: none !important; }

    /* Title cell */
    table tbody td[data-card-title],
    table tbody .card-content td[data-card-title] {
        font-weight: 600;
        font-size: 0.9375rem;
        color: var(--text);
        letter-spacing: -0.01em;
        padding-bottom: 8px;
        margin-bottom: 8px;
        border-bottom: 1px solid var(--gray-100);
        position: relative;
        padding-right: 20px;
    }
    table tbody td[data-card-title]:before,
    table tbody .card-content td[data-card-title]:before { display: none; }
    /* Chevron › */
    table tbody td[data-card-title]::after,
    table tbody .card-content td[data-card-title]::after {
        content: "";
        position: absolute;
        right: 2px;
        top: 50%;
        transform: translateY(-50%) rotate(45deg);
        width: 7px;
        height: 7px;
        border-right: 2px solid var(--text-faint);
        border-top: 2px solid var(--text-faint);
    }

    /* Data values — numbers pop */
    table tbody td.data-cell {
        text-align: right;
        font-weight: 700;
        font-size: 0.875rem;
        font-variant-numeric: tabular-nums;
        color: var(--text);
        letter-spacing: -0.01em;
    }

    /* Monthly data: group plan/fact pairs */
    table tbody td[data-label="План продаж"] { margin-top: 2px; padding-top: 8px; }
    table tbody td[data-label="Факт продаж"] { padding-bottom: 8px; margin-bottom: 4px; }
    table tbody td[data-label="План КП"] { padding-top: 8px; border-top: 1px solid var(--gray-100); }
    table tbody td[data-label="Факт КП"] { padding-bottom: 4px; }

    /* Plan labels lighter, Fact labels bolder */
    table tbody td[data-label="План продаж"]:before,
    table tbody td[data-label="План КП"]:before { color: var(--text-faint); font-size: 0.625rem; }
    table tbody td[data-label="Факт продаж"]:before,
    table tbody td[data-label="Факт КП"]:before { color: var(--text-secondary); font-weight: 700; font-size: 0.625rem; }

    /* Hide password in card */
    table tbody td[data-label="Пароль"] { display: none; }

    /* Role badge in card */
    table tbody td[data-label="Роль"] .role-badge { font-size: 0.6875rem; padding: 2px 10px; }

    /* Card content wrapper (swipe) */
    table tbody tr .card-content {
        position: relative;
        z-index: 1;
        background: var(--card);
        box-shadow: 0 1px 4px rgba(0,0,0,0.04), 0 2px 12px rgba(0,0,0,0.03);
        transition: transform 0.2s ease;
        padding: 16px 16px 14px;
        border-radius: 16px;
        border-left: none;
        display: flex;
        flex-direction: column;
        max-width: 100%;
        box-sizing: border-box;
        gap: 2px;
    }

    /* Initials avatar / ref-icon as avatar */
    table tbody .card-avatar {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 10px;
        font-size: 0.6875rem;
        font-weight: 700;
        color: #fff;
        letter-spacing: 0.02em;
        text-transform: uppercase;
        flex-shrink: 0;
    }
    table tbody .card-avatar svg {
        width: 14px;
        height: 14px;
    }

    /* Legacy color dot (fallback) */
    table tbody .card-dot {
        display: block;
        width: 12px;
        height: 12px;
        border-radius: 50%;
        flex-shrink: 0;
    }

    /* Page header mobile style */
    .page-header h2 {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Title row with initials + name + pct badge */
    table tbody td[data-card-title],
    table tbody .card-content td[data-card-title] {
        display: flex !important;
        align-items: center;
        gap: 10px;
    }

    /* Percentage badge */
    table tbody .card-pct-badge {
        font-size: 0.625rem;
        font-weight: 700;
        padding: 2px 8px;
        border-radius: 50px;
        flex-shrink: 0;
        margin-left: auto;
        margin-right: 4px;
        font-variant-numeric: tabular-nums;
        letter-spacing: 0.02em;
    }

    /* Compact cards — single row layout (accounts, departments, employees) */
    table tbody .card-role-inline,
    table tbody .card-dept-inline {
        font-size: 0.5625rem;
        padding: 4px 14px 3px;
        flex-shrink: 0;
        width: auto;
        min-width: 54px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }
    table tbody tr .card-compact {
        padding: 16px 16px;
    }
    table tbody .card-compact td[data-card-title] {
        display: flex !important;
        align-items: center;
        gap: 10px;
        width: 100%;
        border-bottom: none;
        padding: 0;
        margin: 0;
    }
    table tbody .card-compact td[data-card-title] .ref-name {
        flex: 1;
        min-width: 0;
    }
    table tbody .card-compact td[data-card-title]::after {
        content: "";
        position: static;
        transform: rotate(45deg);
        flex-shrink: 0;
        width: 7px;
        height: 7px;
        border-right: 2px solid var(--text-faint);
        border-top: 2px solid var(--text-faint);
        font-size: 0;
    }
    table tbody .card-compact .card-avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    table tbody .card-compact .card-avatar svg {
        width: 14px;
        height: 14px;
    }

    /* Color-coded values */
    table tbody td.data-cell[data-status="good"] { color: #15803d; }
    table tbody td.data-cell[data-status="warn"] { color: #a16207; }
    table tbody td.data-cell[data-status="bad"] { color: #dc2626; }

    /* Clean labels — no emojis, just uppercase text */

    /* Mini progress bar under Fact rows */
    table tbody .card-progress {
        width: 100%;
        height: 4px;
        background: var(--gray-100);
        border-radius: 3px;
        margin-top: 6px;
        overflow: hidden;
    }
    table tbody .card-progress-fill {
        height: 100%;
        border-radius: 3px;
        transition: width 0.3s ease;
    }

    /* Swipe-to-delete */
    table tbody tr .swipe-delete-btn {
        position: absolute;
        right: 4px;
        top: 0;
        bottom: 0;
        width: 80px;
        background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.75rem;
        font-weight: 700;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        z-index: 0;
        border-radius: 0 16px 16px 0;
        opacity: 0;
        transition: opacity 0.15s ease;
    }
    table tbody tr.swiped .card-content {
        transform: translateX(-80px);
    }
    table tbody tr.swiped .swipe-delete-btn {
        opacity: 1;
    }
}

/* ===== Mobile Bottom Sheet ===== */
.mobile-edit-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.mobile-edit-sheet {
    background: var(--card);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 8px 20px 24px;
    animation: sheetSlideUp 0.2s ease;
}

/* Drag handle */
.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--gray-300);
    border-radius: 3px;
    margin: 0 auto 12px;
}

@keyframes sheetSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--gray-100);
}

.sheet-title {
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--text);
    letter-spacing: -0.01em;
}

.sheet-close {
    background: var(--gray-100);
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.sheet-close:active { background: var(--gray-200); }

.sheet-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sheet-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sheet-field label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.sheet-field input,
.sheet-field select {
    width: 100%;
    height: 48px;
    font-size: 16px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    color: var(--text);
    background: var(--gray-50);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.sheet-field input:focus,
.sheet-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
    background: var(--card);
}

/* Color picker in sheet */
.sheet-color-picker {
    display: flex;
    gap: 10px;
    padding: 8px 0;
}
.sheet-color-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.sheet-color-dot:active {
    transform: scale(0.9);
}
.sheet-color-dot.active {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px currentColor;
    transform: scale(1.1);
}

.sheet-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--gray-100);
}

.sheet-actions .btn {
    flex: 1;
    height: 48px;
    font-size: 0.875rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.sheet-actions .sheet-delete {
    flex: 0 0 48px;
    border-radius: var(--radius);
}
