:root {
    font-size: 14px;
    --navy: #111827;
    --ink: #172033;
    --muted: #687387;
    --line: #e3e8ef;
    --surface: #fff;
    --canvas: #f4f6f8;
    --accent: #2563eb;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 1rem/1.45 Inter, ui-sans-serif, system-ui, sans-serif; }
button, input { font: inherit; }

.admin-shell { min-height: 100vh; display: flex; }
.admin-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 210px; display: flex; flex-direction: column; background: var(--navy); color: #fff; }
.admin-brand { height: 66px; display: flex; align-items: center; gap: 11px; padding: 0 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.admin-brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; background: #2563eb; font-size: .857rem; font-weight: 800; letter-spacing: .03em; }
.admin-brand strong, .admin-brand small { display: block; line-height: 1.2; }
.admin-brand strong { font-size: 1rem; }
.admin-brand small { margin-top: 3px; color: #8794a9; font-size: .857rem; text-transform: uppercase; letter-spacing: .08em; }
.admin-nav { padding: 14px 10px; flex: 1; }
.admin-nav-link { display: flex; align-items: center; gap: 10px; margin-bottom: 3px; padding: 10px; border-radius: 6px; color: #a8b3c4; font-size: .929rem; font-weight: 600; text-decoration: none; transition: .15s; }
.admin-nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.admin-nav-link.active { background: #2563eb; color: #fff; }
.admin-nav-icon { width: 18px; text-align: center; font-size: 1.143rem; }
.admin-signout { padding: 12px 10px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.admin-signout button { width: 100%; display: flex; gap: 10px; border: 0; background: transparent; color: #9ba7ba; padding: 10px; border-radius: 6px; cursor: pointer; font-size: .929rem; }
.admin-signout button:hover { background: rgba(255,255,255,.06); color: #fff; }

.admin-main { width: calc(100% - 210px); min-width: 0; margin-left: 210px; padding: 28px 32px 44px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 21px; }
.page-header h1 { margin: 3px 0 0; font-size: 1.857rem; line-height: 1.15; letter-spacing: -.025em; font-weight: 700; }
.eyebrow { font-size: .857rem; line-height: 1; text-transform: uppercase; letter-spacing: .11em; font-weight: 750; color: #7d8899; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.live-indicator { font-size: .929rem; color: #737f91; }
.live-indicator i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.admin-button { border: 1px solid #d2d9e3; border-radius: 6px; background: #fff; color: #354052; padding: 8px 12px; cursor: pointer; font-size: .929rem; font-weight: 650; box-shadow: 0 1px 1px rgba(15,23,42,.03); }
.admin-button:hover { border-color: #aeb8c7; background: #fafbfc; }

.admin-panel { overflow: visible; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 2px rgba(15,23,42,.025); }
.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.025); }
.metric { padding: 16px 18px; border-right: 1px solid var(--line); }
.metric:last-child { border: 0; }
.metric span, .metric small { display: block; }
.metric span { font-size: .857rem; color: #707c8f; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.metric strong { display: block; margin: 5px 0 2px; font-size: 1.714rem; line-height: 1.15; letter-spacing: -.02em; }
.metric small { font-size: .929rem; color: #8994a5; }
.status-ok { color: #159447; }
.status-warn { color: #d97706; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(270px,.7fr); gap: 16px; margin-bottom: 16px; }
.admin-panel-header { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid #edf0f4; }
.admin-panel-header h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.admin-panel-header p { margin: 3px 0 0; font-size: .929rem; color: #7e899a; }
.panel-total { font-size: 1.286rem; }
.text-link { font-size: .929rem; color: var(--accent); font-weight: 650; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.compact-list { padding: 8px 16px 11px; }
.compact-row { min-height: 33px; display: grid; grid-template-columns: minmax(150px,1fr) minmax(70px,1.5fr) 48px; align-items: center; gap: 13px; border-bottom: 1px solid #f0f2f5; font-size: .929rem; }
.compact-row:last-child { border: 0; }
.compact-row span { display: flex; align-items: center; min-width: 0; }
.compact-row strong { text-align: right; font-size: 1rem; }
.module-dot { width: 8px; height: 8px; flex: 0 0 auto; margin-right: 9px; border-radius: 2px; }
.dot-blue { background:#3b82f6; } .dot-violet { background:#8b5cf6; } .dot-cyan { background:#06b6d4; } .dot-orange { background:#f97316; } .dot-emerald { background:#10b981; } .dot-pink { background:#ec4899; } .dot-yellow { background:#eab308; } .dot-red { background:#ef4444; }
.row-bar { height: 4px; overflow: hidden; border-radius: 3px; background: #eef1f5; }
.row-bar i { display: block; height: 100%; border-radius: 3px; background: #8795aa; }
.instruments-list .compact-row { grid-template-columns: 1fr 55px; min-height: 38px; }

.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { padding: 10px 14px; background: #f8f9fb; border-bottom: 1px solid var(--line); text-align: left; font-size: .857rem; color: #737f91; text-transform: uppercase; letter-spacing: .05em; font-weight: 750; white-space: nowrap; }
.admin-table td { padding: 10px 14px; border-bottom: 1px solid #edf0f4; color: #475267; font-size: .929rem; vertical-align: middle; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover td { background: #fafbfd; }
.admin-table .num { text-align: right; }
.primary-cell { font-weight: 650; color: #263247; font-size: 1rem; }
.secondary-cell { margin-top: 2px; font-size: .857rem; color: #8994a5; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .929em; }
.count-pill { display: inline-grid; place-items: center; min-width: 28px; height: 22px; padding: 0 6px; border-radius: 5px; background: #edf4ff; color: #2563eb; font-weight: 750; }
.empty-cell, .empty-state { text-align: center !important; color: #7d899a !important; }
.empty-state { padding: 46px 20px; font-size: 1rem; }

/* Connections workspace */
.connection-kpis { display: grid; grid-template-columns: repeat(4,minmax(140px,1fr)); margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.connection-kpis div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 15px; border-right: 1px solid var(--line); }
.connection-kpis div:last-child { border: 0; }
.connection-kpis span { color: #6f7a8c; font-size: .929rem; }
.connection-kpis strong { font-size: 1.286rem; color: #202b3f; }
.connections-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.search-box { width: min(530px,100%); height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 11px; border: 1px solid #d2d9e3; border-radius: 7px; background: #fff; color: #7d899a; box-shadow: 0 1px 2px rgba(15,23,42,.025); }
.search-box:focus-within { border-color: #7aa5f8; box-shadow: 0 0 0 3px #e5efff; }
.search-box > span { font-size: 1.286rem; line-height: 1; }
.search-box input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: #263247; font-size: 1rem; }
.search-box input::placeholder { color: #929cac; }
.search-box button { border: 0; background: transparent; color: #7e8999; cursor: pointer; font-size: 1.286rem; line-height: 1; }
.result-count { color: #778294; font-size: .929rem; white-space: nowrap; }
.connection-list { display: grid; gap: 12px; }
.connection-user { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.025); }
.connection-user-header { display: grid; grid-template-columns: 36px minmax(220px,1fr) minmax(170px,.55fr) 110px 100px; align-items: center; gap: 11px; padding: 12px 15px; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.user-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: #e7eefb; color: #315ea8; font-size: 1rem; font-weight: 800; }
.user-main { min-width: 0; }
.user-main strong, .user-main span, .user-telegram span, .user-telegram strong, .user-total strong, .user-total span { display: block; }
.user-main strong { overflow: hidden; text-overflow: ellipsis; color: #202b3f; font-size: 1rem; white-space: nowrap; }
.user-main span { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; color: #7d899a; font-size: .857rem; white-space: nowrap; }
.user-telegram span, .user-total span { color: #7d899a; font-size: .857rem; }
.user-telegram strong { margin-top: 2px; color: #465269; font-size: .929rem; }
.user-total { text-align: right; }
.user-total strong { font-size: 1.143rem; color: #202b3f; }
.connection-columns, .connection-row { display: grid; grid-template-columns: minmax(220px,.75fr) 155px minmax(300px,1.7fr) 100px; align-items: center; gap: 15px; }
.connection-columns { padding: 8px 15px; border-bottom: 1px solid #edf0f4; background: #f7f9fb; color: #707c8e; font-size: .857rem; font-weight: 700; text-transform: uppercase; letter-spacing: .045em; }
.connection-record { border-bottom: 1px solid #edf0f4; }
.connection-record:last-child { border-bottom: 0; }
.connection-record.expanded { background: #fbfdff; }
.connection-row { min-height: 54px; padding: 8px 15px; }
.connection-row:hover { background: #fafbfd; }
.connection-name { min-width: 0; display: flex; align-items: center; gap: 7px; }
.connection-name strong { overflow: hidden; text-overflow: ellipsis; color: #344157; font-size: .929rem; white-space: nowrap; }
.copy-id { flex: 0 0 auto; padding: 2px 5px; border: 1px solid #dce2ea; border-radius: 4px; background: #fff; color: #7b8697; cursor: pointer; font-size: .786rem; font-weight: 700; }
.connection-time { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.connection-time strong { color: #465269; font-size: .929rem; font-weight: 600; }
.connection-time span { color: #7d899a; font-size: .857rem; }
.module-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.module-chip { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 3px 7px; border-radius: 5px; background: #eef2f6; color: #536076; font-size: .857rem; white-space: nowrap; }
.module-chip strong { font-size: .857rem; }
.chip-iceberg { background: #e5f8fb; color: #087e91; } .chip-activity { background: #eaf2ff; color: #2862ad; } .chip-deals { background: #f1ebff; color: #6b42ab; } .chip-price { background: #fff0e6; color: #b55417; } .chip-volume { background: #e7f8f0; color: #187a51; } .chip-slabs { background: #fceaf3; color: #a33d6e; } .chip-futures { background: #fff7d9; color: #8c6b06; } .chip-robots { background: #feecec; color: #af3a3a; }
.no-subscriptions { color: #9a6d28; font-size: .929rem; }
.details-button { display: flex; align-items: center; justify-content: flex-end; gap: 5px; width: 100%; border: 0; background: transparent; color: #2563eb; cursor: pointer; font-size: .929rem; font-weight: 650; }
.details-button span { display: grid; place-items: center; min-width: 24px; height: 22px; padding: 0 5px; border-radius: 5px; background: #edf4ff; }
.details-button i { font-size: 1.286rem; font-style: normal; transition: transform .15s; }
.connection-record.expanded .details-button i { transform: rotate(90deg); }
.details-button:disabled { color: #a0a8b4; cursor: default; }
.subscription-inspector { border-top: 1px solid #dce4ef; background: #f7f9fc; }
.subscription-module { display: grid; grid-template-columns: 155px minmax(0,1fr); border-bottom: 1px solid #dfe5ed; }
.subscription-module:last-child { border-bottom: 0; }
.subscription-module-header { display: flex; align-items: flex-start; gap: 8px; padding: 11px 12px 10px 15px; border-right: 1px solid #dfe5ed; color: #354157; font-size: .929rem; }
.subscription-module-header .module-dot { margin: 5px 0 0; }
.subscription-module-header strong { min-width: 0; flex: 1; }
.subscription-module-count { display: grid; place-items: center; min-width: 23px; height: 21px; padding: 0 5px; border-radius: 4px; background: #e8edf4; color: #667287; font-size: .857rem; font-weight: 700; }
.subscription-entries { min-width: 0; background: #fff; }
.activity-subscriptions { padding: 10px 13px; color: #455268; font-size: .929rem; line-height: 1.5; overflow-wrap: anywhere; }
.subscription-entry { display: grid; grid-template-columns: minmax(170px, .65fr) minmax(0, 2.35fr); align-items: start; gap: 14px; padding: 9px 13px; border-bottom: 1px solid #edf0f4; }
.subscription-entry:last-child { border-bottom: 0; }
.subscription-id { min-width: 0; }
.subscription-id span { display: block; margin-bottom: 2px; color: #7a8698; font-size: .786rem; text-transform: uppercase; letter-spacing: .04em; }
.subscription-id strong { display: block; overflow: hidden; text-overflow: ellipsis; color: #263247; font-size: .929rem; font-weight: 650; white-space: nowrap; }
.parameter-flow { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 5px 16px; min-width: 0; margin: 0; }
.parameter-pair { display: flex; align-items: baseline; gap: 5px; min-width: 0; margin: 0; }
.parameter-pair dt { flex: 0 0 auto; color: #7a8698; font-size: .857rem; }
.parameter-pair dt::after { content: ":"; }
.parameter-pair dd { min-width: 0; margin: 0; color: #455268; font-size: .929rem; line-height: 1.45; overflow-wrap: anywhere; }
.parameter-assets { flex: 1 1 420px; }
.parameter-assets dd { columns: 2 230px; column-gap: 18px; }
.parameter-list { flex: 1 1 100%; }
.parameter-list dd { line-height: 1.6; word-spacing: 4px; }

/* Database users */
.database-indicator i { background: #64748b; box-shadow: 0 0 0 3px #e2e8f0; }
.user-kpis { display: grid; grid-template-columns: repeat(5,minmax(130px,1fr)); margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.user-kpis div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 15px; border-right: 1px solid var(--line); }
.user-kpis div:last-child { border-right: 0; }
.user-kpis span { color: #6f7a8c; font-size: .929rem; }
.user-kpis strong { color: #202b3f; font-size: 1.286rem; }
.users-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.users-search { width: min(520px,100%); }
.status-filter { display: inline-flex; padding: 3px; border: 1px solid #d5dce5; border-radius: 7px; background: #fff; }
.status-filter button { border: 0; border-radius: 5px; background: transparent; padding: 6px 10px; color: #657186; cursor: pointer; font-size: .929rem; }
.status-filter button:hover { color: #263247; }
.status-filter button.active { background: #eaf1fd; color: #245cae; font-weight: 650; }
.users-panel { overflow: hidden; }
.users-table { min-width: 1100px; }
.sort-header { width: 100%; display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; margin: -10px -14px; padding: 10px 14px; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; font-weight: inherit; letter-spacing: inherit; text-align: left; text-transform: inherit; white-space: nowrap; }
.sort-header:hover { background: #eef2f7; color: #344157; }
.sort-header span { color: #a0a9b6; font-size: .929rem; }
th[aria-sort="ascending"] .sort-header, th[aria-sort="descending"] .sort-header { color: #245cae; }
th[aria-sort="ascending"] .sort-header span, th[aria-sort="descending"] .sort-header span { color: #2563eb; }
.users-table td { height: 54px; }
.user-name-cell { display: flex; align-items: center; gap: 7px; color: #263247; font-size: 1rem; font-weight: 650; }
.online-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.user-handle { margin-top: 2px; color: #7d899a; font-size: .857rem; }
.user-status { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: .857rem; font-weight: 650; white-space: nowrap; }
.current-activity-heading { min-width: 145px; }
.current-activity { white-space: nowrap; }
.current-activity strong { display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 6px; border-radius: 5px; background: #edf4ff; color: #2563eb; font-size: .929rem; }
.current-activity span { margin: 0 5px; color: #9aa4b2; }
.status-paid { background: #e7f8ef; color: #17784d; }
.status-expired { background: #fff1e5; color: #a85418; }
.status-disabled { background: #f0f2f5; color: #687386; }
.status-none { background: #f4efff; color: #7147a9; }
.date-primary, .date-relative { display: block; white-space: nowrap; }
.date-primary { color: #465269; font-size: .929rem; }
.date-relative { margin-top: 2px; color: #8490a1; font-size: .857rem; }
.database-id { max-width: 145px; overflow: hidden; text-overflow: ellipsis; color: #657186 !important; white-space: nowrap; }
.users-footer { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 9px 13px; border-top: 1px solid var(--line); color: #707c8e; font-size: .929rem; }
.pagination { display: flex; align-items: center; gap: 10px; }
.pagination button { border: 1px solid #d5dce5; border-radius: 5px; background: #fff; padding: 6px 9px; color: #465269; cursor: pointer; font-size: .857rem; }
.pagination button:hover:not(:disabled) { border-color: #aeb8c7; }
.pagination button:disabled { opacity: .45; cursor: default; }
.users-error { display: flex; flex-direction: column; gap: 5px; padding: 16px; border-color: #fecaca; color: #991b1b; font-size: .929rem; }

@media (max-width: 1000px) {
    .admin-sidebar { position: static; width: 100%; height: auto; display: block; }
    .admin-shell { display: block; }
    .admin-brand { display: none; }
    .admin-nav { display: flex; padding: 8px; }
    .admin-nav-link { margin: 0; }
    .admin-signout { display: none; }
    .admin-main { width: 100%; margin: 0; padding: 22px 17px 36px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .connection-user-header { grid-template-columns: 36px minmax(180px,1fr) 155px 100px 90px; }
    .connection-columns, .connection-row { grid-template-columns: minmax(180px,.8fr) 145px minmax(250px,1.4fr) 90px; }
    .user-kpis { grid-template-columns: repeat(3,1fr); }
    .user-kpis div:nth-child(3) { border-right: 0; }
    .user-kpis div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
    .metric-strip, .connection-kpis { grid-template-columns: repeat(2,1fr); }
    .metric:nth-child(2), .connection-kpis div:nth-child(2) { border-right: 0; }
    .metric:nth-child(-n+2), .connection-kpis div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .connections-toolbar { align-items: stretch; flex-direction: column; gap: 7px; }
    .users-toolbar { align-items: stretch; flex-direction: column; gap: 8px; }
    .status-filter { width: fit-content; }
    .result-count { padding-left: 2px; }
    .connection-user-header { grid-template-columns: 36px 1fr 85px 75px; }
    .user-telegram { display: none; }
    .connection-columns { display: none; }
    .connection-row { grid-template-columns: 1fr auto; gap: 8px 12px; padding: 12px; }
    .connection-time { grid-column: 2; grid-row: 1; justify-content: flex-end; text-align: right; }
    .module-chips { grid-column: 1 / -1; }
    .details-button { grid-column: 1 / -1; justify-content: flex-start; width: auto; }
}

@media (max-width: 500px) {
    .page-header { align-items: flex-start; }
    .live-indicator { display: none; }
    .connection-user-header { grid-template-columns: 36px 1fr 75px; }
    .user-total:last-child { display: none; }
    .subscription-module { grid-template-columns: 1fr; }
    .subscription-module-header { align-items: center; padding: 8px 11px; border-right: 0; border-bottom: 1px solid #e5e9ef; }
    .subscription-module-header .module-dot { margin-top: 0; }
    .subscription-entry { grid-template-columns: 1fr; gap: 6px; }
    .parameter-assets dd { columns: 1; }
    .user-kpis { grid-template-columns: repeat(2,1fr); }
    .user-kpis div { border-bottom: 1px solid var(--line); }
    .user-kpis div:nth-child(odd) { border-right: 1px solid var(--line); }
    .user-kpis div:nth-child(even) { border-right: 0; }
    .user-kpis div:last-child { border-bottom: 0; }
    .users-footer { align-items: flex-start; flex-direction: column; }
}
