:root {
  --bg: #f3f5ef;
  --surface: #ffffff;
  --surface-2: #eef3e4;
  --ink: #14251a;
  --muted: #5c6a60;
  --line: rgba(20, 37, 26, 0.1);
  --brand: #7fb33b;
  --brand-deep: #3d5b18;
  --brand-soft: #dce8c6;
  --accent: #f6c845;
  --danger: #a63f2d;
  --shadow: 0 18px 44px rgba(32, 52, 24, 0.08);
  --chart-text: #5c6a60;
  --chart-grid: rgba(20, 37, 26, 0.1);
  --chart-line: #3d5b18;
  --chart-area: rgba(127, 179, 59, 0.16);
  --tooltip-bg: rgba(255, 255, 255, 0.96);
  --tooltip-border: rgba(20, 37, 26, 0.14);
}

:root[data-theme="dark"] {
  --bg: #0f1512;
  --surface: #16201b;
  --surface-2: #243128;
  --ink: #f3f8f3;
  --muted: #c3d0c6;
  --line: rgba(232, 241, 233, 0.16);
  --brand: #9bd35a;
  --brand-deep: #5f8f22;
  --brand-soft: rgba(155, 211, 90, 0.24);
  --accent: #f59e0b;
  --danger: #f0625d;
  --shadow: 0 24px 52px rgba(0, 0, 0, 0.36);
  --chart-text: #d7e2d8;
  --chart-grid: rgba(232, 241, 233, 0.12);
  --chart-line: #9bd35a;
  --chart-area: rgba(155, 211, 90, 0.18);
  --tooltip-bg: rgba(18, 26, 22, 0.97);
  --tooltip-border: rgba(232, 241, 233, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(127, 179, 59, 0.16), transparent 26%),
    linear-gradient(180deg, #fbfcf8 0%, var(--bg) 100%);
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at top right, rgba(139, 195, 74, 0.12), transparent 26%),
    radial-gradient(circle at 20% 15%, rgba(245, 158, 11, 0.08), transparent 24%),
    linear-gradient(180deg, #111713 0%, var(--bg) 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app-sidebar {
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

:root[data-theme="dark"] .app-sidebar {
  background: rgba(24, 33, 29, 0.9);
}

.brand-lockup {
  display: block;
  margin-bottom: 2rem;
}

.brand-logo-shell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 1rem;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--brand-deep) 0%, #1f3520 100%);
  box-shadow: var(--shadow);
}

.brand-logo {
  display: block;
  width: 112px;
  height: auto;
}

.brand-tag,
.eyebrow,
.metric-label,
.chooser-kicker,
.chart-pill,
.status-badge {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
}

.environment-switcher,
.sidebar-nav {
  display: grid;
  gap: 0.75rem;
}

.environment-switcher {
  margin-bottom: 1.5rem;
}

.environment-switcher select,
.auth-form input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  caret-color: var(--ink);
  font: inherit;
}

.environment-switcher select::placeholder,
.auth-form input::placeholder {
  color: var(--muted);
}

.auth-form input:-webkit-autofill,
.auth-form input:-webkit-autofill:hover,
.auth-form input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--surface) inset;
  transition: background-color 9999s ease-out 0s;
}

.sidebar-nav a {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  color: var(--ink);
  background: transparent;
}

.sidebar-nav a:hover {
  background: var(--surface-2);
}

.app-main {
  padding: 2rem;
}

.app-header,
.overview-intro,
.hero-panel,
.auth-panel {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
}

.app-header {
  align-items: start;
  margin-bottom: 2rem;
}

.overview-intro {
  margin-bottom: 1.75rem;
}

.app-header h1,
.hero-copy h2,
.auth-copy h2 {
  margin: 0.2rem 0 0;
  font-family: "Sora", sans-serif;
  font-size: clamp(1.15rem, 2vw, 1.8rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.nav-toggle {
  display: none !important;
}

.mobile-nav-backdrop {
  display: none;
}

.overview-actions {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.9rem 1.25rem;
  border-radius: 16px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: white;
  box-shadow: var(--shadow);
}

.ghost-button {
  background: white;
  border-color: var(--line);
  color: var(--ink);
}

:root[data-theme="dark"] .ghost-button {
  background: rgba(27, 37, 31, 0.96);
}

.hero-panel,
.auth-panel,
.chooser-card,
.widget-card,
.group-card,
.metric-card {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .hero-panel,
:root[data-theme="dark"] .auth-panel,
:root[data-theme="dark"] .chooser-card,
:root[data-theme="dark"] .widget-card,
:root[data-theme="dark"] .group-card,
:root[data-theme="dark"] .metric-card,
:root[data-theme="dark"] .table-panel,
:root[data-theme="dark"] .history-card {
  background: rgba(24, 33, 29, 0.92);
}

:root[data-theme="dark"] .device-table th,
:root[data-theme="dark"] .device-table td,
:root[data-theme="dark"] .attribute-row {
  border-color: var(--line);
}

:root[data-theme="dark"] .chart-pill,
:root[data-theme="dark"] .status-badge,
:root[data-theme="dark"] .status-chip,
:root[data-theme="dark"] .comparison-pill {
  color: #eff7e8;
}

.hero-panel,
.auth-panel {
  padding: 2rem;
}

.hero-card-grid,
.group-grid,
.chooser-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.widget-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.table-panel {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.search-form {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.search-form input {
  flex: 1;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
}

.table-scroll {
  overflow-x: auto;
}

.device-table {
  width: 100%;
  border-collapse: collapse;
}

.device-table th,
.device-table td {
  padding: 0.9rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.device-table th {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.table-sort-note {
  margin: -0.25rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.table-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: inherit;
  text-decoration: none;
}

.table-sort-link:hover,
.table-sort-link:focus-visible,
.table-sort-link.is-active {
  color: var(--ink);
}

.sort-arrow {
  font-size: 0.9em;
  color: var(--brand);
}

.device-link {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--brand) 48%, transparent);
  text-underline-offset: 0.16em;
  transition: color 160ms ease, text-decoration-color 160ms ease;
}

.device-link:hover,
.device-link:focus-visible {
  color: var(--brand);
  text-decoration-color: var(--brand);
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.attribute-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.attribute-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.attribute-row dt {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.attribute-row dd {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.attribute-timestamp,
.detail-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.comparison-pill {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  margin-right: 0.35rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.comparison-sep {
  color: var(--muted);
  margin: 0 0.35rem;
}

.history-grid {
  display: grid;
  gap: 1rem;
}

.history-section {
  grid-column: 1 / -1;
}

.history-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(127, 179, 59, 0.08) 0%, rgba(255, 255, 255, 0.98) 100%);
}

:root[data-theme="dark"] .history-card {
  background: linear-gradient(180deg, rgba(139, 195, 74, 0.08) 0%, rgba(24, 33, 29, 0.98) 100%);
}

.history-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.history-header h4 {
  margin: 0;
}

.history-header p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.history-chart {
  width: 100%;
  height: 240px;
}

@media (max-width: 960px) {
  .search-form,
  .pager {
    flex-direction: column;
  }
}

.hero-card-grid {
  min-width: min(36vw, 420px);
}

.metric-card,
.chooser-card,
.widget-card,
.group-card {
  padding: 1.25rem;
}

.widget-card {
  display: flex;
  flex-direction: column;
}

.accent-card {
  background: linear-gradient(180deg, rgba(127, 179, 59, 0.12) 0%, white 100%);
}

.metric-value {
  display: block;
  margin-top: 0.45rem;
  font-size: 1.2rem;
}

.chooser-meta,
.widget-meta {
  padding-left: 1.1rem;
  color: var(--muted);
}

.widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.widget-chart {
  width: 100%;
  height: 220px;
  margin: 0.9rem 0 1rem;
}

.widget-chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--line);
  border-radius: 22px;
  color: var(--muted);
  font-weight: 600;
}

.chart-pill,
.status-badge,
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.6rem;
  border-radius: 18px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  text-align: center;
}

.status-row,
.status-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.widget-meta dt {
  font-weight: 700;
  color: var(--ink);
}

.widget-meta dd {
  margin: 0.25rem 0 0.75rem;
  color: var(--muted);
}

.auth-panel {
  align-items: stretch;
}

.auth-form {
  flex: 1;
  display: grid;
  gap: 0.75rem;
  max-width: 28rem;
}

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

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(78vw, 280px);
    height: 100vh;
    border-right: 1px solid var(--line);
    border-bottom: none;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    overflow-y: auto;
  }

  .app-header,
  .hero-panel,
  .auth-panel,
  .overview-intro {
    flex-direction: column;
  }

  .widget-grid {
    grid-template-columns: 1fr;
  }

  .group-grid {
    grid-template-columns: 1fr;
  }

  .nav-toggle {
    display: inline-flex !important;
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 12, 0.42);
    z-index: 15;
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .mobile-nav-backdrop {
    display: block;
  }
}
