:root {
  color-scheme: dark;
  --bg: #101820;
  --panel: #162229;
  --panel-2: #1d2a31;
  --line: #33444c;
  --text: #eef5f3;
  --muted: #9fb1ba;
  --soft: #c7d2d6;
  --gold: #edae49;
  --green: #2a9d8f;
  --blue: #4ea8de;
  --red: #d1495b;
  --orange: #f4a261;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}
button, input { font: inherit; }
a { color: inherit; }
body.crm-open .landing { display: none; }
body.crm-open .crm-shell { display: grid; }
body.home-open .crm-shell,
body.logged-out .crm-shell { display: none; }

.public-header {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(18px, 4vw, 48px);
  background: rgba(16, 24, 32, 0.78);
  backdrop-filter: blur(18px);
}
.brand-mark {
  font-size: 19px;
  font-weight: 900;
  text-decoration: none;
}
.public-nav {
  display: flex;
  gap: 16px;
  color: var(--soft);
  font-weight: 800;
}
.public-nav a {
  text-decoration: none;
}
.landing {
  min-height: 100vh;
}
.landing-grid {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 24px;
  padding: 84px clamp(14px, 3vw, 44px) 24px;
}
.tile-region {
  min-height: calc(100vh - 108px);
  display: flex;
}
.tile-wall {
  width: 100%;
  display: grid;
  grid-template-rows: minmax(180px, 1.4fr) repeat(4, minmax(110px, 1fr));
  gap: 8px;
}
.tile-row {
  display: grid;
  gap: 8px;
}
.tile-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.flip-tile {
  display: block;
  position: relative;
  overflow: hidden;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: #111a20;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 220ms ease, border-color 220ms ease;
}
.flip-tile:hover { transform: translateY(-2px); }
.flip-tile.flipping { transform: perspective(900px) rotateY(88deg); }
.flip-tile.accent-gold { border-color: var(--gold); }
.flip-tile.accent-green { border-color: var(--green); }
.flip-tile.accent-blue { border-color: var(--blue); }
.flip-tile.accent-red { border-color: var(--red); }
.tile-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.68;
}
.tile-scrim {
  position: absolute;
  inset: 0;
  background: rgba(5, 11, 16, 0.74);
}
.tile-body {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.tile-accent {
  width: 38px;
  height: 5px;
  border-radius: 3px;
  margin-bottom: 8px;
}
.accent-gold .tile-accent { background: var(--gold); }
.accent-green .tile-accent { background: var(--green); }
.accent-blue .tile-accent { background: var(--blue); }
.accent-red .tile-accent { background: var(--red); }
.tile-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
.tile-title {
  color: #fff;
  font-size: 18px;
  line-height: 1.18;
  font-weight: 900;
  margin-top: 5px;
}
.tile-hero .tile-title {
  max-width: 760px;
  font-size: clamp(32px, 6vw, 76px);
  line-height: 0.96;
}
.tile-bottom { margin-top: auto; }
.tile-value {
  display: block;
  color: #fff;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
}
.tile-hero .tile-value { font-size: 38px; }
.tile-detail {
  display: block;
  max-width: 360px;
  color: #b8c7cc;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
  margin-top: 5px;
}
.login-panel {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
  border-left: 1px solid var(--line);
}
.status-kicker {
  margin: 0 0 10px;
  color: #78d6b6;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}
.login-panel h1,
.workspace-header h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(38px, 5vw, 64px);
  line-height: 0.98;
}
.login-copy {
  max-width: 38ch;
  color: var(--soft);
  line-height: 1.5;
  font-weight: 700;
}
.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--text);
  background: #111a20;
}
input:focus {
  outline: 2px solid rgba(42, 157, 143, 0.46);
  outline-offset: 2px;
}
.auth-actions,
.workspace-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.primary-button,
.primary-link-button,
.secondary-button,
.ghost-button,
.side-nav button,
.side-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 8px 12px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}
.primary-button,
.primary-link-button {
  border-color: var(--green);
  background: var(--green);
  color: #07120f;
}
.secondary-button {
  background: var(--panel-2);
  color: var(--text);
}
.ghost-button {
  background: transparent;
  color: var(--soft);
}
.form-message,
.sync-state {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.form-message.error,
.sync-state.error { color: #ff9ca8; }

.crm-shell {
  min-height: 100vh;
  grid-template-columns: 238px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #111a20;
}
.operator-name {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.side-nav {
  display: grid;
  gap: 8px;
}
.side-nav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: var(--soft);
}
.side-nav-link {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: var(--soft);
}
.side-nav button.active {
  border-color: var(--green);
  background: rgba(42, 157, 143, 0.14);
  color: #fff;
}
.signed-in-panel {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.signed-in-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.signed-in-panel strong {
  color: #fff;
  font-size: 22px;
  line-height: 1.1;
}
.sidebar-status {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.sidebar-status span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
.sidebar-status strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}
.workspace {
  min-width: 0;
  padding: 24px clamp(16px, 3vw, 34px) 42px;
}
.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.workspace-header h1 {
  font-size: clamp(34px, 4vw, 52px);
}
.workspace-tools {
  justify-content: flex-end;
}
.workspace-tools input {
  width: min(360px, 44vw);
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}
.metric span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1;
}
.crm-view {
  display: grid;
  gap: 12px;
}
.view-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.75fr);
  gap: 12px;
}
.data-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-heading h2 {
  margin: 0;
  font-size: 18px;
}
.panel-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(51, 68, 76, 0.78);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
td {
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
}
td strong {
  display: block;
  color: #fff;
  font-size: 14px;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 4px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  color: var(--soft);
  font-size: 11px;
  font-weight: 900;
}
.tag-green { border-color: rgba(42, 157, 143, 0.65); color: #9be0d6; }
.tag-gold { border-color: rgba(237, 174, 73, 0.65); color: #ffd084; }
.tag-red { border-color: rgba(209, 73, 91, 0.75); color: #ffacb5; }
.tag-blue { border-color: rgba(78, 168, 222, 0.65); color: #a9dcff; }
.stack-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}
.stack-item {
  border: 1px solid rgba(51, 68, 76, 0.82);
  border-radius: 8px;
  padding: 10px;
  background: #111a20;
}
.stack-item strong {
  display: block;
  margin-bottom: 4px;
}
.stack-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.endpoint-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}
.endpoint {
  display: grid;
  gap: 5px;
}
code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  color: #fff;
  background: #101820;
}
.empty-state {
  padding: 24px 14px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 1040px) {
  .landing-grid { grid-template-columns: 1fr; }
  .login-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    justify-content: flex-start;
  }
  .tile-region { min-height: 720px; }
  .crm-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }
  .workspace-tools,
  .workspace-tools input {
    width: 100%;
  }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .view-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .public-header { position: static; }
  .landing-grid { padding-top: 16px; }
  .tile-region { min-height: 780px; }
  .tile-wall { grid-template-rows: 180px repeat(4, minmax(112px, 1fr)); }
  .tile-row.three,
  .tile-row.two { grid-template-columns: 1fr; }
  .tile-row.mobile-hide { display: none; }
  .tile-hero .tile-title { font-size: 34px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th:nth-child(n+4),
  td:nth-child(n+4) { display: none; }
}