:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171b22;
  background: #f4f6f8;
  font-synthesis: none;
  --canvas: #f4f6f8;
  --panel: #ffffff;
  --ink: #171b22;
  --muted: #6f7782;
  --green: #13795f;
  --lime: #c8ff4d;
  --line: #e8ebef;
  --danger: #c94a40;
  --rail-width: 82px;
  --rail-open: 248px;
  --shadow: 0 24px 70px rgb(34 43 56 / 8%);
}

* { box-sizing: border-box; }

html, body, #app { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--green) 45%, white);
  outline-offset: 3px;
}

.app-root, .app-shell { min-height: 100vh; }
.boot-message { margin: 48px; color: var(--muted); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(circle at 18% 15%, rgb(200 255 77 / 24%), transparent 32%),
    var(--canvas);
}

.login-panel {
  width: min(100%, 430px);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgb(20 32 51 / 10%);
}

.login-form { display: grid; gap: 12px; }
.login-heading { margin-bottom: 20px; }
.login-heading h1, .page-header h1 { margin: 8px 0; letter-spacing: -0.035em; }
.login-heading h1 { font-size: 34px; }
.login-heading p, .page-header p { color: var(--muted); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: var(--lime);
  color: var(--ink);
  font-weight: 850;
  letter-spacing: -0.08em;
}

.eyebrow {
  margin: 0;
  color: var(--green) !important;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.field-label { margin-top: 4px; font-size: 14px; font-weight: 650; }
.field-input {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1px solid #cdd4df;
  border-radius: 11px;
  color: var(--ink);
  background: white;
}
.field-input:focus { border-color: var(--green); }

.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
}
.button:disabled { cursor: wait; opacity: .62; }
.button-primary { background: var(--ink); color: white; }
.button-primary:hover { background: #2b3038; }
.button-secondary { border-color: var(--line); background: white; color: var(--ink); }
.button-danger { background: var(--danger); color: white; }
.button-quiet-danger { border-color: #f3c7c2; background: white; color: var(--danger); }
.login-submit { margin-top: 8px; }
.login-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 14px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr); gap: 24px; padding: 20px; }
.rail {
  position: sticky;
  z-index: 10;
  top: 20px;
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: calc(100vh - 40px);
  padding: 16px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgb(255 255 255 / 96%);
  box-shadow: var(--shadow);
  transition: width 180ms ease, box-shadow 180ms ease;
}

@media (hover: hover) and (min-width: 769px) {
  .rail:hover, .rail:focus-within {
    width: var(--rail-open);
    box-shadow: 0 26px 70px rgb(34 43 56 / 16%);
  }
}

.logo-slot, .rail-link, .rail-action, .profile {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}
.logo-slot { padding: 0 5px; }
.logo-slot .brand-mark { width: 48px; height: 48px; flex: 0 0 48px; }
.brand-name { font-weight: 800; }
.rail-nav { display: grid; gap: 8px; }
.rail-link, .rail-action {
  width: 100%;
  padding: 0 17px;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}
.rail-link:hover, .rail-action:hover { background: #f0f3f7; color: var(--ink); }
.rail-link.is-active { background: var(--ink); color: white; box-shadow: 0 10px 24px rgb(23 27 34 / 16%); }
.icon { width: 22px; height: 22px; flex: 0 0 22px; }
.rail-label { opacity: 0; transition: opacity 100ms ease; }
.rail:hover .rail-label, .rail:focus-within .rail-label { opacity: 1; }
.rail-footer { margin-top: auto; display: grid; gap: 8px; }
.profile { padding: 4px 5px; }
.avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e9f3ef;
  color: var(--green);
  font-weight: 800;
}
.profile-copy { display: grid; min-width: 0; }
.profile-copy strong { overflow: hidden; text-overflow: ellipsis; }
.profile-copy small { color: var(--muted); }

.workspace { min-width: 0; }
.workspace-topbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.workspace-brandline { display: flex; align-items: center; gap: 12px; min-width: 0; color: var(--muted); font-size: 14px; font-weight: 650; }
.workspace-brandline strong { color: var(--ink); font-size: 16px; font-weight: 820; white-space: nowrap; }
.workspace-dot { width: 6px; height: 6px; flex: 0 0 6px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 5px rgb(200 255 77 / 25%); }
.workspace-crumb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-user { min-height: 38px; display: inline-flex; align-items: center; gap: 9px; padding: 0 14px 0 7px; border: 1px solid var(--line); border-radius: 999px; background: rgb(255 255 255 / 82%); box-shadow: 0 8px 26px rgb(34 43 56 / 4%); font-size: 13px; font-weight: 720; white-space: nowrap; }
.workspace-user-mark { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: #dff4eb; color: var(--green); font-weight: 850; }
.route-slot { min-height: calc(100vh - 116px); padding: 0 0 32px; }
.platform-page { width: min(100%, 1260px); margin: 0 auto; }
.module-list { display: grid; gap: 12px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: clamp(32px, 3.5vw, 42px); }
.page-header p { max-width: 680px; line-height: 1.6; }

.source-list { display: grid; gap: 12px; }
.source-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 112px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.source-card h2 { margin: 0 0 6px; font-size: 18px; }
.source-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.source-key { margin-top: 7px !important; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.status-chip {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: #f0f3f7;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.stale-notice {
  margin: 0 0 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #fff8e6;
  color: #7a5300;
}

.crm-page { width: min(100%, 1260px); margin: 0 auto; }
.crm-page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.crm-header-actions, .crm-row-actions, .crm-form-actions, .crm-relation-controls {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
}
.crm-kpis { display: flex; min-height: 68px; margin-bottom: 16px; padding: 9px 12px; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: white; box-shadow: 0 8px 26px rgb(34 43 56 / 4%); }
.crm-kpi { min-width: 150px; display: grid; align-content: center; gap: 2px; padding: 0 14px; border-right: 1px solid var(--line); }
.crm-kpi:last-child { border-right: 0; }
.crm-kpi span, .crm-kpi small { color: var(--muted); font-size: 11px; font-weight: 750; }
.crm-kpi strong { font-size: 18px; font-weight: 920; }
.crm-tabs { display: inline-flex; gap: 6px; margin-bottom: 18px; padding: 5px; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 10px 28px rgb(34 43 56 / 5%); }
.crm-tab { padding: 10px 15px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 750; cursor: pointer; }
.crm-tab.is-active { background: var(--ink); color: white; }
.crm-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 200px auto; align-items: end; gap: 12px; margin-bottom: 20px; }
.crm-field { display: grid; gap: 7px; color: var(--ink); font-size: 14px; font-weight: 650; }
.crm-entity-list, .crm-relation-list { display: grid; gap: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); box-shadow: var(--shadow); }
.crm-entity-row, .crm-relation-row, .crm-metadata, .crm-form, .crm-relations {
  border: 1px solid var(--line); border-radius: 22px; background: var(--panel);
}
.crm-entity-row, .crm-relation-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 20px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.crm-entity-row:last-child, .crm-relation-row:last-child { border-bottom: 0; }
.crm-entity-row:hover, .crm-relation-row:hover { background: #f8fbff; }
.crm-entity-row h2, .crm-relation-row strong { margin: 0; font-size: 18px; }
.crm-entity-row p, .crm-section-heading p { margin: 6px 0 0; color: var(--muted); }
.crm-pagination { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.crm-metadata { display: grid; grid-template-columns: minmax(130px, 180px) 1fr; margin: 0 0 20px; padding: 22px; }
.crm-metadata dt, .crm-metadata dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); }
.crm-metadata dt { color: var(--muted); }
.crm-form { display: grid; gap: 16px; max-width: 720px; padding: 28px; box-shadow: var(--shadow); }
.crm-form-message:empty { display: none; }
.crm-notice { margin-bottom: 18px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.crm-notice p { margin: 5px 0 0; color: var(--muted); }
.crm-notice-error { border-color: #f3c7c2; background: #fff7f6; }
.crm-notice-conflict { border-color: #f0d18a; background: #fff9e9; }
.crm-notice .button { margin-top: 12px; }
.crm-relations { padding: 24px; box-shadow: var(--shadow); }
.crm-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.crm-section-heading h2 { margin: 0; }
.crm-relation-copy { display: grid; gap: 6px; min-width: 0; }
.crm-relation-copy code { overflow-wrap: anywhere; color: var(--muted); }
.crm-relation-controls .field-input { width: auto; min-height: 44px; }
.crm-check { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.status-active { background: #e9f3ef; color: var(--green); }
.status-archived { background: #f0f3f7; color: var(--muted); }
.status-tombstone { background: #fff0ee; color: var(--danger); }

.state-view {
  min-height: 320px;
  display: grid;
  align-content: center;
  justify-items: start;
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.state-view h2 { margin: 16px 0 8px; font-size: 22px; }
.state-view p { max-width: 540px; margin: 0 0 20px; color: var(--muted); line-height: 1.6; }
.state-loading { justify-items: center; gap: 16px; }
.empty-mark { width: 44px; height: 7px; border-radius: 999px; background: var(--lime); }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #dfe6ec;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.error-code { font: 12px ui-monospace, monospace; }
.confirm-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 24px; background: rgb(15 31 56 / 35%); }
.confirm-dialog { width: min(720px, 94vw); padding: 28px; border-radius: 22px; background: white; box-shadow: 0 22px 60px rgb(0 0 0 / 25%); }
.confirm-dialog h2 { margin: 0 0 8px; font-size: 24px; }
.confirm-dialog p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 768px) {
  :root { --rail-width: 72px; }
  .app-shell { gap: 16px; padding: 16px; }
  .rail { top: 16px; height: calc(100vh - 32px); }
  .rail { padding-inline: 10px; }
  .rail-label { display: none; }
  .route-slot { padding: 0 0 24px; }
  .page-header { margin-bottom: 24px; }
  .crm-page-header, .crm-entity-row, .crm-relation-row, .crm-section-heading { align-items: stretch; flex-direction: column; }
  .crm-toolbar { grid-template-columns: 1fr; }
  .crm-header-actions, .crm-row-actions, .crm-relation-controls { width: 100%; }
  .crm-relation-controls .field-input { width: 100%; }
}

@media (max-width: 480px) {
  .app-shell { display: block; padding: 10px 10px 84px; }
  .rail { position: fixed; inset: auto 10px 10px; top: auto; width: auto; height: 64px; flex-direction: row; align-items: center; gap: 6px; padding: 7px 9px; border-radius: 20px; }
  .logo-slot, .profile, .rail-action .rail-label { display: none; }
  .rail-nav { display: flex; flex: 1; justify-content: center; gap: 6px; }
  .rail-link, .rail-action { width: 48px; min-height: 48px; justify-content: center; padding: 0; }
  .rail-footer { margin: 0; display: block; }
  .workspace-topbar { align-items: flex-start; flex-direction: column; }
  .workspace-user { max-width: 100%; }
  .route-slot { padding: 0 0 20px; }
  .page-header h1 { font-size: 32px; }
  .source-card { align-items: flex-start; flex-direction: column; gap: 14px; padding: 20px; }
  .state-view { min-height: 280px; padding: 24px; }
  .crm-header-actions .button, .crm-row-actions .button, .crm-form-actions .button, .crm-relation-controls .button { width: 100%; }
  .crm-metadata { grid-template-columns: 1fr; }
  .crm-metadata dt { padding-bottom: 2px; border-bottom: 0; }
  .crm-metadata dd { padding-top: 2px; }
  .crm-form, .crm-relations { padding: 18px; }
  .crm-kpis { scroll-snap-type: x mandatory; }
  .crm-kpi { min-width: 132px; scroll-snap-align: start; }
  .confirm-backdrop { padding: 14px; }
  .confirm-dialog { padding: 22px; }
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions .button { width: 100%; }
  .login-page { padding: 16px; }
  .login-panel { padding: 28px 22px; border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
