:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --border: #2f3f57;
    --text: #e8edf5;
    --muted: #93a4bd;
    --primary: #ffcc00;
    --primary-dark: #e6b800;
    --accent: #4da3ff;
    --success: #3ecf8e;
    --danger: #ff6b6b;
    --radius: 14px;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background:
        radial-gradient(circle at top right, rgba(77, 163, 255, 0.12), transparent 30%),
        radial-gradient(circle at bottom left, rgba(255, 204, 0, 0.08), transparent 25%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

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

.logo {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #ff9500);
    color: #1a1200;
    box-shadow: var(--shadow);
}

h1 {
    margin: 0;
    font-size: 1.6rem;
}

h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
}

.subtitle,
.hint {
    color: var(--muted);
    margin: 4px 0 0;
}

.card {
    background: rgba(26, 35, 50, 0.92);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

.auth-card {
    margin-bottom: 24px;
}

.auth-actions,
.auth-footer,
.toolbar__right {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.auth-actions {
    margin: 20px 0;
}

.auth-footer {
    margin-top: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.field--inline {
    margin-bottom: 0;
    min-width: 150px;
}

.field span {
    font-size: 0.9rem;
    color: var(--muted);
}

.field small {
    color: #6f819c;
}

input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.95rem;
}

input:focus {
    outline: 2px solid rgba(77, 163, 255, 0.35);
    border-color: var(--accent);
}

.btn {
    border: 0;
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn--primary {
    background: linear-gradient(135deg, var(--primary), #ffb300);
    color: #1a1200;
}

.btn--secondary {
    background: var(--accent);
    color: #061018;
}

.btn--ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.badge--muted {
    background: rgba(147, 164, 189, 0.12);
    color: var(--muted);
}

.badge--success {
    background: rgba(62, 207, 142, 0.15);
    color: var(--success);
}

.toolbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.summary-card__label {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.summary-card__value {
    font-size: 1.5rem;
    font-weight: 700;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: rgba(36, 48, 68, 0.8);
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table tbody tr:hover {
    background: rgba(77, 163, 255, 0.06);
}

.data-table td.empty {
    text-align: center;
    color: var(--muted);
    padding: 28px;
}

.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    background: rgba(147, 164, 189, 0.15);
    color: var(--muted);
}

.status--on {
    background: rgba(62, 207, 142, 0.15);
    color: var(--success);
}

.status--off {
    background: rgba(255, 107, 107, 0.12);
    color: var(--danger);
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: 420px;
    padding: 14px 18px;
    border-radius: 12px;
    background: #172033;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 1000;
}

.toast--error {
    border-color: rgba(255, 107, 107, 0.5);
    color: #ffd0d0;
}

.toast--success {
    border-color: rgba(62, 207, 142, 0.5);
    color: #d7ffe9;
}

.hidden {
    display: none !important;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.tab:hover {
    color: var(--text);
    background: rgba(77, 163, 255, 0.08);
}

.tab--active {
    color: var(--text);
    background: rgba(255, 204, 0, 0.12);
    border-color: rgba(255, 204, 0, 0.35);
}

.toolbar--global {
    margin-bottom: 20px;
}

.tab-panel {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel-block {
    margin-bottom: 20px;
}

.section-title {
    margin: 24px 0 12px;
    font-size: 1rem;
}

.agent-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.agent-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    cursor: pointer;
    font-size: 0.85rem;
}

.agent-chip input {
    width: auto;
    margin: 0;
}

.agent-chip:has(input:checked) {
    border-color: rgba(77, 163, 255, 0.5);
    background: rgba(77, 163, 255, 0.12);
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.btn--sm {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.summary-card--accent .summary-card__value {
    color: var(--primary);
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 14px;
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone--active {
    border-color: var(--accent);
    background: rgba(77, 163, 255, 0.06);
}

.upload-zone__title {
    font-size: 1.1rem;
    margin: 0 0 8px;
}

.upload-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.mapping-card {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    margin-bottom: 12px;
}

.field--row {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.field--row input[type="checkbox"] {
    width: auto;
}

.mapping-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.muted {
    color: var(--muted);
    font-size: 0.8rem;
}

.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.account-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.account-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.account-card__head h3 {
    margin: 0;
    font-size: 1rem;
}

.account-card .field {
    margin-bottom: 12px;
}

.account-card .auth-actions {
    margin: 0 0 12px;
}

.account-card .btn--secondary {
    width: 100%;
    margin-bottom: 12px;
}

.date-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.date-preset--active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(77, 163, 255, 0.1);
}

.toolbar--global {
    margin-bottom: 20px;
}

.account-filter-block {
    margin-bottom: 20px;
}

.account-filter-block h3 {
    margin: 0 0 4px;
}

.chart-section {
    margin: 28px 0;
}

.chart-section__head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-section__head .section-title {
    margin: 0;
}

.chart-section__title-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chart-context {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.chart-context.hidden {
    display: none;
}

.chart-scope-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: rgba(36, 48, 68, 0.45);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.chart-scope-bar__label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.segmented--wrap {
    flex-wrap: wrap;
    max-width: 100%;
}

.segmented--wrap .segmented__btn {
    white-space: nowrap;
}

.chart-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.chart-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-2);
}

.segmented__btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 8px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.segmented__btn:hover {
    color: var(--text);
}

.segmented__btn--active {
    background: rgba(255, 204, 0, 0.15);
    color: var(--primary);
}

.chart-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.chart-stat {
    background: rgba(36, 48, 68, 0.6);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}

.chart-stat__label {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.chart-stat__value {
    font-size: 1.05rem;
    font-weight: 700;
}

.chart-stat__sub {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 4px;
}

.chart-wrap {
    position: relative;
    height: 320px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: rgba(15, 20, 25, 0.5);
}

.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    margin: 0;
}

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

.check-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(36, 48, 68, 0.5);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    user-select: none;
}

.check-chip input {
    width: auto;
    margin: 0;
    accent-color: var(--primary);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(420px, 100%);
}

.login-card__brand {
    margin-bottom: 24px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-error {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid rgba(255, 107, 107, 0.35);
    color: var(--danger);
}

.btn--block {
    width: 100%;
    justify-content: center;
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }
}
