:root {
  --bg: #0b0d0f;
  --bg-soft: #121519;
  --card: #0f1216;
  --card-edge: #1b2026;
  --text: #e8edf3;
  --muted: #9aa4b2;
  --accent: #8d9299;
  --accent-2: #7f8a96;
  --danger: #d45757;
  --success: #2bb673;
  --shadow: 0 30px 80px rgba(0,0,0,0.45);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at 15% 10%, #1a1d22, #0b0d0f 40%),
              radial-gradient(circle at 70% 0%, #1a1d22, transparent 50%),
              #0b0d0f;
  color: var(--text);
  min-height: 100vh;
}

body[data-ui-theme="black"] {
  background: #000;
  color: #eaeaea;
}

body[data-ui-theme="black"] .topbar {
  background: rgba(0, 0, 0, 0.82);
  border-bottom-color: #171717;
}

body[data-ui-theme="black"] .card {
  background: #090909;
  border-color: #1f1f1f;
}

body[data-ui-theme="black"] .table-row {
  background: #0d0d0d;
  border-color: #1f1f1f;
}

body[data-ui-theme="black"] .board-row {
  background: #0b0b0b;
  border-color: #1f1f1f;
}

body[data-ui-theme="black"] .board-empty {
  background: #080808;
  border-color: #1f1f1f;
}

body[data-ui-theme="black"] input:not([type="checkbox"]):not([type="radio"]),
body[data-ui-theme="black"] select,
body[data-ui-theme="black"] textarea {
  background: #060606;
  border-color: #202020;
  color: #eaeaea;
}

body[data-ui-theme="black"] .user-pill {
  background: #101010;
}

body[data-ui-theme="gray"] {
  background: #cfcfcf;
  color: #111;
}

body[data-ui-theme="gray"] .topbar {
  background: rgba(207, 207, 207, 0.86);
  border-bottom-color: #111;
}

body[data-ui-theme="gray"] .brand,
body[data-ui-theme="gray"] .hero h1,
body[data-ui-theme="gray"] h2,
body[data-ui-theme="gray"] strong,
body[data-ui-theme="gray"] a {
  color: #111;
}

body[data-ui-theme="gray"] .nav a,
body[data-ui-theme="gray"] .muted,
body[data-ui-theme="gray"] .hero p,
body[data-ui-theme="gray"] label,
body[data-ui-theme="gray"] .user-pill,
body[data-ui-theme="gray"] .secure-link-meta,
body[data-ui-theme="gray"] .agent-create-note {
  color: #222;
}

body[data-ui-theme="gray"] .card {
  background: #d9d9d9;
  border-color: #111;
}

body[data-ui-theme="gray"] .table-row {
  background: #d1d1d1;
  border-color: #111;
}

body[data-ui-theme="gray"] .board-row {
  background: #d1d1d1;
  border-color: #111;
}

body[data-ui-theme="gray"] .board-empty {
  background: #d6d6d6;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .badge,
body[data-ui-theme="gray"] .pill {
  background: #c8c8c8;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] input:not([type="checkbox"]):not([type="radio"]),
body[data-ui-theme="gray"] select,
body[data-ui-theme="gray"] textarea {
  background: #dcdcdc;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] input[type="checkbox"],
body[data-ui-theme="gray"] input[type="radio"] {
  accent-color: #111;
}

body[data-ui-theme="gray"] button,
body[data-ui-theme="gray"] .primary,
body[data-ui-theme="gray"] .ghost {
  background: #111;
  color: #fff;
  border-color: #111;
}

body[data-ui-theme="gray"] .danger {
  background: #511;
  color: #fff;
  border-color: #511;
}

body[data-ui-theme="gray"] .alert {
  background: #d3d3d3;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .alert.success {
  background: #b8d2bf;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .alert.info {
  background: #cfd3d8;
  border-color: #111;
  color: #111;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 40px;
  border-bottom: 1px solid #14181d;
  position: sticky;
  top: 0;
  backdrop-filter: blur(14px);
  background: rgba(11,13,15,0.75);
  z-index: 10;
}

.brand {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 20px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  margin: 0;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 999px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav a:hover { color: var(--text); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  background: #141920;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.user-menu {
  position: relative;
}

.user-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  padding: 0;
  font-size: 16px;
  border: 1px solid #2a3038;
  background: #141920;
  color: #d0d4db;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 260px;
  z-index: 30;
}

.user-menu-panel .user-pill {
  border-radius: 12px;
  border: 1px solid #2a3038;
  display: block;
  padding: 10px 12px;
}

.page {
  padding: 32px 40px 80px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin: 40px 0 24px;
}

.hero h1 {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 42px;
  letter-spacing: 0.02em;
  margin: 0 0 12px;
  color: #d6dde7;
}

.hero p { color: var(--muted); max-width: 560px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0 0 6px;
  color: #d6dde7;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.session-status-grid {
  margin-bottom: 16px;
  gap: 18px;
}

.session-status-item {
  display: grid;
  gap: 10px;
  align-content: start;
}

.session-status-item .label {
  font-size: 15px;
  line-height: 1.25;
}

.session-status-pill-wrap {
  min-height: 34px;
  display: flex;
  align-items: center;
}

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

input:not([type="checkbox"]):not([type="radio"]), select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #20252c;
  background: #0c0f13;
  color: var(--text);
}

select {
  -webkit-appearance: none !important;
  appearance: none !important;
  padding-right: 34px;
  background-color: #0c0f13;
  background-image:
    linear-gradient(45deg, transparent 50%, #7f8791 50%),
    linear-gradient(135deg, #7f8791 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select::-ms-expand { display: none; }

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  accent-color: #8d9299;
}

textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #20252c;
  background: #0c0f13;
  color: var(--text);
  resize: vertical;
}

.check-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.magic-theme-select {
  width: auto;
  min-width: 120px;
}

button, .primary, .ghost {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  white-space: normal;
  text-align: center;
}

button {
  background: linear-gradient(120deg, #8a8f96, #a0a5ac);
  color: #111317;
  border: 1px solid #7a7f87;
}

.primary {
  background: linear-gradient(120deg, #8a8f96, #a0a5ac);
  color: #111317;
  border: 1px solid #7a7f87;
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid #2a3038;
}

.danger {
  background: rgba(212, 87, 87, 0.18);
  color: #ffd5d5;
  border: 1px solid rgba(212, 87, 87, 0.55);
}

.danger:hover {
  background: rgba(212, 87, 87, 0.26);
}

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

.table {
  display: grid;
  gap: 10px;
}

.table-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  align-items: center;
  background: #10141a;
  border: 1px solid #1b2026;
  padding: 12px;
  border-radius: 12px;
}

.table-row > * {
  min-width: 0;
}

.badges { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  padding: 4px 8px;
  background: #1a2028;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid #2a3038;
}

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: #1c2430;
  color: #d7dbe2;
  font-size: 12px;
  border: 1px solid #2a3038;
}

.status-token {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.status-ok {
  background: rgba(43, 182, 115, 0.14);
  color: #9de9c2;
  border-color: rgba(43, 182, 115, 0.45);
}

.status-active {
  background: rgba(132, 144, 161, 0.16);
  color: #d8dee8;
  border-color: rgba(132, 144, 161, 0.46);
}

.status-pending {
  background: rgba(255, 193, 7, 0.12);
  color: #ffde8a;
  border-color: rgba(255, 193, 7, 0.4);
}

.status-draft {
  background: rgba(148, 163, 184, 0.15);
  color: #d6dce5;
  border-color: rgba(148, 163, 184, 0.4);
}

.status-failed,
.status-cancelled,
.status-expired {
  background: rgba(212, 87, 87, 0.15);
  color: #ffb8b8;
  border-color: rgba(212, 87, 87, 0.45);
}

.status-not-enabled {
  background: rgba(123, 141, 169, 0.14);
  color: #c3cfdf;
  border-color: rgba(123, 141, 169, 0.4);
}

.status-timeout {
  background: rgba(255, 146, 76, 0.14);
  color: #ffcda6;
  border-color: rgba(255, 146, 76, 0.45);
}

.status-neutral {
  background: rgba(117, 130, 153, 0.14);
  color: #d1dae7;
  border-color: rgba(117, 130, 153, 0.4);
}

.copy {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.copy input {
  flex: 1;
  min-width: 0;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  margin-right: 8px;
}

.board-card h2 {
  margin-bottom: 4px;
}

.board-list {
  margin-top: 10px;
}

.board-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #1e2530;
  background: linear-gradient(180deg, #10141a 0%, #0d1218 100%);
}

.board-dot {
  width: 10px;
  height: 10px;
  margin-right: 0;
  box-shadow: 0 0 0 4px rgba(14, 165, 165, 0.12);
}

.board-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

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

.board-title {
  font-size: 17px;
  line-height: 1.1;
}

.board-id {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-open {
  min-width: 88px;
}

.board-empty {
  border: 1px dashed #293141;
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  background: #0e131a;
}

.upload {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: center;
}

.alert {
  background: #2a1a1a;
  border: 1px solid #4a2a2a;
  color: #f0b7b7;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.alert.success {
  background: #12301f;
  border-color: #1c4a2f;
  color: #a3f0c1;
}

.alert.info {
  background: #171b22;
  border-color: #2a3038;
  color: #b5bfce;
}

.auth {
  display: grid;
  place-items: center;
  min-height: 80vh;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  padding: 30px;
  border-radius: var(--radius);
  border: 1px solid var(--card-edge);
  box-shadow: var(--shadow);
}

.auth-card form .primary {
  margin-top: 10px;
}

.auth-links {
  margin-top: 10px;
  font-size: 13px;
}

.auth-links a {
  color: var(--muted);
  text-decoration: none;
}

.auth-links a:hover {
  color: var(--text);
}

.auth-help {
  margin-bottom: 14px;
}

.muted { color: var(--muted); }

.helper-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.info-hint {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid #4e5560;
  color: #c2c8d2;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: help;
  user-select: none;
}

.info-hint-text {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 260px;
  max-width: min(360px, calc(100vw - 64px));
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #30363f;
  background: #0d1218;
  color: #d7dce3;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 25;
}

.info-hint:hover .info-hint-text,
.info-hint:focus .info-hint-text,
.info-hint:focus-within .info-hint-text {
  opacity: 1;
}

body[data-ui-theme="gray"] .info-hint {
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .info-hint-text {
  background: #e1e1e1;
  border-color: #111;
  color: #111;
}

@media (max-width: 760px) {
  .info-hint-text {
    left: auto;
    right: 0;
    min-width: 220px;
  }
}

.actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

.agent-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(240px, 1fr) minmax(170px, auto) minmax(170px, auto) auto;
  gap: 14px;
  align-items: end;
  margin-top: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.agent-create-note {
  color: var(--muted);
  font-size: 13px;
  padding-bottom: 10px;
}

.agent-create-form .actions {
  justify-content: flex-start;
}

.team-row {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: start;
}

.team-user {
  display: grid;
  gap: 8px;
}

.role-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 10px;
  background: #151b24;
  border: 1px solid #313a48;
  color: #cfd5de;
  font-size: 12px;
  font-weight: 600;
}

.agent-metrics {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.team-row .check {
  white-space: normal;
  align-self: center;
}

.team-row button {
  min-width: 120px;
}

.team-row input,
.team-row select {
  min-width: 0;
}

.session-guide {
  margin-bottom: 14px;
}

.session-guide p {
  margin: 0;
}

.session-next-step {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.section-title-with-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.session-inline-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 6px 0 12px;
}

.sessions-row {
  grid-template-columns: minmax(280px, 2fr) minmax(120px, auto) minmax(150px, auto) minmax(220px, auto);
  align-items: center;
}

.session-owner {
  justify-self: center;
}

.session-row-actions {
  justify-self: end;
}

.signature-approval-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.approval-center {
  justify-content: center;
}

.evidence-card .primary {
  margin-top: 20px;
}

.audit-card .primary {
  margin-top: 20px;
}

.session-actions-row {
  width: 100%;
  justify-content: flex-end;
  gap: 10px;
}

.session-actions-card {
  padding-top: 14px;
  padding-bottom: 14px;
}

.session-actions-card h2 {
  margin-bottom: 2px;
}

.identity-card .inline {
  margin-bottom: 12px;
}

.identity-card .ghost,
.identity-card .primary,
.identity-card .copy .primary {
  min-width: 140px;
}

.identity-card .copy {
  gap: 14px;
}

.identity-card .copy input {
  min-height: 42px;
}

.secure-link-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.approve-btn {
  font-weight: 600;
}

.agency-signer-toggle {
  font-weight: 600;
}

.agency-signer-fields {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.terms-editor-form {
  display: grid;
  gap: 12px;
}

.terms-editor-input {
  min-height: 460px;
  line-height: 1.55;
}

.terms-preview {
  white-space: normal;
  line-height: 1.6;
  border: 1px solid #232a34;
  border-radius: 12px;
  padding: 14px;
  background: #0d1117;
  max-height: 560px;
  overflow: auto;
}

body[data-ui-theme="gray"] .terms-preview {
  background: #d2d2d2;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .user-icon-btn {
  background: #d2d2d2;
  border-color: #111;
  color: #111;
}

body[data-ui-theme="gray"] .user-menu-panel .user-pill {
  background: #d2d2d2;
  border-color: #111;
  color: #111;
}

body.modal-open {
  overflow: hidden;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(6, 10, 16, 0.74);
  backdrop-filter: blur(3px);
  z-index: 1400;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  width: min(940px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

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

.modal-head h2 {
  margin: 0;
}

.modal-close-btn {
  min-width: 92px;
}

.create-session-form {
  margin-top: 10px;
}

.create-session-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.35;
}

.create-session-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px 18px;
  align-items: start;
}

.create-session-field {
  min-width: 0;
}

.create-session-span-2 {
  grid-column: 1 / -1;
}

.create-session-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 8px 12px;
}

.create-session-form .check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  line-height: 1.35;
}

.create-session-form .helper-line {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
}

.create-session-forbidden-warning {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.create-session-form .actions {
  justify-content: flex-end;
  margin-top: 14px;
}

@media (max-width: 1200px) {
  .agent-create-form { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
  .team-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

@media (max-width: 840px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .hero { flex-direction: column; align-items: flex-start; }
  .grid-3 { grid-template-columns: 1fr; }
  .upload { grid-template-columns: 1fr; }
  .agency-signer-fields { grid-template-columns: 1fr; }
  .agent-create-form { grid-template-columns: 1fr; }
  .team-row { grid-template-columns: 1fr; }
  .team-row button { width: 100%; min-width: 0; }
  .board-row { grid-template-columns: auto 1fr; }
  .board-open { grid-column: 2; justify-self: start; }
  .copy { flex-direction: column; align-items: stretch; }
  .copy button,
  .copy a,
  .doc-actions button,
  .doc-actions a,
  .actions button,
  .actions a { width: 100%; }
  .inline { width: 100%; }
  .inline button,
  .inline a { width: 100%; }
  .create-session-grid { grid-template-columns: 1fr; }
  .create-session-steps { grid-template-columns: 1fr; }
  .sessions-row {
    grid-template-columns: 1fr;
  }
  .session-owner,
  .session-row-actions {
    justify-self: start;
  }
}
