/* ============================================================
   Mikoshi Dashboard — single-page custom replacement for Homarr
   Design language: btop-aesthetic, dark, green accent, Inter,
   tabular-nums everywhere, responsive grid.
============================================================ */

/* --- Design tokens ------------------------------------------ */
:root {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface-2: #2d2d2d;
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.12);
  --text: rgba(255,255,255,0.92);
  --text-dim: rgba(255,255,255,0.55);
  --text-faint: rgba(255,255,255,0.35);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.15);
  --blue: #60a5fa;
  --pink: #f472b6;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* --- Page chrome -------------------------------------------- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

header.brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
  padding: 0 4px;
}
header.brand h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text);
}
header.brand h1 span {
  color: var(--green);
}
header.brand .subtitle {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

/* --- Grid layout (desktop default) -------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  grid-auto-flow: dense;
}

/* Section sizing — desktop 12-col grid, btop-flow layout
   Row 0: Media Library | Speedtest
   Row 1-2: Compute graph (tall) | CPU (top), GPU (bottom)
   Row 3-4: Memory | Storage | Activity (tall)  /  Network | Activity continues */
.tile-media-library { grid-column: 1 / span 8;  grid-row: 1; }
.tile-speedtest     { grid-column: 9 / span 4;  grid-row: 1; }

.tile-services      { grid-column: 1 / span 12; grid-row: 2; }
.tile-section-raijin{ grid-column: 1 / span 12; grid-row: 3; }

.tile-compute       { grid-column: 1 / span 8;  grid-row: 4 / span 2; }
.tile-cpu           { grid-column: 9 / span 4;  grid-row: 4; }
.tile-gpu           { grid-column: 9 / span 4;  grid-row: 5; }

.tile-memory        { grid-column: 1 / span 4;  grid-row: 6; }
.tile-storage       { grid-column: 5 / span 4;  grid-row: 6; }
.tile-activity      { grid-column: 9 / span 4;  grid-row: 6 / span 2; }
.tile-network       { grid-column: 1 / span 8;  grid-row: 7; }

.tile-spacer-top    { display: none; }

/* --- Tile chrome -------------------------------------------- */
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.tile-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  flex-shrink: 0;
}
.tile-header .subtitle {
  font-weight: 400;
  color: var(--text-faint);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: none;
}

/* Big primary numbers (CPU 12.3%, GPU 0%, etc.) */
.primary-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}
.primary-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 2px;
}
.primary-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Detail grid (e.g., "User 5%, System 2%, Idle 90%, I/O wait 0%") */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  font-size: 12px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
.detail-label { color: var(--text-faint); font-size: 11px; }
.detail-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Mini progress bar (used in CPU big-number row, storage rows) */
.bar {
  width: 60px;
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.5s ease;
}
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

/* --- Storage tile ------------------------------------------- */
.storage-row { display: flex; flex-direction: column; gap: 2px; }
.storage-row + .storage-row { margin-top: 8px; }
.storage-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.storage-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.storage-name .role {
  font-weight: 400;
  color: var(--text-faint);
  margin-left: 4px;
  font-size: 10px;
}
.storage-pct {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.storage-pct .unit {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 2px;
}
.storage-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
  margin: 4px 0 2px;
}
.storage-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.5s ease;
}
.storage-row-bottom {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
}
.storage-row-bottom .free { color: var(--text-dim); }
.storage-row-bottom .total { color: var(--text-faint); }

/* --- Memory tile sparkline --------------------------------- */
.spark-wrap {
  position: relative;
  width: 100%;
  height: 28px;
  margin-top: auto;
}
.spark-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.spark-meta {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* --- Graph tiles (network, compute) ------------------------ */
.graph-wrap {
  position: relative;
  flex: 1;
  min-height: 120px;
  width: 100%;
}
.graph-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.axis-label {
  position: absolute;
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  pointer-events: none;
  background: rgba(36,36,36,0.6);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
}
.axis-label.left-top { top: 4px; left: 6px; }
.axis-label.left-bottom { bottom: 4px; left: 6px; }
.axis-label.right-top { top: 4px; right: 6px; }
.axis-label.right-bottom { bottom: 4px; right: 6px; }

.readouts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.readout-label {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--text-faint);
}
.readout-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.readout-unit {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: -2px;
}

/* --- Activity tile ----------------------------------------- */
.activity-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.activity-section + .activity-section { margin-top: 12px; }
.section-heading {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.counts-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.count-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.count-icon {
  font-size: 11px;
  color: var(--text-dim);
}
.count-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.count-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.downloads-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.download-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.download-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}
.download-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.download-tags { display: flex; gap: 4px; flex-shrink: 0; }
.download-tag {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--green-dim);
  color: var(--green);
  flex-shrink: 0;
}
.download-tag.tag-tv { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.download-tag.tag-music { background: rgba(244, 114, 182, 0.15); color: var(--pink); }
.download-tag.tag-quality { background: rgba(255,255,255,0.06); color: var(--text); opacity: 0.85; }
.download-tag.tag-quality-4k { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.download-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-dim);
}
.download-progress {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
.download-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.5s ease;
}
.empty-state {
  padding: 12px 0;
  color: var(--text-faint);
  font-size: 11px;
  font-style: italic;
  text-align: center;
}

/* --- Speedtest tile (iframe wrapper) ------------------------
   The embed.html provides its own tile chrome, so the section
   here is just a sized container — no padding, no border, no
   background of its own.
------------------------------------------------------------- */
.tile-speedtest {
  display: block;
  min-height: 0;
  overflow: hidden;
  border-radius: 10px;
}
.tile-speedtest iframe {
  width: 100%;
  height: 100%;
  min-height: 280px;
  display: block;
  border: 0;
  background: var(--surface);
  border-radius: 10px;
}

/* --- Media library — two big stream blocks, request as subordinate ----- */
.apps-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
}
.app-block {
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.app-block:has(.app-primary:hover) {
  border-color: rgba(74, 222, 128, 0.35);
}
.app-primary {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 18px 14px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
  flex: 1;
}
.app-primary:hover {
  background: rgba(74, 222, 128, 0.08);
}
.app-primary:hover .app-primary-name { color: var(--green); }
.app-primary:hover .app-primary-icon { color: var(--green); }
.app-primary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.app-primary-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--text-dim);
  transition: color 0.15s;
}
.app-primary-icon svg {
  width: 100%; height: 100%;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.app-primary-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.app-primary-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  transition: color 0.15s;
  line-height: 1.1;
}
.app-primary-action {
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 4px;
}
.app-primary-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.media-pill {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 3px;
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.6);
}

.app-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.app-secondary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 18px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.app-secondary:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.app-secondary-arrow {
  color: var(--text-faint);
  transition: transform 0.15s;
}
.app-secondary:hover .app-secondary-arrow {
  transform: translateX(2px);
  color: var(--text);
}
/* --- Footer ------------------------------------------------- */
footer.brand-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
footer.brand-footer a {
  color: var(--text-dim);
  text-decoration: none;
}
footer.brand-footer a:hover { color: var(--text); }


/* --- Service health strip ---------------------------------- */
.tile-services {
  padding: 10px 14px;
}
.services-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.services-strip::-webkit-scrollbar { display: none; }
.service-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.service-chip:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.service-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.service-chip.up .service-dot {
  background: var(--green);
  box-shadow: 0 0 5px rgba(74, 222, 128, 0.4);
}
.service-chip.down {
  border-color: rgba(248, 113, 113, 0.3);
}
.service-chip.down .service-dot {
  background: var(--danger);
}
.service-chip.unknown .service-dot {
  background: var(--warn);
}
.service-chip.uptime-chip {
  margin-left: auto;
  cursor: default;
  color: var(--text-faint);
  background: transparent;
  border-color: transparent;
}
.service-chip.uptime-chip:hover {
  background: transparent;
  color: var(--text-faint);
}
.uptime-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.uptime-value {
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}


/* --- Section dividers (label + hairline) -------------------- */
.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 2px;
}
.section-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-faint);
}
.section-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.section-aside {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.section-aside .aside-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-right: 6px;
}

/* ============================================================
   RESPONSIVE — collapse layout on smaller screens
============================================================ */

/* Tablet */
@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(6, 1fr); }
  .tile-media-library { grid-column: span 6; grid-row: auto; }
  .tile-speedtest     { grid-column: span 6; grid-row: auto; }
  .tile-spacer-top    { display: none; }
  .tile-compute       { grid-column: span 6; }
  .tile-cpu           { grid-column: span 3; }
  .tile-gpu           { grid-column: span 3; }
  .tile-memory        { grid-column: span 3; }
  .tile-storage       { grid-column: span 3; }
  .tile-network       { grid-column: span 6; }
  .tile-activity      { grid-column: span 6; }
  .tile-services      { grid-column: span 6; }
  .tile-section-raijin{ grid-column: span 6; }
}

/* Mobile */
@media (max-width: 700px) {
  .page { padding: 16px 12px 32px; }
  header.brand h1 { font-size: 18px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .tile-media-library, .tile-speedtest, .tile-services, .tile-section-raijin, .tile-compute, .tile-cpu, .tile-gpu,
  .tile-memory, .tile-storage, .tile-network, .tile-activity {
    grid-column: span 1;
    grid-row: auto;
  }
  .matrix { grid-template-columns: 70px 1fr 1fr; }
  .matrix-headers { grid-template-columns: 70px 1fr 1fr; }
  .primary-value { font-size: 26px; }
}
