:root {
  color-scheme: dark;
  --bg: #071311;
  --bg-elevated: rgba(14, 32, 29, 0.92);
  --bg-soft: rgba(20, 46, 41, 0.7);
  --border: rgba(86, 181, 165, 0.18);
  --text: #f1f7f5;
  --muted: #9cc8c0;
  --accent: #1bc7bf;
  --accent-strong: #6ff0df;
  --danger: #f26f6f;
  --warning: #f0be61;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  font-family: "Segoe UI", "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(27, 199, 191, 0.12), transparent 24rem),
    linear-gradient(180deg, #071311 0%, #050b0b 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
}

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

/* === NEW SIDEBAR === */
.sidebar {
  width: 16rem;
  min-height: 100vh;
  position: relative;
  transition: width 0.2s ease;
  border-right: 1px solid var(--border);
  background: rgba(7,19,17,0.97);
  display: flex;
  flex-direction: column;
  padding: 0;
  gap: 0;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.sidebar__brand-main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.sidebar__logo-wrap {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.6rem;
  background: linear-gradient(180deg, var(--accent), #127776);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  box-shadow: 0 6px 18px rgba(0, 168, 167, 0.18);
}

.sidebar__logo-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.sidebar__rail-toggle {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 40px;
  border-radius: 0 8px 8px 0;
  border: 1px solid var(--border);
  border-left: none;
  background: rgba(7, 19, 17, 0.97);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  z-index: 10;
}

.sidebar__rail-toggle:hover {
  color: var(--text);
  background: rgba(20, 46, 41, 0.9);
}

.sidebar--collapsed .sidebar__brand-copy,
.sidebar--collapsed .sidebar__nav-label,
.sidebar--collapsed .sidebar-user__info {
  display: none;
}

.sidebar--collapsed {
  width: 70px;
}

.sidebar--collapsed .sidebar__rail-toggle svg {
  transform: scaleX(-1);
}

.sidebar--collapsed .sidebar__nav-item {
  justify-content: center;
  padding: 0.75rem 0.5rem;
}

.sidebar--collapsed .sidebar__status-section {
  display: none;
}

.sidebar--collapsed .sidebar-user__row {
  justify-content: center;
}

.sidebar__name {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.sidebar__tagline {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 0.65rem;
  flex: 1;
}

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.8rem;
  border-radius: 0.7rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.sidebar__nav-item:hover {
  background: rgba(27,199,191,0.07);
  color: var(--text);
}

.sidebar__nav-item.is-active {
  background: rgba(27,199,191,0.14);
  border-color: rgba(111,240,223,0.28);
  color: var(--accent-strong);
}

.sidebar__nav-icon {
  flex-shrink: 0;
  opacity: 0.8;
  display: flex;
  align-items: center;
}

.sidebar__nav-item.is-active .sidebar__nav-icon {
  opacity: 1;
}

.sidebar__nav-label {
  font-weight: 500;
}

.sidebar__bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.sidebar__status-section {
  padding: 0.65rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar__status-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.sidebar__status-value {
  font-size: 0.78rem;
  word-break: break-all;
  margin-top: 0.15rem;
  color: var(--text);
}

/* Sidebar footer / user area */
.sidebar__footer {
  padding: 0.75rem 0.9rem;
}

.sidebar-user__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-user__avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(180deg, #7c5cff, #5c31ff);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  user-select: none;
}

.sidebar-user__info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-user__name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar-user__email {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar-user__logout {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.sidebar-user__logout:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

/* Shared label styles */
.brand__sub,
.sidebar__label,
.eyebrow,
.subtle {
  color: var(--muted);
}

.eyebrow {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

/* Buttons */
.ghost-button,
.primary-button,
.danger-button {
  border: 1px solid var(--border);
  border-radius: 0.95rem;
  font: inherit;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.ghost-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
  border-color: rgba(111, 240, 223, 0.42);
}

.ghost-button,
.primary-button,
.danger-button {
  padding: 0.8rem 1rem;
  background: transparent;
  color: var(--text);
}

.primary-button {
  background: linear-gradient(135deg, #14c4bc, #69e8d9);
  color: #022826;
  border-color: transparent;
  font-weight: 700;
}

.danger-button {
  background: rgba(242, 111, 111, 0.12);
  color: #ffc4c4;
  border-color: rgba(242, 111, 111, 0.28);
}

/* Status / Panel cards */
.status-card,
.panel,
.kpi-card,
.login-card,
.audit-row {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  box-shadow: var(--shadow);
}

.status-card {
  padding: 0.95rem 1rem;
}

.status-card__label {
  color: var(--muted);
  font-size: 0.84rem;
}

.status-card__value {
  margin-top: 0.35rem;
  font-size: 0.92rem;
  word-break: break-word;
}

/* Content area */
.content {
  padding: 1rem 1.5rem 2rem;
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-bottom: 0;
}

.topbar h1 {
  margin: 0.1rem 0 0;
  font-size: 1.5rem;
}

.topbar__actions {
  display: flex;
  gap: 0.75rem;
}

/* Alerts */
.alert {
  padding: 0.95rem 1rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: rgba(15, 34, 30, 0.85);
}

.alert--error {
  border-color: rgba(242, 111, 111, 0.4);
  color: #ffd4d4;
}

.alert--warning {
  border-color: rgba(240, 190, 97, 0.4);
  color: #ffe2ab;
}

/* Grids */
.grid {
  display: grid;
  gap: 1rem;
}

.grid--kpi {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

/* Panel */
.panel {
  padding: 1.15rem 1.2rem;
}

.panel h2,
.panel h3,
.login-card h2 {
  margin-top: 0;
}

/* KPI cards */
.kpi-card {
  padding: 1rem;
}

.kpi-card__value {
  margin-top: 0.55rem;
  font-size: 1.8rem;
  font-weight: 700;
}

/* Lists */
.list {
  display: grid;
  gap: 0.75rem;
}

.list-item {
  padding: 0.85rem 0.95rem;
  border-radius: 0.95rem;
  background: rgba(12, 28, 26, 0.82);
  border: 1px solid var(--border);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(27, 199, 191, 0.12);
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Auth / Login screen */
.login-shell {
  min-height: calc(100vh - 8rem);
  display: grid;
  place-items: center;
}

.auth-screen {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(22rem, 30rem);
  gap: 1.5rem;
  align-items: stretch;
}

.auth-screen__hero {
  padding: clamp(1.5rem, 3vw, 2.4rem);
  border-radius: 1.35rem;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at top right, rgba(27, 199, 191, 0.18), transparent 18rem),
    linear-gradient(180deg, rgba(11, 27, 24, 0.96), rgba(8, 20, 18, 0.96));
  box-shadow: var(--shadow);
}

.auth-screen__hero h2 {
  margin: 0.35rem 0 0.9rem;
  font-size: clamp(2rem, 4vw, 3rem);
}

.auth-screen__copy {
  max-width: 40rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.auth-screen__facts {
  margin-top: 1.5rem;
  display: grid;
  gap: 0.85rem;
}

.auth-screen__fact {
  display: grid;
  gap: 0.35rem;
  padding: 1rem 1.05rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: rgba(10, 24, 22, 0.72);
}

.auth-screen__fact span {
  color: var(--muted);
}

.auth-screen__domains {
  margin: 1rem 0;
}

.login-card {
  width: min(34rem, 100%);
  padding: 1.5rem;
}

body.is-auth-screen .shell {
  grid-template-columns: 1fr;
}

body.is-auth-screen .sidebar,
body.is-auth-screen .topbar,
body.is-auth-screen #alerts {
  display: none;
}

body.is-auth-screen .content {
  min-height: 100vh;
  padding: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}

body.is-auth-screen #app {
  width: 100%;
}

/* Form fields */
.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.85rem 0.95rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: rgba(9, 21, 19, 0.95);
  color: var(--text);
  font: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(111, 240, 223, 0.52);
}

/* Audit */
.audit-toolbar {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}

.audit-filter {
  min-width: 12rem;
  margin: 0;
}

.audit-filter--wide {
  min-width: 18rem;
  flex: 1 1 18rem;
}

.audit-toolbar__actions {
  display: flex;
  gap: 0.5rem;
  align-items: end;
  flex-wrap: wrap;
}

.audit-row {
  padding: 1rem;
  display: grid;
  gap: 0.65rem;
}

.audit-row--failure {
  border-color: rgba(231, 76, 60, 0.42);
}

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

.audit-row__title {
  font-weight: 700;
}

.audit-row__summary {
  color: var(--muted);
}

.audit-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.audit-error {
  padding: 0.65rem 0.8rem;
  border: 1px solid rgba(231, 76, 60, 0.28);
  border-radius: 0.5rem;
  color: #ffb4a8;
  background: rgba(231, 76, 60, 0.08);
  font-size: 0.86rem;
}

.code-block {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow: auto;
  border-radius: 0.95rem;
  background: rgba(6, 15, 14, 0.92);
  border: 1px solid rgba(111, 240, 223, 0.14);
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 0.84rem;
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.82rem;
}

.pagination-bar__info {
  color: var(--muted);
  flex: 1;
}

.pagination-bar__controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pagination-bar__controls span {
  color: var(--muted);
  white-space: nowrap;
  min-width: 6rem;
  text-align: center;
}

.pagination-bar__controls button {
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.pagination-bar__size {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
}

.pagination-bar__size select {
  padding: 0.25rem 0.4rem;
  background: rgba(9,21,19,0.95);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
}

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

  .sidebar {
    width: 100%;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .auth-screen {
    grid-template-columns: 1fr;
  }

  .auth-screen__hero {
    order: 2;
  }

  .login-card {
    width: 100%;
  }
}
