/* =============================================
   CLIENT PANEL — Stripe-like v1.2 Polish
   Depends on: ui-tokens.css (loaded first)
   ============================================= */

/* === RESET === */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: var(--ca-font);
    background: var(--bg) !important;
    color: var(--text) !important;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    padding: 0;
}

/* =============================================
   LAYOUT
   ============================================= */

.page {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.container,
.ca-page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px var(--s-7);
    width: 100%;
}

main,
main.flex-1 {
    background: var(--bg) !important;
    min-height: 100vh;
    flex: 1;
    margin-left: var(--ca-sidebar-w);
    display: flex;
    flex-direction: column;
}

/* ── Page Header ── */
.page-header,
.ca-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: 16px;
    flex-wrap: wrap;
    min-height: 48px;
}

.page-title,
.ca-page-title {
    font-size: var(--fs-5);
    line-height: 1.15;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0;
}

.page-subtitle,
.ca-page-subtitle {
    margin-top: var(--s-2);
    font-size: var(--fs-2);
    color: var(--muted);
    margin-bottom: 0;
}

.ca-page-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ca-page-actions {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    flex-shrink: 0;
}

/* ── Top Bar ── */
.ca-topbar,
header.ca-topbar {
    height: var(--ca-header-h);
    background: var(--surface) !important;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--s-7);
    position: sticky;
    top: 0;
    z-index: 30;
    flex-shrink: 0;
}

.ca-topbar-title {
    font-size: var(--fs-4);
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.ca-topbar-right {
    display: flex;
    align-items: center;
    gap: var(--s-4);
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar,
.ca-sidebar,
aside.ca-sidebar,
aside {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--ca-sidebar-w);
    height: 100vh;
    background: var(--sidebar) !important;
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
    border-right: none !important;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.12);
}

.ca-sidebar-brand {
    height: var(--ca-header-h);
    display: flex;
    align-items: center;
    padding: 0 var(--s-5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.ca-sidebar-brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    flex-shrink: 0;
    letter-spacing: -1px;
}

.ca-sidebar-brand-name {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    margin-left: 10px;
    letter-spacing: -0.3px;
}

.ca-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-4) 10px;
    scrollbar-width: none;
}

.ca-sidebar-nav::-webkit-scrollbar {
    display: none;
}

.ca-sidebar-section {
    font-size: 11px;
    font-weight: 600;
    color: #3D5166;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0 10px;
    margin: var(--s-4) 0 6px;
}

.ca-sidebar-section:first-child {
    margin-top: 4px;
}

/* ── Nav Link ── */
.ca-nav-link,
.nav-link,
.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 10px 0 14px;
    border-radius: var(--r-sm);
    color: var(--sidebar-text);
    opacity: 0.9;
    font-size: var(--fs-2);
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s, opacity 0.2s;
    position: relative;
    margin-bottom: 2px;
}

.ca-nav-link i,
.nav-link i {
    font-size: 18px;
    flex-shrink: 0;
}

.ca-nav-link:hover,
.nav-link:hover,
.sidebar a:hover {
    background: rgba(230, 238, 248, 0.08);
    opacity: 1;
    color: #fff;
}

.ca-nav-link.active,
.nav-link.active,
.sidebar a.active {
    background: rgba(99, 91, 255, 0.22);
    box-shadow: inset 3px 0 0 var(--primary);
    opacity: 1;
    color: #fff;
    font-weight: 600;
}

.ca-nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
    min-width: 20px;
    text-align: center;
}

/* Sidebar user zone */
.ca-sidebar-user {
    padding: var(--s-3) 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.ca-sidebar-user-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.05);
}

.ca-sidebar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(99, 91, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #A5B4FC;
    flex-shrink: 0;
}

.ca-sidebar-username {
    font-size: 13px;
    font-weight: 500;
    color: #E6EEF8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ca-sidebar-role {
    font-size: 11px;
    color: #4B6073;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ca-sidebar-logout {
    margin-left: auto;
    color: #4B6073;
    transition: color var(--ca-ease);
    flex-shrink: 0;
    text-decoration: none;
    line-height: 0;
}

.ca-sidebar-logout:hover {
    color: var(--danger);
}

/* =============================================
   CARD
   ============================================= */
.card,
.ca-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm);
    padding: 20px;
    overflow: hidden;
}

.card.tight,
.ca-card.tight {
    padding: var(--s-5);
}

.ca-card-header {
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    flex-wrap: wrap;
}

.ca-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.ca-card-body {
    padding: var(--s-5);
}

/* ── KPI Grid ── */
.ca-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--s-4);
    margin-bottom: var(--s-6);
}

.ca-kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-5);
    box-shadow: var(--sh-md);
    border-top: 2px solid var(--primary);
    transition: box-shadow 0.2s;
}

.ca-kpi-card:hover {
    box-shadow: 0 8px 24px rgba(10, 37, 64, 0.10);
}

.ca-kpi-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
}

.ca-kpi-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.ca-kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

/* =============================================
   EMPTY STATE — эмоционально нейтральный v1.2
   ============================================= */
.empty,
.ca-empty {
    text-align: center;
    padding: 48px var(--s-6);
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.empty .title,
.ca-empty-title {
    color: var(--text);
    font-weight: 650;
    font-size: 15px;
    margin-top: var(--s-2);
    margin-bottom: 0;
}

.empty .hint,
.ca-empty-desc {
    margin-top: 4px;
    font-size: 13px;
    color: #8A9BB0;
    max-width: 280px;
    line-height: 1.5;
    margin-bottom: var(--s-3);
}

.ca-empty-icon {
    font-size: 32px;
    color: #9FB3C8;
    opacity: 0.8;
}

/* Onboarding / Welcome card */
.ca-welcome {
    max-width: 840px;
    margin: 0 auto;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s-7) 64px;
    box-shadow: var(--sh-sm);
}

.ca-welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: rgba(99, 91, 255, 0.10);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--primary);
    margin-bottom: var(--s-4);
}

.ca-welcome-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    margin: 0 0 var(--s-2);
}

.ca-welcome-desc {
    font-size: var(--fs-3);
    color: var(--muted);
    margin: 0 0 var(--s-6);
    line-height: 1.6;
}

.ca-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: var(--s-2);
}

.ca-progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* =============================================
   FILTER BAR — единый компонент v1.2
   Export: always ghost  |  Apply: always primary
   ============================================= */
.ca-filter-bar,
.filter-card,
.card-filter {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 16px;
    box-shadow: var(--sh-sm);
}

.ca-filter-bar .input,
.ca-filter-bar .select,
.filter-card .input,
.filter-card .select,
.card-filter .input,
.card-filter .select {
    height: 40px !important;
    flex-shrink: 0;
}

.ca-filter-spacer {
    flex: 1;
    min-width: 8px;
}

/* =============================================
   TABLE
   ============================================= */
.table,
.ca-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-wrap,
.ca-table-wrap,
.ca-table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--sh-sm);
}

.ca-table-header {
    padding: var(--s-3) var(--s-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    flex-wrap: wrap;
    background: var(--surface);
}

.table th,
.ca-table th {
    text-transform: uppercase;
    font-size: var(--fs-1);
    letter-spacing: 0.06em;
    color: var(--muted);
    background: var(--surface-2);
    padding: 12px 14px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    height: 44px;
    font-weight: 600;
}

.table td,
.ca-table td {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    color: var(--text-2);
    font-size: var(--fs-2);
    height: 48px;
    vertical-align: middle;
}

.table tbody tr:first-child td {
    border-top: none;
}

.table tr:hover td,
.ca-table tbody tr:hover td {
    background: #EEF2FF;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn,
.ca-btn {
    height: 40px;
    padding: 0 14px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    font-size: var(--fs-2);
    font-weight: 650;
    font-family: var(--ca-font);
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, transform 0.05s;
    flex-shrink: 0;
    outline: none;
}

.btn:active,
.ca-btn:active {
    transform: translateY(1px);
}

.btn i,
.ca-btn i {
    font-size: 16px;
}

/* Primary */
.btn-primary,
.ca-btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--sh-sm);
}

.btn-primary:hover,
.ca-btn-primary:hover {
    background: var(--primary-hover);
    color: #fff;
}

/* Ghost */
.btn-ghost,
.ca-btn-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text-2);
}

.btn-ghost:hover,
.ca-btn-secondary:hover {
    background: var(--surface-2);
}

/* Danger */
.ca-btn-danger {
    background: var(--danger);
    color: #fff;
}

.ca-btn-danger:hover {
    background: #BE123C;
    color: #fff;
}

/* Small */
.btn-sm,
.ca-btn-sm {
    height: 32px;
    padding: 0 10px;
    font-size: var(--fs-1);
}

/* Icon-only */
.ca-btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--r-sm);
    background: transparent;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--muted);
    cursor: pointer;
    transition: background var(--ca-ease), color var(--ca-ease);
    text-decoration: none;
}

.ca-btn-icon:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* =============================================
   INPUTS & SELECTS
   ============================================= */
.input,
.select,
.ca-form-input,
.ca-form-select {
    height: 40px;
    padding: 0 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: var(--fs-2);
    color: var(--text);
    font-family: var(--ca-font);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

.input:focus,
.select:focus,
.ca-form-input:focus,
.ca-form-select:focus {
    border-color: rgba(99, 91, 255, 0.6);
    box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.12);
}

.ca-form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.ca-form-group {
    margin-bottom: var(--s-4);
}

/* =============================================
   BADGES
   ============================================= */
.badge,
.ca-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: var(--fs-1);
    font-weight: 600;
    white-space: nowrap;
}

.badge-success,
.ca-badge-success {
    background: rgba(14, 159, 110, 0.10);
    color: #047857;
}

.badge-danger,
.ca-badge-danger {
    background: rgba(225, 29, 72, 0.10);
    color: #BE123C;
}

.badge-warning,
.ca-badge-warning {
    background: rgba(245, 158, 11, 0.10);
    color: #92400E;
}

.badge-info,
.ca-badge-info {
    background: rgba(99, 91, 255, 0.10);
    color: #4F46E5;
}

.badge-secondary,
.ca-badge-neutral {
    background: var(--surface-2);
    color: var(--muted);
}

/* =============================================
   MODALS
   ============================================= */
.ca-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 37, 64, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: var(--s-5);
}

.ca-modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--sh-md);
}

.ca-modal-header {
    padding: var(--s-5) var(--s-6) var(--s-4);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ca-modal-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.ca-modal-body {
    padding: var(--s-5) var(--s-6);
}

.ca-modal-footer {
    padding: var(--s-4) var(--s-6);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--s-2);
}

/* Legacy .ca-modal-close */
.ca-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    color: var(--muted);
    line-height: 1;
    padding: 4px;
    transition: color var(--ca-ease);
}

.ca-modal-close:hover {
    color: var(--danger);
}

/* =============================================
   STATUS DOT
   ============================================= */
.ca-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ca-status-dot.online {
    background: var(--success);
    animation: pulse-dot 2s infinite;
}

.ca-status-dot.offline {
    background: var(--muted);
}

@keyframes pulse-dot {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(14, 159, 110, 0.15);
    }

    50% {
        box-shadow: 0 0 0 5px transparent;
    }
}

/* =============================================
   FLASH MESSAGES
   ============================================= */
.ca-flash-success {
    background: #F0FDF4;
    color: #047857;
    border: 1px solid #A7F3D0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px var(--s-4);
    border-radius: var(--r-sm);
    font-size: var(--fs-2);
    font-weight: 500;
    margin-bottom: 12px;
}

.ca-flash-error {
    background: #FFF1F2;
    color: #BE123C;
    border: 1px solid #FECDD3;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px var(--s-4);
    border-radius: var(--r-sm);
    font-size: var(--fs-2);
    font-weight: 500;
    margin-bottom: 12px;
}

/* =============================================
   LANG SWITCHER
   ============================================= */
.ca-lang-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 2px;
}

.ca-lang-btn {
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    transition: background var(--ca-ease), color var(--ca-ease);
}

.ca-lang-btn.active,
.ca-lang-btn:hover {
    background: var(--surface);
    color: var(--text);
}

/* =============================================
   UTILITIES
   ============================================= */
.ca-text-muted {
    color: var(--muted) !important;
}

.ca-text-primary {
    color: var(--text) !important;
}

.ca-text-success {
    color: var(--success) !important;
}

.ca-text-danger {
    color: var(--danger) !important;
}

.ca-text-warning {
    color: var(--warning) !important;
}

.ca-fw-500 {
    font-weight: 500 !important;
}

.ca-fw-600 {
    font-weight: 600 !important;
}

.ca-fw-700 {
    font-weight: 700 !important;
}

.ca-fs-12 {
    font-size: 12px !important;
}

.ca-fs-13 {
    font-size: 13px !important;
}

.ca-fs-14 {
    font-size: 14px !important;
}

.ca-flex {
    display: flex;
}

.ca-flex-col {
    display: flex;
    flex-direction: column;
}

.ca-items-center {
    align-items: center;
}

.ca-justify-between {
    justify-content: space-between;
}

.ca-gap-8 {
    gap: 8px;
}

.ca-gap-12 {
    gap: 12px;
}

.ca-gap-16 {
    gap: 16px;
}

.ca-mb-4 {
    margin-bottom: 4px;
}

.ca-mb-8 {
    margin-bottom: 8px;
}

.ca-mb-16 {
    margin-bottom: var(--s-4);
}

.ca-mb-24 {
    margin-bottom: var(--s-6);
}

.ca-mt-16 {
    margin-top: var(--s-4);
}

.ca-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: var(--s-4) 0;
}

.ca-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Violations compat */
.dashboard-container {
    max-width: 1120px;
    margin: 0 auto;
    padding: var(--s-6) var(--s-7);
}