:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-raised: #fcfdff;
  --text: #172033;
  --muted: #687386;
  --muted-strong: #4f5c70;
  --line: #dfe4ec;
  --line-strong: #cbd3df;
  --primary: #335cff;
  --primary-dark: #2448d8;
  --primary-soft: #eef2ff;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning-bg: #fff7e8;
  --warning: #8a5200;
  --success: #176b45;
  --success-soft: #edf8f2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

button {
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  padding: 9px 14px;
  font-weight: 680;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

button:hover:not(:disabled) { background: var(--primary-dark); }
button:disabled { cursor: not-allowed; opacity: .48; }

button.secondary, button.quiet, button.danger-quiet {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}

button.secondary:hover:not(:disabled), button.quiet:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: #aeb8c7;
}

button.danger-quiet { color: var(--danger); }
button.danger-quiet:hover:not(:disabled) { background: var(--danger-soft); border-color: #f3b9b3; }
button.quiet { padding: 7px 10px; }
button.compact-button { padding: 6px 9px; font-size: 12px; }
button.full-width { width: 100%; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
}

textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(51 92 255 / 18%);
  outline-offset: 1px;
  border-color: var(--primary);
}

label, legend {
  color: #364154;
  font-size: 13px;
  font-weight: 650;
}

label input, label select, label textarea { margin-top: 6px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 25px; letter-spacing: -.02em; }
h2 { margin-bottom: 0; font-size: 20px; letter-spacing: -.01em; }
h3 { margin: 0; font-size: 15px; }

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.login-card {
  width: min(430px, 100%);
  margin: 15vh auto 0;
  padding: 30px 32px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 16px 44px rgb(22 34 56 / 8%);
}

.login-card h1 { margin-bottom: 8px; font-size: 27px; }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.muted { color: var(--muted); line-height: 1.55; }
.muted-small { color: var(--muted); font-size: 12px; }
.error { color: var(--danger) !important; }
.login-card .error { min-height: 20px; margin: 12px 0 0; }

.topbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 6px;
}

.brand-row, .topbar-actions, .page-heading, .save-cluster, .lease-heading-actions, .subsection-heading,
.global-strip, .management-row, .effective-controls, .lease-card-actions, .effective-lease-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.product-chip, .status-chip, .readonly-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.product-chip { background: var(--surface-soft); color: var(--muted-strong); border: 1px solid var(--line); }
.status-chip[data-state="clean"] { background: var(--success-soft); color: var(--success); }
.status-chip[data-state="dirty"] { background: var(--warning-bg); color: var(--warning); }
.status-chip[data-state="temporary"] { background: var(--primary-soft); color: #3849b5; }
.status-chip[data-state="danger"] { background: var(--danger-soft); color: var(--danger); }
.readonly-chip { background: var(--primary-soft); color: #3849b5; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.snapshot-details { position: relative; }
.snapshot-details > summary, .management-menu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted-strong);
  padding: 7px 10px;
  font-weight: 650;
}
.snapshot-details > summary::-webkit-details-marker, .management-menu > summary::-webkit-details-marker { display: none; }
.snapshot-details > summary code { color: var(--text); margin-left: 4px; font-size: 11px; }

.snapshot-popover, .management-popover {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 8px);
  width: min(470px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 16px 42px rgb(22 34 56 / 14%);
  padding: 14px;
}

.snapshot-popover { display: grid; gap: 10px; }
.snapshot-popover > div { display: grid; gap: 3px; }
.snapshot-popover span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.snapshot-popover code { font-size: 11px; word-break: break-all; line-height: 1.45; }
.snapshot-popover button { justify-self: end; }

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px 9px;
}
.tabs button:hover:not(:disabled) { background: transparent; color: var(--text); }
.tabs button[aria-current="page"] { border-bottom-color: var(--primary); color: var(--primary); }

.notice {
  margin: -6px 0 12px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 9px 11px;
  font-size: 13px;
}
.notice[data-visible="false"], .notice:empty { display: none; }
.notice.error { background: var(--danger-soft); }

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 22px 24px 26px;
}

.page-heading {
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
}
.section-description { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.save-cluster, .lease-heading-actions { flex-shrink: 0; }

.context-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  margin-bottom: 12px;
}
.context-select { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; }
.context-select select { margin-top: 0; }
.management-menu { position: relative; }
.management-popover { width: min(420px, calc(100vw - 32px)); display: grid; gap: 10px; }
.management-row { align-items: stretch; }
.management-row button { flex-shrink: 0; }

.warning {
  margin: 0;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.global-strip {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 2px 14px;
  margin-bottom: 2px;
}
.global-strip > div:first-child { display: grid; gap: 2px; }
.inline-options { display: flex; gap: 16px; align-items: center; }
.inline-options label, .checkbox-grid label { display: flex; align-items: center; gap: 7px; font-weight: 520; }
.inline-options input, .checkbox-grid input { width: auto; margin: 0; }

.policy-form { display: grid; }
.policy-group { padding: 18px 0; border-bottom: 1px solid var(--line); }
.policy-group:last-child { border-bottom: 0; padding-bottom: 0; }
.group-heading { margin-bottom: 12px; }
.group-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.field-hint { color: var(--muted); font-size: 11px; font-weight: 500; }

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

fieldset {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  margin: 0;
}

.capability-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.checkbox-grid { display: grid; gap: 5px; margin-top: 5px; }
.capability-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.checkbox-option {
  min-width: 0;
  border-radius: 6px;
  padding: 5px 7px;
  color: var(--muted-strong);
}
.checkbox-option:hover { background: var(--surface-soft); }
.checkbox-option span { min-width: 0; overflow-wrap: anywhere; }

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

.lease-management { border-top: 1px solid var(--line); padding-top: 16px; }
.subsection-heading { justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.subsection-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card-list { display: grid; gap: 10px; }
.lease-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.lease-card, .effective-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-raised);
  padding: 14px;
}
.lease-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.lease-identity { min-width: 0; display: grid; gap: 3px; }
.lease-identity strong { font-size: 14px; overflow-wrap: anywhere; }
.lease-repository { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.lease-card-actions { flex-shrink: 0; }
.lease-block { margin-top: 12px; }
.meta-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }

.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }
.token {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-strong);
  padding: 3px 6px;
  font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}
.capability-tokens .token { background: #f2f5ff; border-color: #dbe2ff; color: #34479a; }
.effective-tokens .token { background: #eaf2ff; border-color: #cfdcff; color: #1f4ea8; }
.muted-token { color: var(--muted); background: var(--surface-soft); }

.lease-scope-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 11px; }
.lease-footer { display: grid; gap: 4px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.4; }
.lease-reason { color: var(--muted-strong); }
.empty-state { border: 1px dashed var(--line-strong); border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); }
.empty-state p { margin: 5px 0 0; font-size: 12px; }

.create-surface { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.lease-form-grid { padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.actions { justify-content: flex-end; }

.effective-heading { align-items: center; }
.effective-controls { min-width: min(540px, 55%); }
.effective-controls label { white-space: nowrap; }
.effective-controls select { margin-top: 0; min-width: 260px; }
.effective-controls button { flex-shrink: 0; }
.effective-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(260px, .55fr); gap: 12px; }
.effective-card.wide, .effective-snapshot.wide { grid-column: 1 / -1; }
.effective-card h3 { margin-bottom: 8px; }
.effective-description { margin: -2px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.authorization-story { padding: 16px; }
.authorization-flow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.authorization-stage { min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 11px; }
.authorization-stage:last-child { border-color: #cbd8ff; background: #f8faff; }
.authorization-stage-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.authorization-stage-header > div { display: grid; gap: 1px; min-width: 0; }
.authorization-stage-header strong { font-size: 12px; }
.authorization-stage-header span:not(.flow-symbol) { color: var(--muted); font-size: 10px; }
.flow-symbol { display: inline-grid; place-items: center; flex: 0 0 23px; height: 23px; border-radius: 7px; background: var(--primary-soft); color: var(--primary); font-weight: 800; }

.boundary-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.boundary-row:last-child { border-bottom: 0; padding-bottom: 0; }
.limit-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 0; }
.limit-summary-grid > div { border-radius: 8px; background: var(--surface); border: 1px solid var(--line); padding: 9px; }
.limit-summary-grid dt { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.limit-summary-grid dd { margin: 3px 0 0; font-weight: 750; font-size: 15px; }

.effective-lease-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.effective-lease-row { min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 11px; }
.effective-lease-header { justify-content: space-between; align-items: flex-start; margin-bottom: 9px; }
.effective-lease-header strong { overflow-wrap: anywhere; }
.effective-lease-reason { margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.45; }

.effective-snapshot { border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.effective-snapshot summary { cursor: pointer; color: var(--muted-strong); padding: 10px 12px; font-weight: 650; }
.snapshot-hashes { padding: 0 12px 10px; }
.snapshot-hashes p { margin: 5px 0; color: var(--muted); font-size: 11px; word-break: break-all; }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .lease-list, .effective-lease-list { grid-template-columns: 1fr; }
  .authorization-flow { grid-template-columns: 1fr; }
  .effective-grid { grid-template-columns: 1fr; }
  .effective-card.wide, .effective-snapshot.wide { grid-column: 1; }
  .effective-heading { align-items: flex-start; }
  .effective-controls { min-width: 0; width: 100%; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1180px); padding-top: 12px; }
  .panel { padding: 17px; }
  .topbar, .page-heading, .global-strip, .subsection-heading { align-items: flex-start; }
  .page-heading, .global-strip { flex-direction: column; }
  .save-cluster, .lease-heading-actions { width: 100%; justify-content: space-between; }
  .context-bar, .form-grid, .capability-columns, .limits-grid, .lease-scope-grid { grid-template-columns: 1fr; }
  .wide { grid-column: 1; }
  .context-select { grid-template-columns: 1fr; gap: 4px; }
  .capability-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .tabs button { white-space: nowrap; }
  .topbar-actions { gap: 6px; }
  .product-chip { display: none; }
  .effective-controls { display: grid; grid-template-columns: 1fr; }
  .effective-controls select { min-width: 0; }
  .management-popover { right: auto; left: 0; }
}
