:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #111827;
  --surface-2: #1f2937;
  --line: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
  color: var(--text);
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.login-card,
.loading-card,
.overview-card,
.toolbar-card,
.editor-card,
.service-card,
.metric-card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card {
  width: min(480px, 100%);
  padding: 32px;
}

.login-form,
.toolbar-grid,
.editor-form {
  display: grid;
  gap: 16px;
}

.login-form label,
.editor-form label {
  display: grid;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  padding: 12px 14px;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #082f49;
  font-weight: 700;
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.danger-button {
  background: var(--danger);
  color: white;
}

.auth-error-body {
  min-height: 100vh;
  background: #0f172a;
}

.auth-error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(24px, 6vw, 72px);
}

.auth-error-card {
  width: min(560px, 100%);
  position: relative;
  display: grid;
  gap: 18px;
  padding: clamp(32px, 5vw, 56px);
  overflow: hidden;
  border: 1px solid rgba(254, 205, 211, 0.2);
  border-radius: 28px;
  background: rgba(17, 24, 39, 0.96);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.42);
}

.auth-error-card > * {
  position: relative;
}

.auth-error-card h1 {
  margin: 0;
  max-width: 12ch;
  font-size: clamp(34px, 7vw, 58px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

.auth-error-card p {
  margin: 0;
  max-width: 42ch;
  color: #cbd5e1;
  font-size: 16px;
  line-height: 1.65;
}

.auth-error-action {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 13px 18px;
  border: 1px solid rgba(254, 205, 211, 0.3);
  border-radius: 14px;
  background: #fecdd3;
  color: #4c0519;
  font-weight: 800;
  text-decoration: none;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.auth-error-action:hover {
  transform: translateY(-1px);
  background: #ffe4e6;
  box-shadow: 0 18px 40px rgba(251, 113, 133, 0.2);
}

.dashboard-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid rgba(148, 163, 184, 0.15);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(16px);
}

.brand-label,
.eyebrow {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--accent);
}

.sidebar-nav {
  display: grid;
  gap: 10px;
}

.sidebar-link {
  display: block;
  padding: 14px 16px;
  border-radius: 14px;
  text-decoration: none;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid transparent;
}

.sidebar-link.active {
  border-color: rgba(56, 189, 248, 0.6);
  background: rgba(14, 165, 233, 0.12);
}

.sidebar-link small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.content {
  padding: 18px 24px 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.8);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--muted);
}

.user-badge .ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-color: rgba(56, 189, 248, 0.32);
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(14, 165, 233, 0.1);
  color: #bae6fd;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.user-badge .ghost-button:hover {
  border-color: rgba(56, 189, 248, 0.56);
  background: rgba(14, 165, 233, 0.18);
  color: #e0f2fe;
}

.section-toolbar,
.section-content {
  display: grid;
  align-content: start;
  gap: 16px;
}

.section-toolbar:empty {
  display: none;
}

.toolbar-card,
.editor-card {
  padding: 18px;
}

.section-content.loading-card {
  padding: 14px;
}

.toolbar-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.services-grid,
.metrics-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.services-grid {
  width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 250px));
  justify-content: start;
  gap: 14px;
}

.overview-panel {
  display: grid;
  align-self: start;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 0;
}

.overview-panel-copy {
  display: grid;
  max-width: 680px;
  gap: 8px;
}

.overview-panel-copy h2 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 42px);
  line-height: 0.96;
  letter-spacing: -0.07em;
}

.overview-panel-copy p {
  margin: 0;
  color: var(--muted);
}

.overview-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
}

.overview-stats div {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 16px;
  padding: 10px;
  background: rgba(2, 6, 23, 0.32);
}

.overview-stats strong {
  font-size: 24px;
  line-height: 1;
  letter-spacing: -0.05em;
}

.overview-stats span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.service-card,
.metric-card {
  padding: 18px;
}

.service-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 164px;
  gap: 16px;
  align-content: space-between;
  overflow: hidden;
  text-decoration: none;
  background: rgba(17, 24, 39, 0.82);
  box-shadow: none;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.service-card:hover {
  transform: translateY(-2px);
  border-color: rgba(226, 232, 240, 0.32);
  background: rgba(17, 24, 39, 0.96);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.22);
}

.service-card-meta,
.service-card-body,
.service-card-action {
  position: relative;
}

.service-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.service-card-meta .service-status {
  flex: 0 0 auto;
}

.service-card-badge {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-card-body {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.service-card-body h3 {
  margin: 0;
  font-size: 21px;
  line-height: 1.05;
  letter-spacing: -0.055em;
  overflow-wrap: anywhere;
}

.service-card-body p {
  margin: 0;
  overflow-wrap: anywhere;
}

.service-card-action {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(2, 6, 23, 0.42);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease;
}

.service-card-action span {
  flex: 0 0 auto;
}

.service-card-action:hover,
.service-card-action:focus-visible {
  border-color: rgba(226, 232, 240, 0.34);
  background: rgba(226, 232, 240, 0.08);
  color: #f8fafc;
  outline: none;
}

.service-card-unavailable {
  border-color: rgba(251, 113, 133, 0.22);
}

.service-card p,
.metric-card p,
.muted {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.iframe-card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 18px;
}

.iframe-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.iframe-stage {
  position: relative;
}

.iframe-loader {
  position: absolute;
  inset: 1px;
  z-index: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  color: var(--muted);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.iframe-loaded .iframe-loader {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loader-ring {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(148, 163, 184, 0.24);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: loader-spin 800ms linear infinite;
}

@keyframes loader-spin {
  to {
    transform: rotate(360deg);
  }
}

.service-frame {
  width: 100%;
  min-height: 720px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 16px;
  background: #fff;
}

.summary-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  background: rgba(15, 23, 42, 0.72);
}

th,
td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(134, 239, 172, 0.18);
  border-radius: 10px;
  padding: 6px 9px;
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.status-pill.archived {
  border-color: rgba(203, 213, 225, 0.16);
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

.status-pill.conflict,
.status-pill.unavailable {
  border-color: rgba(254, 205, 211, 0.16);
  background: rgba(251, 113, 133, 0.18);
  color: #fecdd3;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.stack {
  display: grid;
  gap: 8px;
}

@media (max-width: 900px) {
  .dashboard-page {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  }

  .content {
    padding: 20px;
  }

  .overview-panel {
    grid-template-columns: 1fr;
  }

  .overview-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .overview-stats {
    grid-template-columns: 1fr;
  }

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