:root {
  --bg: #f6f7f9;
  --sidebar: #0b1f3a;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --text: #172033;
  --muted: #687386;
  --line: #dfe5ec;
  --panel: #ffffff;
  --warn: #b45309;
  --ok: #047857;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #eef2f7;
  padding: 20px;
}

.login-screen.hidden {
  display: none;
}

.login-panel {
  width: min(520px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
  padding: 26px;
}

.login-panel h1 {
  margin: 22px 0 16px;
}

.login-panel .brand {
  color: var(--text);
}

.login-panel .brand span {
  color: var(--muted);
}

.login-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: var(--sidebar);
  color: #fff;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--primary);
  border-radius: 8px;
  font-weight: 800;
}

.brand span,
.tenant-card span,
.tenant-card small {
  display: block;
  color: #b9c6d8;
  font-size: 12px;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 7px;
  overflow: auto;
}

.nav-item {
  color: #dce7f4;
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  padding: 11px 12px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.tenant-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 14px;
}

.shell {
  margin-left: 260px;
  min-height: 100vh;
  padding: 26px 30px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary,
.ghost {
  border-radius: 8px;
  padding: 10px 15px;
  cursor: pointer;
}

.primary {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

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

.ghost:hover {
  border-color: #b7c4d4;
  background: #f8fafc;
}

.small {
  padding: 8px 12px;
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-gap {
  margin-top: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 30px;
  margin: 8px 0 4px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  background: #eef2f7;
  color: #475569;
  white-space: nowrap;
}

.tag.ok {
  background: #dcfce7;
  color: var(--ok);
}

.tag.warn {
  background: #fef3c7;
  color: var(--warn);
}

.rank-list,
.check-list,
.permission-grid,
.activity-list,
.summary-list {
  display: grid;
  gap: 12px;
}

.rank-list div,
.permission-grid div,
.activity-list div,
.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.permission-grid div,
.summary-list div {
  display: grid;
}

.permission-grid span,
.rank-list span,
.activity-list span,
.summary-list span {
  color: var(--muted);
}

.check-list label {
  display: flex;
  gap: 9px;
  align-items: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  text-align: left;
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
}

th {
  color: #334155;
  background: #f8fafc;
  font-size: 13px;
}

td:last-child,
th:last-child {
  white-space: nowrap;
}

.quote-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}

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

.form-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-section,
.dynamic-fields {
  grid-column: 1 / -1;
}

.form-section {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px 14px;
}

.form-section strong,
.form-section span {
  display: block;
}

.form-section span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.dynamic-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.process-options label {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.process-options input {
  width: auto;
  margin-top: 2px;
}

label {
  color: #334155;
  font-size: 13px;
}

input,
select {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
}

.search {
  width: min(260px, 100%);
  margin-top: 0;
  padding: 8px 11px;
}

.role-select {
  width: auto;
  min-width: 138px;
  margin-top: 0;
  padding: 9px 11px;
}

.session-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 8px 11px;
  font-size: 13px;
}

.summary {
  position: sticky;
  top: 20px;
  align-self: start;
}

.price {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.price span,
.price small {
  color: var(--muted);
}

.price strong {
  display: block;
  font-size: 30px;
  margin: 8px 0 4px;
}

.cost-lines {
  display: grid;
  gap: 9px;
  margin: 0;
}

.cost-lines div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.cost-lines dt {
  color: var(--muted);
}

.cost-lines dd {
  margin: 0;
  font-weight: 700;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.rule-box {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #475569;
  font-size: 13px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.detail-row span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.master-form {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.form-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.form-group h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.drawer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.drawer-grid .wide {
  grid-column: 1 / -1;
}

.drawer-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: linear-gradient(rgba(255, 255, 255, 0.84), #fff 35%);
  padding-top: 14px;
}

.sql {
  white-space: pre-wrap;
  background: #0f172a;
  color: #dbeafe;
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #0f766e;
  color: #fff;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.18);
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  background: rgba(15, 23, 42, 0.28);
}

.drawer.open {
  display: block;
}

.drawer-panel {
  position: absolute;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  background: #fff;
  box-shadow: -18px 0 36px rgba(15, 23, 42, 0.16);
  padding: 24px;
  overflow: auto;
}

.drawer-close {
  float: right;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .shell {
    margin-left: 0;
    padding: 20px;
  }

  .metric-grid,
  .two-col,
  .quote-layout,
  .form-grid,
  .dynamic-fields {
    grid-template-columns: 1fr;
  }

  .button-grid,
  .form-grid.compact,
  .drawer-grid {
    grid-template-columns: 1fr;
  }

  .drawer-grid .wide {
    grid-column: auto;
  }

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

  .panel {
    overflow-x: auto;
  }

  th,
  td {
    padding: 11px 8px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}
