/* ====== CSS Variables ====== */
:root {
  color-scheme: dark;
  --bg-primary: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #16213e;
  --text-primary: #e0e0e0;
  --text-secondary: #888888;
  --accent-blue: #4fc3f7;
  --accent-orange: #ffcc80;
  --accent-purple: #ce93d8;
  --accent-green: #a5d6a7;
  --accent-red: #ef9a9a;
  --positive: #4caf50;
  --negative: #f44336;
  --border: #0f3460;
  /* 兼容别名：部分页面（blacklist/ads 等）使用这些名字 */
  --border-color: var(--border);
  --bg-input: var(--bg-primary);
  --tag-spoof: var(--negative);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

.skip-link {
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 1000;
  padding: .55rem .8rem;
  border-radius: 6px;
  background: var(--accent-blue);
  color: #000;
  transform: translateY(-180%);
}
.skip-link:focus-visible { transform: translateY(0); }

button, a { touch-action: manipulation; }

:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  color-scheme: dark;
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ====== Login Overlay ====== */
.login-overlay {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg-primary);
}
.login-card {
  background: var(--bg-card); border-radius: 12px;
  padding: 3rem 2.5rem; width: 380px; max-width: 90vw;
  text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.login-card h2 { font-size: 1.5rem; margin-bottom: .5rem; color: var(--accent-blue); }
.login-card .subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%; padding: .75rem; font-size: 1rem;
  background: var(--bg-primary); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 6px;
  transition: border-color .2s;
}
.login-card input[type="password"]:focus,
.login-card input[type="text"]:focus { border-color: var(--accent-blue); }
.login-card input[type="text"] { margin-bottom: .5rem; }
.login-card button {
  width: 100%; margin-top: 1rem; padding: .75rem; font-size: 1rem;
  background: var(--accent-blue); color: #000; border: none;
  border-radius: 6px; cursor: pointer; font-weight: 600;
}
.login-card button:hover { opacity: .9; }
.error-msg { color: var(--negative); margin-top: .75rem; font-size: .9rem; }

/* ====== Top Bar ====== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; background: var(--bg-card);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: .5rem;
}
.topbar h1 { font-size: 1.25rem; color: var(--accent-blue); }
.topbar-info { font-size: .75rem; color: var(--text-secondary); margin-left: auto; margin-right: 1rem; }
.topbar-controls { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.range-buttons { display: flex; gap: .25rem; }
.range-buttons button, .range-buttons input {
  padding: .35rem .75rem; font-size: .85rem;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 4px; cursor: pointer;
  transition: background .2s;
}
.range-buttons button.active { background: var(--accent-blue); color: #000; border-color: var(--accent-blue); }
.range-buttons button:hover:not(.active) { background: var(--bg-card-hover); }

#granularity-select, #logout-btn {
  padding: .35rem .75rem; font-size: .85rem;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 4px; cursor: pointer;
}
#logout-btn:hover { color: var(--accent-red); border-color: var(--accent-red); }

/* ====== Section Headers ====== */
.dashboard-section { margin-bottom: 1.5rem; }
.section-title {
  font-size: 1.1rem; font-weight: 600; color: var(--text-primary);
  margin-bottom: .25rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.section-desc { font-size: .8rem; color: var(--text-secondary); margin-bottom: .75rem; }

/* ====== Layout ====== */
#app { display: flex; min-height: 100vh; }

.overview-cards {
  display: grid; gap: 1rem; margin-bottom: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.overview-card {
  background: var(--bg-card); border-radius: 8px; padding: 1.25rem;
  text-align: center; border: 1px solid var(--border);
  transition: transform .15s, box-shadow .15s;
}
.overview-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.overview-card .label { font-size: .8rem; color: var(--text-secondary); text-transform: uppercase; }
.overview-card .value { font-size: 1.75rem; font-weight: 700; margin: .25rem 0; }
.overview-card .unit { font-size: .8rem; font-weight: 400; opacity: .6; }
.overview-card .change { font-size: .8rem; }
.overview-card .change.up { color: var(--positive); }
.overview-card .change.down { color: var(--negative); }

.charts-row {
  display: grid; gap: 1rem; margin-bottom: 1.5rem;
  grid-template-columns: 2fr 1fr;
}
.charts-row.three-col { grid-template-columns: 1fr 1fr 1fr; }

.chart-box {
  background: var(--bg-card); border-radius: 8px;
  padding: 1rem; border: 1px solid var(--border);
  position: relative; min-height: 280px; overflow: hidden;
}
.chart-box.large { min-height: 320px; }
.chart-box.small { min-height: 260px; }
.chart-box.medium { min-height: 260px; }
.chart-box.compact { height: 200px; min-height: auto; }
.chart-box.medium { min-height: 260px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.chart-box .no-data-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; min-height: 120px; color: var(--text-secondary);
}
.chart-box .no-data-placeholder .no-data-title {
  font-size: 13px; color: #e0e0e0; margin-bottom: .5rem;
}
.chart-box .no-data-placeholder .no-data-text {
  font-size: 12px;
}

.tables-row {
  display: grid; gap: 1rem; margin-bottom: 1.5rem;
  grid-template-columns: 1fr 1fr;
}
.table-box {
  background: var(--bg-card); border-radius: 8px;
  padding: 1rem; border: 1px solid var(--border);
}
.table-box h3 { font-size: 1rem; color: var(--accent-blue); margin-bottom: .75rem; }
.table-box .table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.table-box .table-header h3 { margin-bottom: 0; }

.export-btn {
  padding: .2rem .6rem; font-size: .75rem;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 4px; cursor: pointer;
}
.export-btn:hover { color: var(--accent-blue); border-color: var(--accent-blue); }

.mac-link { color: var(--accent-blue); text-decoration: none; cursor: pointer; }
.mac-link:hover { text-decoration: underline; color: #80deea; }
.mac-filter-bar {
  padding: .35rem .75rem; font-size: .8rem;
  background: rgba(79,195,247,.1); border: 1px solid rgba(79,195,247,.3);
  border-radius: 4px; color: var(--accent-blue); margin-top: .5rem;
}
.mac-filter-bar button {
  background: transparent; border: none; color: var(--accent-red);
  cursor: pointer; margin-left: .5rem; font-size: .8rem;
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
th, td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--accent-blue); font-weight: 600; }
tr:hover { background: var(--bg-card-hover); }

.pagination { display: flex; justify-content: center; gap: .5rem; margin-top: .75rem; }
.pagination button {
  padding: .25rem .75rem; font-size: .85rem;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 4px; cursor: pointer;
}
.pagination button:hover:not(:disabled) { background: var(--bg-card-hover); }
.pagination button:disabled { opacity: .4; cursor: default; }

/* Tag Labels */
.tag { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 600; }
.tag-spoof { background: rgba(229,115,115,.3); color: #ef5350; }
.tag-studio { background: rgba(206,147,216,.2); color: var(--accent-purple); }
.tag-company { background: rgba(255,204,128,.2); color: var(--accent-orange); }
.tag-cafe { background: rgba(239,154,154,.2); color: var(--accent-red); }

/* Loading / Skeleton */
.loading { color: var(--text-secondary); text-align: center; padding: 2rem; }
.skeleton { animation: pulse 1.5s infinite; background: var(--bg-card-hover); border-radius: 4px; }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: .4; }
}

/* ====== Sidebar ====== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: 200px;
  background: #0a0a14; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.25rem 1rem; font-size: 1.15rem; font-weight: 700;
  color: var(--accent-blue); border-bottom: 1px solid var(--border);
  text-align: center;
}
.sidebar-nav { list-style: none; padding: .5rem 0; }
.sidebar-nav li { margin: .25rem 0; }
.sidebar-nav a {
  display: block; padding: .6rem 1rem; color: var(--text-secondary);
  text-decoration: none; font-size: .9rem;
  transition: color .15s, background-color .15s, border-color .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--text-primary); background: var(--bg-card-hover);
  border-left-color: var(--accent-blue);
}

.sidebar-divider { border-top: 1px solid var(--border); margin: .5rem 0; list-style: none; }

/* ====== Main Content Area ====== */
.main-content {
  margin-left: 200px;
  padding: 1.5rem;
  max-width: 1400px;
  min-height: 100vh;
  flex: 1;
}

/* ====== Detail Pages ====== */
.detail-page {
  animation: fadeIn .2s ease;
}
.detail-page > .section-title {
  margin-bottom: 1rem;
}

/* ====== Detail Toolbar ====== */
.detail-toolbar {
  display: flex; gap: .5rem; margin-bottom: 1rem; align-items: center;
  flex-wrap: wrap;
}
.detail-toolbar input[type="text"] {
  padding: .4rem .75rem; font-size: .85rem;
  background: var(--bg-primary); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 4px;
  min-width: 200px;
}
.detail-toolbar input[type="text"]:focus-visible {
  border-color: var(--accent-blue);
}
.detail-toolbar > button {
  padding: .4rem .75rem; font-size: .85rem;
  background: var(--accent-blue); color: #000; border: none;
  border-radius: 4px; cursor: pointer; font-weight: 600;
}
.detail-toolbar > button:hover { opacity: .9; }

/* ====== Filter Buttons ====== */
.filter-buttons { display: flex; gap: .25rem; }
.filter-buttons button {
  padding: .35rem .75rem; font-size: .85rem;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 4px; cursor: pointer;
  transition: background .2s;
}
.filter-buttons button.active {
  background: var(--accent-blue); color: #000; border-color: var(--accent-blue);
}
.filter-buttons button:hover:not(.active) { background: var(--bg-card-hover); }

/* ====== Type Badges ====== */
.type-badge {
  display: inline-block; padding: .1rem .4rem; border-radius: 3px;
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
}
.type-boot { background: rgba(79,195,247,.2); color: var(--accent-blue); }
.type-game_active { background: rgba(165,214,167,.2); color: var(--accent-green); }

/* ====== Sub-row / Drill-down ====== */
.sub-row td {
  background: var(--bg-primary); padding: .75rem 1.5rem;
}
.sub-row .inner-table {
  width: 100%; font-size: .8rem;
}
.sub-row .inner-table th { font-size: .75rem; }

/* ====== Cross-tab Table ====== */
.crosstab th:first-child,
.crosstab td:first-child {
  position: sticky; left: 0; background: var(--bg-card); z-index: 1;
}
.crosstab tr:hover td:first-child { background: var(--bg-card-hover); }

/* ====== Clickable Rows ====== */
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--bg-card-hover) !important; }

/* ====== Fade-in ====== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== Responsive Sidebar ====== */
@media (max-width: 768px) {
  .sidebar { width: 160px; }
  .main-content { margin-left: 160px; }
}
@media (max-width: 600px) {
  .sidebar {
    position: relative; width: 100%; bottom: auto;
    flex-direction: row; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { display: none; }
  .sidebar-nav { display: flex; padding: 0; }
  .sidebar-nav li { margin: 0; flex-shrink: 0; }
  .sidebar-nav a { border-left: none; border-bottom: 2px solid transparent; padding: .5rem .75rem; font-size: .8rem; }
  .sidebar-nav a.active { border-bottom-color: var(--accent-blue); border-left: none; }
  #app { flex-direction: column; }
  .main-content { margin-left: 0; padding: 1rem; }
}

/* Clickable overview cards */
.overview-card[data-card] { cursor: pointer; }
.overview-card[data-card]:hover { border-color: var(--accent-blue); }

/* Responsive */
@media (max-width: 900px) {
  .charts-row, .tables-row { grid-template-columns: 1fr; }
  .charts-row.three-col { grid-template-columns: 1fr; }
}

/* Monitor type colors */
.type-boot { color: #00ff88; }
.type-game_active { color: #ffd700; }
.type-dll_install { color: #ff6b9d; }

/* ====== System Profile ====== */
#detail-system-profile {
  --profile-blue: 79, 195, 247;
  --profile-green: 165, 214, 167;
  --profile-orange: 255, 204, 128;
}

#detail-system-profile .system-profile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

#detail-system-profile .system-profile-header h2 {
  margin: .15rem 0 .35rem;
  font-size: clamp(1.55rem, 2.5vw, 2rem);
  line-height: 1.2;
  text-wrap: balance;
}

#detail-system-profile .system-profile-header p:not(.system-profile-eyebrow) {
  max-width: 680px;
  color: var(--text-secondary);
  text-wrap: pretty;
}

#detail-system-profile .system-profile-eyebrow {
  color: var(--accent-blue);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
}

#detail-system-profile .system-profile-scope {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .35rem;
  flex-shrink: 0;
}

#detail-system-profile .system-profile-scope span {
  padding: .25rem .6rem;
  border: 1px solid rgba(var(--profile-blue), .35);
  border-radius: 999px;
  background: rgba(var(--profile-blue), .08);
  color: var(--accent-blue);
  font-size: .75rem;
  font-weight: 600;
}

#detail-system-profile .system-profile-scope time {
  color: var(--text-secondary);
  font-size: .75rem;
}

#detail-system-profile .system-profile-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}

#detail-system-profile .system-profile-metric {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
}

#detail-system-profile .system-profile-metric-label {
  margin-bottom: .25rem;
  color: var(--text-secondary);
  font-size: .75rem;
}

#detail-system-profile .system-profile-metric-value {
  overflow: hidden;
  color: var(--text-primary);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#detail-system-profile .system-profile-metric-note {
  margin-top: .25rem;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: .72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#detail-system-profile .system-profile-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
}

#detail-system-profile .system-profile-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
}

#detail-system-profile .system-profile-release-card { grid-column: span 7; }
#detail-system-profile .system-profile-side-stack {
  display: grid;
  grid-column: span 5;
  gap: 1rem;
}
#detail-system-profile .system-profile-av-card { grid-column: span 12; }
#detail-system-profile .system-profile-edition-card { grid-column: span 5; }
#detail-system-profile .system-profile-matrix-card { grid-column: span 7; }

#detail-system-profile .system-profile-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1rem .75rem;
  border-bottom: 1px solid rgba(15, 52, 96, .7);
}

#detail-system-profile .system-profile-card-header h3 {
  color: var(--text-primary);
  font-size: .95rem;
  font-weight: 650;
  text-wrap: balance;
}

#detail-system-profile .system-profile-card-header p {
  margin-top: .15rem;
  color: var(--text-secondary);
  font-size: .72rem;
  text-wrap: pretty;
}

#detail-system-profile .system-profile-content { padding: .9rem 1rem 1rem; }

#detail-system-profile .system-profile-empty {
  padding: 1.5rem;
  color: var(--text-secondary);
  text-align: center;
}

#detail-system-profile .system-profile-family + .system-profile-family {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(15, 52, 96, .55);
}

#detail-system-profile .system-profile-family-header,
#detail-system-profile .system-profile-bar-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
}

#detail-system-profile .system-profile-family-header { margin-bottom: .55rem; }
#detail-system-profile .system-profile-family-name { font-weight: 650; }
#detail-system-profile .system-profile-family-total,
#detail-system-profile .system-profile-bar-value {
  color: var(--text-secondary);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#detail-system-profile .system-profile-bar-row + .system-profile-bar-row { margin-top: .58rem; }
#detail-system-profile .system-profile-bar-label {
  min-width: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-size: .8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#detail-system-profile .system-profile-bar-track {
  height: 7px;
  margin-top: .3rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .055);
}

#detail-system-profile .system-profile-bar-fill {
  width: var(--bar-width, 0%);
  height: 100%;
  border-radius: inherit;
  background: rgb(var(--profile-blue));
  transform-origin: left center;
}

#detail-system-profile .system-profile-family:nth-child(2n) .system-profile-bar-fill {
  background: rgb(var(--profile-green));
}

#detail-system-profile .system-profile-family:nth-child(3n) .system-profile-bar-fill {
  background: rgb(var(--profile-orange));
}

#detail-system-profile .system-profile-av-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem 1.5rem;
}

#detail-system-profile .system-profile-table-wrap {
  max-height: 560px;
  overflow: auto;
  overscroll-behavior: contain;
}

#detail-system-profile .system-profile-table {
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

#detail-system-profile .system-profile-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #17172a;
  color: var(--text-secondary);
  font-size: .7rem;
  letter-spacing: .02em;
  text-transform: uppercase;
}

#detail-system-profile .system-profile-table th,
#detail-system-profile .system-profile-table td { padding: .55rem .7rem; }
#detail-system-profile .system-profile-table .numeric { text-align: right; }
#detail-system-profile .system-profile-table .profile-category-cell {
  width: 34%;
  color: var(--text-primary);
  font-weight: 650;
  vertical-align: top;
}

#detail-system-profile .system-profile-table .profile-secondary { color: var(--text-secondary); }
#detail-system-profile .system-profile-table .profile-total-row td {
  background: rgba(var(--profile-blue), .07);
  color: var(--text-primary);
  font-weight: 700;
}

#detail-system-profile .system-profile-matrix th:first-child,
#detail-system-profile .system-profile-matrix td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 150px;
  background: var(--bg-card);
}

#detail-system-profile .system-profile-matrix th:first-child {
  z-index: 4;
  background: #17172a;
}

#detail-system-profile .system-profile-matrix-cell {
  background: rgba(var(--profile-blue), var(--heat, 0));
}

#detail-system-profile .system-profile-matrix-cell.is-zero { color: rgba(136, 136, 136, .45); }

@media (max-width: 1050px) {
  #detail-system-profile .system-profile-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #detail-system-profile .system-profile-release-card,
  #detail-system-profile .system-profile-side-stack,
  #detail-system-profile .system-profile-edition-card,
  #detail-system-profile .system-profile-matrix-card { grid-column: span 12; }
}

@media (max-width: 640px) {
  #detail-system-profile .system-profile-header { flex-direction: column; }
  #detail-system-profile .system-profile-scope { align-items: flex-start; }
  #detail-system-profile .system-profile-summary { grid-template-columns: 1fr 1fr; }
  #detail-system-profile .system-profile-av-list { grid-template-columns: 1fr; }
  #detail-system-profile .system-profile-metric { padding: .8rem; }
  #detail-system-profile .system-profile-metric-value { font-size: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .detail-page,
  .skeleton { animation: none; }
  .overview-card { transition: none; }
}
