@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
  --canvas: #f3f4f6;
  --background: #ffffff;
  --foreground: #3c3c3a;
  --muted: #757575;
  --border: #c4c4c4;
  --border-soft: #e8e9eb;
  --hover: #f3f4f6;
  --selected: #f3f4f6;
  --blue-100: #1c3d5e;
  --blue-80: #4a8cca;
  --blue-40: #c0d7ed;
  --blue-20: #dce9f4;
  --red: #f8485e;
  --pink: #ec86a3;
  --pink-10: #fddade;
  --green: #5ab891;
  --yellow: #fcc354;
  --orange: #f09e52;
  --card-shadow: 0 1px 4px rgba(0, 0, 0, .16);
  --header-height: 3.5rem;
  --sidebar-width: 15rem;
  --login-strip-width: 5px;
}

html.dark {
  --canvas: #080323;
  --background: #15112e;
  --foreground: #f3f4f6;
  --muted: #c4c4c4;
  --border: #1c3d5e;
  --border-soft: #1c3d5e;
  --hover: #21194b;
  --selected: #21194b;
  --blue-100: #c0d7ed;
  --blue-80: #4a8cca;
  --blue-40: #6c7894;
  --blue-20: #1e1845;
  --card-shadow: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--foreground);
  background: var(--canvas);
  font-family: Montserrat, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-size: 14px;
  font-weight: 500;
  line-height: 24px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; text-decoration: none; }

.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) var(--login-strip-width) minmax(360px, .82fr);
  background: var(--background);
}
.login-media { position: relative; overflow: hidden; background: #080323; }
.login-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.login-strip {
  min-height: 100%;
  background: linear-gradient(
    180deg,
    var(--red) 0%,
    var(--red) 12%,
    var(--blue-100) 34%,
    var(--blue-80) 70%,
    #38c9f6 100%
  );
}
.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 54px;
  background: var(--background);
  box-shadow: -20px 0 60px rgba(0,0,0,.12);
}
.login-panel img { width: 150px; margin-bottom: 52px; }
.login-panel h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.15; color: var(--blue-100); font-weight: 700; }
.login-panel p { margin: 0 0 28px; color: var(--muted); line-height: 1.5; }
.login-foot { margin-top: 56px; color: var(--muted); font-size: 12px; }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--foreground);
  font-size: 12px;
  font-weight: 600;
}
.field-help {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--background);
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  cursor: help;
  padding: 0;
}
.field-help:hover,
.field-help:focus {
  color: var(--blue-80);
  border-color: var(--blue-80);
  outline: none;
}
html.dark .field-help {
  background: #15112e;
  border-color: #6c7894;
  color: #c7c2d8;
}
html.dark .field-help:hover,
html.dark .field-help:focus {
  color: #78aee0;
  border-color: #78aee0;
}
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--background);
  color: var(--foreground);
  padding: 9px 10px;
  outline: none;
  min-height: 36px;
}
html.dark .input,
html.dark .select,
html.dark .textarea {
  background: #15112e;
  border-color: #6c7894;
  color: var(--foreground);
}
html.dark .input::placeholder,
html.dark .textarea::placeholder {
  color: #6c7894;
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: .55;
  cursor: not-allowed;
  background: #f3f5f7;
}
html.dark .input:disabled,
html.dark .select:disabled,
html.dark .textarea:disabled {
  background: #0f0a2a;
  border-color: rgba(108, 120, 148, .45);
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue-80);
  box-shadow: 0 0 0 2px rgba(74, 140, 202, .16);
}
.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.check-field {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 6px 10px;
  background: #fafafa;
  color: var(--foreground);
  font-size: 12px;
  font-weight: 600;
}
html.dark .check-field {
  background: #080323;
  border-color: #1c3d5e;
}
.check-field.disabled {
  opacity: .45;
  cursor: not-allowed;
}
.check-field.cloud-choice {
  gap: 8px;
  padding-right: 12px;
}
.field.disabled label {
  color: var(--muted);
}
.cloud-icon {
  width: 34px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.cloud-icon.azure {
  width: 18px;
}
.cloud-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.cloud-label,
.cloud-pill,
.cloud-list {
  display: inline-flex;
  align-items: center;
}
.cloud-label {
  gap: 6px;
  vertical-align: middle;
}
.cloud-list {
  flex-wrap: wrap;
  gap: 6px;
}
.cloud-pill {
  gap: 6px;
  min-height: 24px;
  padding: 2px 8px 2px 6px;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  background: var(--hover);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 700;
}
html.dark .cloud-pill {
  border-color: #1c3d5e;
  background: #21194b;
}
.btn {
  min-height: 36px;
  border: 1px solid var(--blue-80);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: white;
  background: var(--blue-80);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn.secondary { color: var(--foreground); background: var(--hover); border-color: var(--border-soft); }
.btn.dark { color: white; background: var(--blue-100); border-color: var(--blue-100); }
.btn.ghost { color: var(--foreground); background: transparent; border-color: transparent; }
.btn.dashed { color: var(--foreground); background: rgba(255,255,255,.35); border-style: dashed; border-color: var(--border); }
.btn.danger { background: var(--red); border-color: var(--red); }
html.dark .btn.secondary {
  color: var(--foreground);
  background: #21194b;
  border-color: #1c3d5e;
}
html.dark .btn.ghost { color: var(--foreground); }
html.dark .btn.dashed {
  color: var(--foreground);
  background: rgba(21, 17, 46, .42);
  border-color: #344c70;
}
.error {
  display: none;
  color: #9b1c2b;
  background: #fff1f3;
  border: 1px solid #ffd0d8;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 12px;
}
html.dark .error {
  color: #fca2ae;
  background: rgba(248, 72, 94, .12);
  border-color: rgba(248, 72, 94, .45);
}

.shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  background: var(--canvas);
}
html.dark .shell { background: #080323; }
.side {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  height: 100svh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px 12px;
  background: var(--background);
  color: var(--foreground);
  z-index: 12;
}
html.dark .side {
  background: #080323;
}
.side::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, var(--red), var(--blue-80));
}
.side-logo { width: 132px; height: auto; margin: 0 4px 20px; }
html.dark .side-logo { content: url('/static/assets/pulse-logo-dark.svg'); }
.nav { display: grid; gap: 6px; }
.nav-group { display: grid; gap: 4px; }
.nav button {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 8px 8px;
  color: var(--foreground);
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
}
.nav button:hover, .nav button.active { background: var(--hover); }
.nav button.active .nav-icon { color: var(--red); }
.nav-children {
  display: grid;
  gap: 2px;
  margin-left: 20px;
  padding-left: 10px;
  border-left: 1px solid var(--border-soft);
}
.nav-child {
  min-height: 28px !important;
  padding: 4px 10px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
}
.nav-child.active { color: var(--blue-100); }
html.dark .nav button {
  color: var(--foreground);
}
html.dark .nav button:hover,
html.dark .nav button.active {
  background: #21194b;
}
html.dark .nav-children { border-left-color: #1c3d5e; }
.nav-spacer { flex: 1; }
.side-meta {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  padding: 8px 8px 2px;
}
.nav-icon {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 17px;
  color: var(--foreground);
}
.main {
  min-width: 0;
  grid-column: 2;
  padding-top: var(--header-height);
  background:
    linear-gradient(112deg, rgba(248, 72, 94, .12) 0%, rgba(248, 72, 94, .08) 13%, rgba(74, 140, 202, .14) 38%, rgba(243, 244, 246, .92) 70%),
    linear-gradient(180deg, rgba(255, 255, 255, .2) 0%, var(--canvas) 58%);
  min-height: 100svh;
}
html.dark .main {
  background:
    linear-gradient(115deg, rgba(248, 72, 94, .24) 0%, rgba(248, 72, 94, .16) 13%, rgba(74, 140, 202, .18) 43%, rgba(8, 3, 35, .96) 76%),
    linear-gradient(180deg, #15112e 0%, #080323 36%, #080323 100%);
}
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 0 18px;
  background: rgba(255,255,255,.36);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, var(--red), var(--blue-80)) 1;
  z-index: 10;
}
html.dark .topbar {
  background: rgba(21, 17, 46, .72);
  border-image: linear-gradient(90deg, var(--red), #4a8cca) 1;
}
.topbar h1 { display: none; }
.scope-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.tenant-menu {
  position: relative;
}
.tenant-button {
  height: 32px;
  min-width: 122px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 0 12px;
  background: rgba(255,255,255,.34);
  color: white;
  background-color: var(--blue-80);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
  font-size: 12px;
  font-weight: 600;
}
.tenant-button:hover { background-color: var(--blue-100); }
.business-unit-button {
  min-width: 170px;
  color: var(--foreground);
  background: rgba(255,255,255,.34);
  background-color: rgba(255,255,255,.34);
}
.business-unit-button:hover {
  background-color: rgba(74, 140, 202, .13);
}
html.dark .tenant-button {
  border-color: #344c70;
  color: white;
  background-color: #4a8cca;
}
html.dark .tenant-button:hover { background-color: #2e689e; }
html.dark .business-unit-button {
  color: var(--foreground);
  background-color: rgba(21, 17, 46, .5);
}
html.dark .business-unit-button:hover {
  background-color: rgba(74, 140, 202, .22);
}
.chevron {
  width: 7px;
  height: 7px;
  display: inline-block;
  flex: 0 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
  opacity: .78;
}
.tenant-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  display: grid;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 0;
  background: var(--background);
  box-shadow: 0 8px 22px rgba(0,0,0,.14);
  z-index: 30;
}
html.dark .tenant-popover {
  background: #15112e;
  border-color: #344c70;
  box-shadow: 0 8px 24px rgba(0,0,0,.38);
}
.tenant-option, .tenant-create {
  min-height: 32px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  padding: 6px 12px;
  background: transparent;
  color: var(--foreground);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
}
.tenant-option small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.tenant-option:hover, .tenant-create:hover { background: var(--hover); }
.tenant-create {
  justify-content: flex-start;
  border-top: 1px solid var(--border-soft);
  margin-top: 6px;
  padding-top: 10px;
  color: var(--blue-80);
}
.checkmark {
  font-size: 0;
  color: var(--foreground);
}
.checkmark::before {
  content: "\2713";
  font-size: 14px;
}
.tenant-chip {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  background: rgba(255,255,255,.35);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 600;
}
html.dark .tenant-chip {
  background: rgba(21, 17, 46, .5);
  border-color: #344c70;
  color: var(--foreground);
}
.identity { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.avatar {
  border: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: white;
  background: var(--blue-80);
  font-weight: 700;
  font-size: 14px;
}
.avatar.large {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
}
.profile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 96vw);
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  background: var(--background);
  box-shadow: -10px 0 28px rgba(28, 61, 94, .18);
  transform: translateX(100%);
  transition: transform .2s ease;
  z-index: 50;
}
html.dark .profile-drawer {
  background: #15112e;
  box-shadow: -10px 0 28px rgba(0,0,0,.42);
}
.profile-drawer.open { transform: translateX(0); }
.profile-rail {
  background: var(--blue-100);
  color: white;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10px;
}
html.dark .profile-rail { background: #1c3d5e; }
.drawer-close {
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: white;
  font-size: 18px;
  line-height: 1;
}
.profile-body {
  padding: 24px;
  display: block;
}
.profile-body hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: 18px 0 14px;
}
.profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.profile-head strong {
  display: block;
  color: var(--blue-100);
  font-size: 14px;
  line-height: 18px;
  font-weight: 700;
}
html.dark .profile-head strong { color: var(--foreground); }
.profile-head span {
  display: block;
  color: var(--foreground);
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
}
.drawer-label, .drawer-section strong {
  display: block;
  margin-bottom: 8px;
  color: var(--foreground);
  font-size: 12px;
  font-weight: 700;
}
.drawer-section { margin-top: 16px; }
.drawer-action {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 5px 0;
  background: transparent;
  color: var(--foreground);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
}
.split-action {
  justify-content: space-between;
}
.split-action input {
  appearance: none;
  width: 24px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background:
    radial-gradient(circle at 6px 50%, var(--muted) 0 4px, transparent 4.5px),
    var(--hover);
  transition: background .15s ease, border-color .15s ease;
}
.split-action input:checked {
  border-color: var(--blue-80);
  background:
    radial-gradient(circle at 17px 50%, white 0 4px, transparent 4.5px),
    var(--blue-80);
}
.danger-text { color: var(--red); }
.content {
  padding: 24px 26px 96px 32px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.page-title {
  margin: 0 0 16px;
  color: var(--blue-100);
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
}
html.dark .page-title { color: var(--foreground); }
.page-head .page-title { margin-bottom: 0; }
.tenant-select { width: min(280px, 36vw); }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.panel, .pulse-card {
  position: relative;
  background: var(--background);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  box-shadow: var(--card-shadow);
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
html.dark .panel,
html.dark .pulse-card {
  background: #15112e;
  border-color: #1c3d5e;
}
.panel.pad { padding: 16px; }
.panel h2, .panel h3 { margin: 0; color: var(--foreground); font-size: 14px; line-height: 20px; font-weight: 600; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.metric {
  min-height: 80px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 14px 16px 13px;
}
.metric > div:first-child { min-width: 0; }
.metric > div:first-child > span {
  display: block;
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
}
.metric strong {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--blue-100);
  font-size: 24px;
  line-height: 32px;
  font-weight: 700;
  white-space: nowrap;
}
html.dark .metric strong,
html.dark .cost-value,
html.dark .impact-stat strong,
html.dark .infra-stat strong,
html.dark .entity-card h3 {
  color: var(--foreground);
}
.metric em { display: block; margin-top: 0; color: var(--muted); font-size: 12px; line-height: 16px; font-style: normal; }
.metric-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--blue-40);
}
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-height: 21px;
  border-radius: 3px;
  padding: 2px 7px;
  color: white;
  background: var(--pink);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  flex: 0 0 auto;
}
.delta.green { background: var(--green); }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.dash-panel {
  min-height: 386px;
  padding: 18px 16px 14px;
}
.dash-panel h3 { font-size: 14px; line-height: 20px; font-weight: 600; margin: 0 0 16px; }
.dash-panel.wide { grid-column: span 1; }
.cost-value {
  color: var(--blue-100);
  font-size: 24px;
  line-height: 32px;
  font-weight: 700;
}
.subtle { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.chart-svg { width: 100%; height: 250px; display: block; }
.chart-svg [data-tip] { cursor: pointer; }
.chart-svg text { font-family: inherit; font-weight: 500; }
html.dark .chart-svg line { stroke: rgba(196, 196, 196, .36); }
html.dark .chart-svg text { fill: #6c7894; }
.donut-edge { pointer-events: none; }
.donut-segment { cursor: pointer; }
.legend {
  display: flex;
  justify-content: center;
  gap: 42px;
  color: var(--muted);
  font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; margin-right: 5px; }
.impact-row, .infra-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}
.impact-stat, .infra-stat {
  border-left: 2px solid var(--pink);
  padding-left: 12px;
}
.impact-stat:nth-child(2), .infra-stat:nth-child(2) { border-color: var(--yellow); }
.impact-stat:nth-child(3), .infra-stat:nth-child(3) { border-color: var(--green); }
.impact-stat strong, .infra-stat strong { display: block; color: var(--blue-100); font-size: 24px; line-height: 26px; font-weight: 700; }
.impact-stat span, .infra-stat span { color: var(--muted); font-size: 12px; }
.map-wrap { display: grid; justify-items: center; gap: 10px; }
.map-svg { width: 100%; height: 214px; display: block; }
.map-legend {
  width: 56%;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.map-legend div { display: flex; justify-content: space-between; }
.world-dot { filter: drop-shadow(0 4px 6px rgba(28, 61, 94, .25)); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  color: var(--muted);
  background: #fafafa;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--foreground); }
html.dark th {
  color: var(--muted);
  background: #080323;
}
html.dark th:hover { color: var(--foreground); }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
html.dark th,
html.dark td {
  border-bottom-color: #1c3d5e;
}
.sort-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.sort-indicator {
  width: 7px;
  height: 7px;
  display: inline-block;
  flex: 0 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0;
  transform: rotate(45deg) translateY(-1px);
  transition: opacity .12s ease, transform .12s ease;
}
th:hover .sort-indicator { opacity: .28; }
.sort-indicator.sort-asc {
  opacity: .82;
  transform: rotate(225deg) translate(-1px, -1px);
}
.sort-indicator.sort-desc {
  opacity: .82;
  transform: rotate(45deg) translateY(-1px);
}
td.wrap { white-space: normal; min-width: 220px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 3px;
  padding: 2px 8px;
  background: var(--hover);
  color: var(--foreground);
  font-weight: 700;
  font-size: 12px;
}
.badge.green { color: #2f7a60; background: #e7f5ef; }
.badge.red { color: #9b1c2b; background: #fff1f3; }
.badge.blue { color: var(--blue-100); background: var(--blue-20); }
html.dark .badge {
  color: var(--foreground);
  background: #21194b;
}
html.dark .badge.green { color: #5ab891; background: rgba(90, 184, 145, .14); }
html.dark .badge.red { color: #fca2ae; background: rgba(248, 72, 94, .14); }
html.dark .badge.blue { color: #c0d7ed; background: #1e1845; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}
.toolbar .field { min-width: 180px; }
.view-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
html.dark .view-tools { background: #15112e; }
.view-tools .data-filter { max-width: 360px; }
.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.builder-status {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
}
.builder-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: #fafafa;
}
html.dark .segmented {
  background: #080323;
  border-color: #1c3d5e;
}
.action-row { display: inline-flex; gap: 6px; align-items: center; }
.btn.icon-btn {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}
.btn.sync-status-btn {
  width: 92px;
  padding-left: 6px;
  padding-right: 6px;
  white-space: nowrap;
}
.btn.sync-status-btn.is-loading {
  gap: 5px;
}
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.entity-grid-catalog,
.entity-grid-business-units,
.entity-grid-customers,
.entity-grid-discounts,
.entity-grid-invoice-lines,
.entity-grid-subscriptions,
.entity-grid-invoices,
.entity-grid-partners,
.entity-grid-users {
  grid-template-columns: repeat(auto-fill, minmax(300px, 380px));
  justify-content: start;
}
.entity-card {
  padding: 16px;
  display: grid;
  gap: 10px;
}
.entity-card h3 { margin: 0; color: var(--blue-100); font-size: 16px; font-weight: 700; }
.entity-card p { margin: 0; color: var(--muted); font-size: 12px; }
.structured-card,
.discount-card {
  align-content: start;
  gap: 14px;
  min-height: 0;
}
.entity-card-head,
.discount-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.entity-card-head > div,
.discount-card-head > div {
  min-width: 0;
}
.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  text-transform: uppercase;
}
.structured-card h3,
.discount-card h3 {
  overflow-wrap: anywhere;
  line-height: 22px;
}
.entity-value,
.discount-value {
  display: grid;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(220, 233, 244, .58), rgba(255,255,255,.2));
}
html.dark .entity-value,
html.dark .discount-value {
  background: linear-gradient(90deg, rgba(74, 140, 202, .13), rgba(33, 25, 75, .28));
  border-color: #1c3d5e;
}
.entity-value strong,
.discount-value strong {
  color: var(--blue-100);
  font-size: 24px;
  line-height: 30px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
html.dark .entity-value strong,
html.dark .discount-value strong {
  color: var(--foreground);
}
.entity-value span,
.discount-value span {
  color: var(--muted);
  font-size: 12px;
}
.entity-details,
.discount-details {
  display: grid;
  gap: 8px;
  margin: 0;
}
.entity-detail,
.discount-detail {
  display: grid;
  grid-template-columns: minmax(94px, .48fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.entity-detail dt,
.discount-detail dt {
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
  font-weight: 700;
  text-transform: uppercase;
}
.entity-detail dd,
.discount-detail dd {
  min-width: 0;
  margin: 0;
  color: var(--foreground);
  font-size: 12px;
  line-height: 18px;
  overflow-wrap: anywhere;
}
.mapping-list {
  display: grid;
  gap: 8px;
}
.mapping-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: var(--panel-soft);
}
.mapping-row strong,
.mapping-row span {
  display: block;
}
.mapping-row span {
  color: var(--muted);
  font-size: 12px;
}
.mapping-row code {
  color: var(--blue-100);
  font-size: 12px;
  white-space: nowrap;
}
html.dark .mapping-row {
  border-color: #1c3d5e;
  background: rgba(255,255,255,.03);
}
.timeline {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.timeline-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
}
.timeline-dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--blue-80);
  box-shadow: 0 0 0 4px rgba(74, 140, 202, .14);
}
.timeline-row.success .timeline-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(91, 184, 145, .14); }
.timeline-row.failed .timeline-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(248, 72, 94, .14); }
.timeline-row.skipped .timeline-dot { background: var(--yellow); box-shadow: 0 0 0 4px rgba(246, 190, 77, .16); }
.timeline-body {
  display: grid;
  gap: 6px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.timeline-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.timeline-head strong {
  color: var(--blue-100);
  font-size: 13px;
}
.timeline-head span,
.timeline-body small {
  color: var(--muted);
  font-size: 12px;
}
.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.timeline-meta code {
  color: var(--blue-100);
  font-size: 12px;
}
.timeline-body p {
  margin: 0;
  color: var(--foreground);
  font-size: 13px;
}
html.dark .timeline-body { border-bottom-color: #1c3d5e; }
.structured-card .action-row,
.discount-card .action-row {
  margin-top: 2px;
}
.subscription-card .action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.subscription-card .btn.icon-btn {
  width: 100%;
  min-width: 0;
  white-space: normal;
}
.subscription-card .btn.sync-status-btn {
  width: 100%;
}
.compact-card {
  gap: 10px;
  padding: 12px;
}
.compact-card .entity-value {
  padding: 10px;
}
.compact-card .entity-value strong {
  font-size: 18px;
  line-height: 24px;
}
.bar-list { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 6px; }
.bar-label { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.bar-track { height: 8px; border-radius: 999px; background: var(--border-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--blue-80); }
html.dark .bar-track { background: rgba(108, 120, 148, .28); }
html.dark .bar-fill { background: #4a8cca; }
.empty { padding: 24px; color: var(--muted); text-align: center; }
.entity-grid > .empty { grid-column: 1 / -1; }
.split { display: flex; gap: 10px; align-items: center; }
.hidden { display: none !important; }
.field.full { grid-column: 1 / -1; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(28, 61, 94, .28);
  backdrop-filter: blur(4px);
  z-index: 40;
}
html.dark .modal-backdrop {
  background: rgba(8, 3, 35, .62);
}
.modal {
  width: min(860px, 96vw);
  max-height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.confirm-modal {
  width: min(520px, 94vw);
  max-height: none;
}
.modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
  overflow: auto;
}
.confirm-body {
  grid-template-columns: 1fr;
  padding: 20px 16px 16px;
  overflow: visible;
}
.info-body {
  grid-template-columns: 1fr;
  overflow: auto;
}
.confirm-copy {
  display: grid;
  gap: 8px;
}
.confirm-message {
  margin: 0;
  color: var(--foreground);
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
}
.confirm-detail {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
}
.confirm-error {
  margin-bottom: 0;
}
.explain-stack {
  display: grid;
  gap: 16px;
}
.explain-summary {
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(220, 233, 244, .52), rgba(255,255,255,.18));
}
html.dark .explain-summary {
  border-color: #1c3d5e;
  background: linear-gradient(90deg, rgba(74, 140, 202, .12), rgba(33, 25, 75, .28));
}
.explain-summary strong {
  display: block;
  color: var(--blue-100);
  font-size: 14px;
  line-height: 22px;
}
html.dark .explain-summary strong {
  color: var(--foreground);
}
.explain-context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.explain-stat {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: rgba(255,255,255,.42);
}
html.dark .explain-stat {
  border-color: #1c3d5e;
  background: rgba(21, 17, 46, .48);
}
.explain-stat span {
  color: var(--muted);
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  text-transform: uppercase;
}
.explain-stat strong {
  color: var(--foreground);
  font-size: 13px;
  line-height: 18px;
  overflow-wrap: anywhere;
}
.explain-section {
  display: grid;
  gap: 10px;
}
.explain-section h4 {
  margin: 0;
  color: var(--blue-100);
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
}
html.dark .explain-section h4 {
  color: var(--foreground);
}
.explain-rule-list {
  display: grid;
  gap: 10px;
}
.explain-rule {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: rgba(255,255,255,.4);
}
.explain-rule.applied {
  background: linear-gradient(90deg, rgba(220, 233, 244, .56), rgba(255,255,255,.22));
}
html.dark .explain-rule,
html.dark .explain-rule.applied {
  border-color: #1c3d5e;
  background: rgba(21, 17, 46, .46);
}
.explain-rule-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.explain-rule-head strong {
  display: block;
  color: var(--foreground);
  font-size: 13px;
  line-height: 18px;
}
.explain-rule-head span {
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
}
.explain-rule-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.explain-rule p {
  margin: 0;
  color: var(--foreground);
  font-size: 12px;
  line-height: 18px;
}
.form-section {
  grid-column: 1 / -1;
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: rgba(220, 233, 244, .18);
}
html.dark .form-section {
  background: rgba(74, 140, 202, .06);
  border-color: rgba(74, 140, 202, .32);
}
.form-section-head {
  display: grid;
  gap: 3px;
}
.form-section-head h4 {
  margin: 0;
  color: var(--blue-100);
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
}
html.dark .form-section-head h4 { color: #f2f0fa; }
.form-section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 17px;
}
.form-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}
.spinner {
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,.32);
  border-top-color: currentColor;
  border-radius: 999px;
  animation: spin .7s linear infinite;
}
.spinner.sm {
  width: 14px;
  height: 14px;
}
.btn.secondary .spinner {
  border-color: rgba(60, 60, 58, .2);
  border-top-color: currentColor;
}
html.dark .btn.secondary .spinner {
  border-color: rgba(243, 244, 246, .2);
  border-top-color: currentColor;
}
.btn.danger .spinner {
  border-color: rgba(255,255,255,.28);
  border-top-color: currentColor;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.chart-tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--card-shadow);
  font-size: 12px;
  font-weight: 600;
}
html.dark .chart-tip {
  background: #15112e;
  border-color: #6c7894;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
}
.interactive-outline:hover {
  border-color: transparent;
  background:
    linear-gradient(var(--background), var(--background)) padding-box,
    linear-gradient(90deg, var(--red), var(--blue-80)) border-box;
  box-shadow: 0 7px 18px rgba(28, 61, 94, .16);
  transform: translateY(-1px);
}
html.dark .interactive-outline:hover {
  background:
    linear-gradient(#21194b, #21194b) padding-box,
    linear-gradient(135deg, var(--red) 0%, #4a8cca 62%, #38c9f6 100%) border-box;
  border-color: transparent;
  box-shadow: none;
}

@media (max-width: 1280px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1040px) {
  :root { --sidebar-width: 13.5rem; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-media { display: none; }
  .login-strip { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static;
    width: 100%;
    height: auto;
    border-right: 0;
  }
  .side::after {
    top: auto;
    bottom: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, var(--red), var(--blue-80));
  }
  .nav-spacer { display: none; }
  .main { grid-column: 1; padding-top: 0; }
  .topbar { position: static; height: auto; min-height: var(--header-height); left: 0; flex-wrap: wrap; padding: 10px 14px; }
  .scope-controls { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .tenant-button, .business-unit-button { min-width: min(100%, 180px); }
  .content { padding: 18px; }
  .grid.cols-4 { grid-template-columns: 1fr; }
  .view-tools { align-items: stretch; flex-direction: column; }
  .view-tools .data-filter { max-width: none; }
  .modal-body, .form-section-grid { grid-template-columns: 1fr; }
  .explain-context-grid { grid-template-columns: 1fr; }
  .login-panel { padding: 34px 24px; }
}
