:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef5f3;
  --text: #14213d;
  --muted: #64748b;
  --line: #d9e2ec;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --good: #16a34a;
  --warn: #ca8a04;
  --bad: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e141b;
  --surface: #151f29;
  --surface-2: #1d2b35;
  --text: #eef5ff;
  --muted: #a7b5c8;
  --line: #2d3e4d;
  --accent: #2dd4bf;
  --accent-2: #60a5fa;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 900;
  box-shadow: var(--shadow);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.nav-list,
.drawer-nav {
  display: grid;
  gap: 3px;
  margin-top: 20px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
}

.sidebar-card,
.recommend-card,
.section-panel,
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar-card {
  margin-top: 22px;
  padding: 16px;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.search-wrap {
  flex: 1;
  max-width: 680px;
  position: relative;
}

.search-wrap input,
.mobile-drawer input,
.tool-form input,
.tool-form select,
.calculator-grid input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 800;
}

.search-wrap input {
  padding-left: 38px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

main {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 22px;
}

.section-panel {
  padding: 24px;
  margin-bottom: 22px;
}

.hero {
  min-height: 390px;
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
  background: #0f172a;
  color: #fff;
}

.hero-media {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(90deg, rgba(8, 16, 30, 0.9), rgba(8, 16, 30, 0.35), rgba(8, 16, 30, 0.08)), url("assets/network-hero.png");
  background-size: cover;
  background-position: center;
}

.hero-content {
  width: min(570px, 100%);
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0;
  font-weight: 800;
}

.hero .eyebrow {
  color: #7dd3fc;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.25rem, 3.5vw, 3.45rem);
  line-height: 1.04;
  max-width: 570px;
  margin-bottom: 16px;
}

h2 {
  font-size: clamp(1.25rem, 2vw, 1.85rem);
  line-height: 1.15;
  margin-bottom: 0;
}

.hero-copy {
  font-size: 1rem;
  line-height: 1.55;
  color: #dbeafe;
  max-width: 560px;
}

.hero-actions,
.result-toolbar,
.section-heading,
.tool-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 20px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  background: #fff;
  color: #0f172a;
}

.ghost-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.danger-button {
  background: color-mix(in srgb, var(--bad) 14%, var(--surface));
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 25%, var(--line));
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.metric-card {
  padding: 16px;
  min-height: 116px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.25rem, 1.7vw, 1.75rem);
  word-break: break-word;
}

.metric-card small,
.metric-label {
  color: var(--muted);
}

.metric-card small {
  display: block;
  margin-top: 3px;
  line-height: 1.35;
}

#localIpSummary {
  color: var(--accent);
  font-weight: 700;
}

.score-card {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--surface)), var(--surface));
}

.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}

.right-panel {
  position: sticky;
  top: 94px;
  display: grid;
  gap: 16px;
}

.recommend-card {
  padding: 18px;
}

.recommend-card ul {
  padding-left: 20px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.speed-rings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.speed-ring {
  min-height: 156px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: radial-gradient(circle at center, color-mix(in srgb, var(--accent) 18%, transparent), transparent 62%), var(--surface-2);
}

.speed-ring span {
  display: block;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1;
  font-weight: 900;
}

.speed-ring small {
  display: block;
  color: var(--muted);
  margin-top: 10px;
}

.progress-track {
  height: 10px;
  margin: 20px 0;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.test-status {
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.test-status.error {
  color: var(--bad);
  font-weight: 700;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--good));
  transition: width 0.35s ease;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.tool-card {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  color: var(--text);
}

.tool-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tool-card small {
  color: var(--muted);
  line-height: 1.45;
}

.data-grid,
.calculator-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.data-item {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.data-item span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.data-item strong {
  display: block;
  word-break: break-word;
}

#deviceInfoGrid .data-item:first-child {
  border-color: color-mix(in srgb, var(--good) 45%, var(--line));
  background: color-mix(in srgb, var(--good) 10%, var(--surface));
}

#deviceInfoGrid .data-item:first-child strong::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 18%, transparent);
}

.tool-form {
  margin-bottom: 14px;
}

.tool-form input {
  flex: 1 1 260px;
}

.tool-form select {
  width: auto;
  min-width: 140px;
}

.tool-form.stacked {
  align-items: stretch;
}

.result-box {
  min-height: 120px;
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0f172a;
  color: #dbeafe;
  overflow: auto;
  white-space: pre-wrap;
}

.qr-wrap {
  min-height: 240px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: var(--surface-2);
}

.qr-wrap img {
  display: none;
  width: 220px;
  height: 220px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.checklist {
  display: grid;
  gap: 10px;
}

.check-row,
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.check-dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: var(--good);
}

.check-dot.warn {
  background: var(--warn);
}

.icon-button,
.icon-close {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.icon-button {
  display: none;
  place-items: center;
  gap: 4px;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.mobile-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: min(88vw, 360px);
  padding: 20px;
  background: var(--surface);
  transform: translateX(-102%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.drawer-open .drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

.drawer-open .mobile-drawer {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: 70px;
  display: none;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.bottom-nav a {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
}

.bottom-nav a.active {
  color: var(--accent);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 8px;
  color: #fff;
  background: #0f172a;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.single-page .content-layout {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1100px;
  margin: 0 auto;
}

.single-page .main-column > section:not([hidden]) {
  min-height: min(680px, calc(100vh - 130px));
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .icon-button {
    display: grid;
  }

  .content-layout {
    grid-template-columns: 1fr;
  }

  .right-panel {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-grid,
  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: 70px;
  }

  .topbar {
    height: auto;
    padding: 12px;
  }

  .topbar-actions .ghost-button {
    display: none;
  }

  main {
    padding: 12px;
  }

  .hero {
    min-height: 470px;
    align-items: end;
  }

  .hero-media {
    background-image: linear-gradient(180deg, rgba(8, 16, 30, 0.1), rgba(8, 16, 30, 0.9)), url("assets/network-hero.png");
  }

  .section-panel {
    padding: 18px;
  }

  .quick-grid,
  .tool-grid,
  .speed-rings,
  .data-grid,
  .calculator-grid,
  .right-panel {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
  }

  .bottom-nav {
    display: grid;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 84px;
  }
}

@media (min-width: 1800px) {
  .tool-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .quick-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.admin-link {
  display: inline-flex;
  justify-content: center;
  margin: 10px 0;
  text-decoration: none;
}

.admin-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.admin-card {
  width: min(100%, 440px);
  padding: 28px;
}

.admin-card h1,
.admin-dashboard h1 {
  margin: 0 0 18px;
  font-size: clamp(2rem, 5vw, 3.5rem);
}

.admin-dashboard {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: 28px;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-section {
  margin-top: 22px;
  padding: 24px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.table {
  color: var(--text);
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--line);
}

@media (max-width: 760px) {
  .admin-top,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-top {
    align-items: flex-start;
    flex-direction: column;
  }
}
