:root {
    --bg: #f5f6fb;
    --panel: #fff;
    --ink: #17152b;
    --muted: #737286;
    --line: #e9e8f1;
    --purple: #6d4aff;
    --purple-dark: #5132db;
    --cyan: #16b8c9;
    --orange: #f59d3d;
    --green: #2eb67d;
    --red: #d94a63;
    --sidebar: #17152c;
    --shadow: 0 12px 35px rgba(33, 25, 75, .07);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
body { margin: 0; min-width: 320px; }
a { color: var(--purple-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
code { font-family: "SFMono-Regular", Consolas, monospace; font-size: .86em; color: #443b71; }
.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; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 20px 20px; color: #fff; background: linear-gradient(175deg, #1e193a 0%, #121022 100%); z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 0 8px 30px; }
.brand:hover { text-decoration: none; }
.brand span:last-child { display: flex; flex-direction: column; }
.brand small { color: #9991c7; font-size: 11px; margin-top: 2px; letter-spacing: .03em; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(145deg, #8b71ff, #5533e8); color: #fff; font-weight: 800; box-shadow: 0 8px 20px rgba(109,74,255,.35); }
.brand-mark.large { width: 52px; height: 52px; margin-bottom: 22px; font-size: 22px; }
.main-nav { display: flex; flex-direction: column; gap: 5px; }
.main-nav a { position: relative; padding: 12px 14px; border-radius: 10px; color: #bdb8dc; font-size: 14px; font-weight: 600; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.06); text-decoration: none; }
.main-nav a.active { color: #fff; background: linear-gradient(90deg, rgba(109,74,255,.34), rgba(109,74,255,.08)); }
.main-nav a.active::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: #947dff; }
.sidebar-user { margin-top: auto; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; border-top: 1px solid rgba(255,255,255,.09); padding: 20px 5px 0; }
.sidebar-user strong, .sidebar-user small { display: block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user strong { font-size: 13px; }
.sidebar-user small { margin-top: 3px; color: #938dae; font-size: 11px; text-transform: capitalize; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #35304f; color: #c8c0ff; font-weight: 800; }
.icon-button { border: 0; background: transparent; color: #8d87a7; font-size: 19px; }
.icon-button:hover { color: #fff; }

.page { min-width: 0; }
.topbar { height: 94px; display: flex; align-items: center; gap: 15px; padding: 18px 36px; background: rgba(245,246,251,.9); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 2px 0 0; font-size: 25px; line-height: 1.1; }
.eyebrow { margin: 0; color: var(--purple); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .13em; }
.menu-button, .mobile-profile { display: none; }
.content { max-width: 1500px; padding: 28px 36px 50px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 18px; margin-bottom: 20px; }
.stat-card { position: relative; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 22px; box-shadow: var(--shadow); }
.stat-card::after { content: ""; position: absolute; width: 80px; height: 80px; right: -25px; top: -28px; border-radius: 50%; opacity: .12; background: currentColor; }
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card span { font-size: 13px; font-weight: 650; }
.stat-card strong { display: block; margin: 9px 0 6px; font-size: 29px; color: var(--ink); }
.stat-card small { font-size: 11px; }
.accent-purple { color: var(--purple); border-top: 3px solid var(--purple); }
.accent-cyan { color: var(--cyan); border-top: 3px solid var(--cyan); }
.accent-orange { color: var(--orange); border-top: 3px solid var(--orange); }
.accent-green { color: var(--green); border-top: 3px solid var(--green); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; margin-bottom: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.dashboard-grid .panel { margin-bottom: 0; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; margin-bottom: 20px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 17px; }
.panel-heading > a { font-size: 12px; font-weight: 700; }
.distribution-list > div { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.distribution-list > div:last-child { border-bottom: 0; }
.distribution-list span { display: flex; gap: 8px; align-items: center; }
.app-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--purple); }
.trend-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; height: 215px; padding-top: 6px; }
.trend-column { display: grid; grid-template-rows: 20px 1fr 22px; min-width: 0; text-align: center; }
.trend-value { color: var(--muted); font-size: 10px; }
.trend-track { position: relative; height: 100%; border-radius: 7px; background: #f0eff7; overflow: hidden; }
.trend-bar { position: absolute; left: 0; right: 0; bottom: 0; min-height: 3px; border-radius: 7px; background: linear-gradient(180deg, #8c74ff, #5f3fe5); transition: height .4s ease; }
.trend-bar.level-0 { height: 2%; } .trend-bar.level-1 { height: 10%; } .trend-bar.level-2 { height: 20%; } .trend-bar.level-3 { height: 30%; } .trend-bar.level-4 { height: 40%; } .trend-bar.level-5 { height: 50%; } .trend-bar.level-6 { height: 60%; } .trend-bar.level-7 { height: 70%; } .trend-bar.level-8 { height: 80%; } .trend-bar.level-9 { height: 90%; } .trend-bar.level-10 { height: 100%; }
.trend-column small { padding-top: 7px; color: var(--muted); font-size: 10px; }
.device-compact-list { display: flex; flex-direction: column; }
.device-compact-list a { display: grid; grid-template-columns: 36px 1fr; align-items: center; gap: 10px; padding: 10px 0; color: var(--ink); border-bottom: 1px solid var(--line); }
.device-compact-list a:hover { text-decoration: none; }
.device-compact-list a:last-child { border: 0; }
.device-compact-list strong, .device-compact-list small { display: block; }
.device-compact-list strong { font-size: 13px; }
.device-compact-list small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.device-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #f0edff; color: var(--purple); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 11px 12px; color: var(--muted); background: #fafafd; border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbff; }
.actions { text-align: right; white-space: nowrap; }
.actions a, .link-button { font-weight: 700; font-size: 11px; }
.action-group { display: flex; justify-content: flex-end; gap: 12px; }
.link-button { padding: 0; color: var(--red); background: none; border: 0; }
.table-subtitle { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.app-badge, .role-badge, .status { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 20px; font-size: 10px; font-weight: 750; white-space: nowrap; }
.app-badge { color: #5337cb; background: #f0edff; }
.role-badge { color: #4d4963; background: #efeff4; text-transform: capitalize; }
.status-success { color: #177651; background: #e4f7ef; }
.status-warning { color: #9a5c10; background: #fff1d9; }
.status-muted { color: #6f6d79; background: #eeeef2; }

.filter-bar { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.filter-bar input { min-width: 250px; flex: 1; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(150px,1fr)); gap: 14px; align-items: end; }
.filter-grid label, .form-stack label { display: flex; flex-direction: column; gap: 7px; }
.filter-grid label span, .form-stack label > span { color: #4d4a61; font-size: 11px; font-weight: 750; }
.filter-actions { display: flex; gap: 8px; align-items: center; }
input, select { width: 100%; min-height: 41px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #dcd9e8; border-radius: 9px; outline: none; }
input:focus, select:focus { border-color: #8d76ff; box-shadow: 0 0 0 3px rgba(109,74,255,.1); }
input[readonly] { color: var(--muted); background: #f4f3f7; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 41px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 750; font-size: 12px; cursor: pointer; }
.button:hover { text-decoration: none; }
.button-primary { color: #fff; background: var(--purple); box-shadow: 0 6px 15px rgba(109,74,255,.18); }
.button-primary:hover { background: var(--purple-dark); }
.button-light { color: #4f4b63; background: #f2f1f6; }
.button-block { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding-top: 18px; color: var(--muted); font-size: 11px; }
.pagination a { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-weight: 700; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 20px; }
.detail-grid > .panel { align-self: start; }
.page-actions { margin-bottom: 14px; }
.page-actions.align-right { display: flex; justify-content: flex-end; }
.back-link { color: var(--muted); font-size: 12px; font-weight: 700; }
.metadata { margin: 0; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 25px; }
.metadata > div { min-width: 0; padding: 12px 0; border-bottom: 1px solid var(--line); }
.metadata dt, .payload-data dt { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.metadata dd, .payload-data dd { margin: 0; font-size: 12px; }
.metadata.compact { grid-template-columns: 1fr; margin-bottom: 22px; }
.breakable { word-break: break-all; }
.payload-locked { padding: 45px 20px; text-align: center; }
.payload-locked > span { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 15px; border-radius: 50%; color: var(--purple); background: #f0edff; font-size: 25px; }
.payload-locked h3 { margin: 0 0 7px; font-size: 15px; }
.payload-locked p { margin: 0 auto 18px; max-width: 330px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.payload-data { margin: 0; }
.payload-data > div { padding: 11px 0; border-bottom: 1px solid var(--line); }
.payload-data .payload-message dd { padding: 13px; border-radius: 9px; background: #f7f6fb; white-space: normal; overflow-wrap: anywhere; line-height: 1.55; }
.privacy-note { color: var(--muted); font-size: 10px; }

.alert { margin-bottom: 16px; padding: 12px 15px; border-radius: 9px; font-size: 12px; line-height: 1.5; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-error { color: #9e2940; background: #fdebef; border: 1px solid #f8ced7; }
.alert-success { color: #176c4b; background: #e7f8f0; border: 1px solid #c8eddd; }
.form-panel { max-width: 900px; }
.form-stack { display: flex; flex-direction: column; gap: 17px; }
.form-stack small { color: var(--muted); font-size: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 17px; }

.auth-page { min-height: 100vh; background: radial-gradient(circle at 20% 20%, #eee9ff, transparent 38%), radial-gradient(circle at 80% 75%, #dff6fa, transparent 36%), #f7f7fb; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 25px; }
.setup-wrap { min-height: 100vh; display: grid; place-items: center; padding: 35px 20px; }
.auth-card { width: 100%; max-width: 430px; padding: 38px; border: 1px solid rgba(220,217,232,.8); border-radius: 20px; background: rgba(255,255,255,.92); box-shadow: 0 25px 70px rgba(44,32,92,.13); }
.setup-card { max-width: 760px; }
.setup-section { padding-top: 4px; }
.setup-section h2 { margin: 0 0 14px; padding-bottom: 9px; border-bottom: 1px solid var(--line); font-size: 14px; }
.full-field { grid-column: 1 / -1; }
.secret-result { margin: 20px 0; }
.secret-result p { margin: 16px 0 7px; }
.secret-result p:first-child { margin-top: 0; }
.secret-result small { display: block; margin-top: 4px; color: var(--muted); font-weight: 400; }
.secret-result code { display: block; padding: 12px; overflow-wrap: anywhere; border-radius: 8px; background: #f3f1fb; }
.auth-heading { margin-bottom: 26px; }
.auth-heading h1 { margin: 6px 0 8px; font-size: 25px; }
.auth-heading > p:last-child { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.error-card { text-align: center; }
.error-card h1 { margin: 5px 0 8px; }
.error-card p { color: var(--muted); margin-bottom: 22px; }
.error-code { color: var(--purple); font-size: 45px; font-weight: 850; }
.sidebar-overlay { display: none; }

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .filter-grid { grid-template-columns: repeat(3,minmax(150px,1fr)); }
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 260px; transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.visible { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(13,11,27,.45); }
    .topbar { height: 78px; padding: 14px 20px; }
    .topbar h1 { font-size: 20px; }
    .menu-button { display: inline-flex; padding: 7px; border: 0; background: none; font-size: 22px; }
    .mobile-profile { display: block; margin-left: auto; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 700; }
    .content { padding: 20px; }
    .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
    .filter-grid { grid-template-columns: repeat(2,minmax(140px,1fr)); }
}

@media (max-width: 560px) {
    .stat-grid, .filter-grid, .form-grid { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .panel { padding: 16px; border-radius: 12px; }
    .stat-grid { gap: 12px; }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .filter-bar input { min-width: 0; }
    .filter-actions { grid-column: 1; }
    .metadata { grid-template-columns: 1fr; }
    .pagination { flex-wrap: wrap; justify-content: center; }
    .auth-card { padding: 27px 22px; }
}
