:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #14202c;
  --muted: #657282;
  --line: #dce5ee;
  --nav: #101820;
  --blue: #2f66d0;
  --teal: #149783;
  --green: #228653;
  --amber: #bf7417;
  --red: #c4423f;
  --soft: #f7f9fc;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  min-height: 36px;
  border-radius: 7px;
  padding: 0 12px;
  font-weight: 760;
  font-size: 13px;
  color: var(--ink);
  background: #e5ebf3;
  cursor: pointer;
}

button.primary {
  background: var(--blue);
  color: #fff;
}

input, select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--ink);
  padding: 8px 10px;
  outline: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.hidden { display: none !important; }

.login-error {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 750;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(47, 102, 208, .12), rgba(20, 151, 131, .1)),
    radial-gradient(circle at 20% 20%, rgba(20,151,131,.16), transparent 28%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 20px 50px rgba(20, 38, 60, .14);
  display: grid;
  gap: 20px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-row strong, .brand-row span {
  display: block;
}

.brand-row strong {
  font-size: 18px;
  line-height: 1;
}

.brand-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.brand-row.compact strong {
  color: #fff;
  font-size: 17px;
}

.brand-row.compact span {
  color: #aeb9c6;
  font-size: 12px;
}

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

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

.app {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  background: var(--nav);
  color: #f7f9fc;
  padding: 20px 16px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
}

.nav {
  display: grid;
  gap: 6px;
  align-content: start;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #cbd5e0;
}

.nav-item.active {
  background: var(--blue);
  color: #fff;
}

.sidebar-card {
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  background: #172638;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.sidebar-card span, .sidebar-card small {
  color: #aeb9c6;
  font-size: 12px;
  line-height: 1.35;
}

.sidebar-card strong {
  color: #fff;
  font-size: 28px;
}

.main {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filters-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: 0 12px 28px rgba(20,38,60,.06);
}

.filter-main {
  display: grid;
  grid-template-columns: 1.15fr .82fr .48fr .85fr .85fr;
  gap: 10px;
}

.filter-secondary {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) .6fr .7fr;
  gap: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 11px;
  display: grid;
  align-content: center;
  gap: 4px;
}

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

.metric strong {
  font-size: 22px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(600px, 1fr) minmax(340px, .52fr);
  gap: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(20,38,60,.05);
}

.panel-head {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel-head strong {
  font-size: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.list-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.lead-list {
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.lead-row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) 64px 76px minmax(130px, 160px);
  gap: 10px;
  align-items: center;
  border-radius: 0;
  min-height: 74px;
}

.lead-row:hover, .lead-row.active {
  background: #f4f8ff;
}

.lead-row.active {
  box-shadow: inset 4px 0 0 var(--blue);
}

.lead-title strong, .lead-title span {
  display: block;
}

.lead-title strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.lead-title span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.cell-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
  margin-bottom: 3px;
}

.cell-value {
  display: block;
  font-size: 14px;
  font-weight: 820;
  overflow-wrap: anywhere;
}

.tag {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.tag-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag.hot { color: #8a2c25; background: #fdeceb; }
.tag.good { color: #145b36; background: #eaf7f0; }
.tag.warn { color: #744608; background: #fff2d4; }
.tag.neutral { color: #435263; background: #edf2f7; }

.detail-stack {
  min-height: 0;
  display: grid;
  gap: 12px;
  grid-template-rows: auto minmax(160px, 0.42fr);
}

.script-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.detail-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.detail-body {
  padding: 12px 14px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.lead-dossier {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  align-items: start;
}

.photo-box {
  min-height: 170px;
  height: 170px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(135deg, #f0f5f8, #dde7ee);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 780;
  text-align: center;
}

.photo-box img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  object-position: left center;
  display: block;
}

.photo-open {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
  display: block;
}

.photo-open span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 820;
}

.photo-open:hover img,
.photo-open:focus-visible img {
  filter: saturate(1.06) contrast(1.03);
}

.photo-open:focus-visible {
  outline: 3px solid rgba(48, 104, 211, 0.45);
  outline-offset: -3px;
}

.photo-empty {
  width: 100%;
  min-height: 170px;
  height: 170px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef2f6, #f8fafc);
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.detail-title {
  display: grid;
  gap: 4px;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.detail-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.reason-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 10px;
  display: grid;
  gap: 5px;
}

.reason-card strong {
  font-size: 13px;
}

.reason-card p {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
}

.facts-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  align-content: start;
}

.facts-list div {
  min-height: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 0 7px;
  display: grid;
  gap: 2px;
}

.facts-list div:first-child {
  grid-column: 1 / -1;
}

.facts-list span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.facts-list strong {
  font-size: 12px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

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

.detail-actions a, .detail-actions button {
  min-height: 36px;
  border-radius: 7px;
  padding: 8px 10px;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 780;
  color: var(--ink);
  background: #e5ebf3;
}

.detail-actions a.primary-link {
  background: var(--blue);
  color: #fff;
}

.script-inline {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 9px;
  display: grid;
  gap: 6px;
}

.script-inline > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.script-inline strong {
  font-size: 13px;
}

.script-inline span,
.script-inline small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
}

.script-inline p {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.28;
  font-weight: 720;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.script-body {
  padding: 14px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.38;
  overflow: auto;
}

.script-body strong {
  color: var(--ink);
  font-size: 14px;
}

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

.status-buttons button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.photo-viewer.hidden {
  display: none;
}

.photo-viewer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.72);
}

.photo-viewer-card {
  position: relative;
  z-index: 1;
  width: min(1040px, 96vw);
  max-height: 92vh;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.28);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.photo-viewer-head {
  min-height: 52px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.photo-viewer-head strong {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.photo-viewer-head button {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 7px;
}

.photo-viewer-card img {
  width: 100%;
  max-height: calc(92vh - 52px);
  object-fit: contain;
  background: #0f172a;
  display: block;
}

body.photo-viewer-open {
  overflow: hidden;
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .main { overflow: visible; }
  .sidebar { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .lead-list { max-height: 520px; }
}

@media (max-width: 760px) {
  .main { padding: 12px; }
  .topbar, .top-actions { display: grid; }
  .filter-main, .filter-secondary, .metrics, .workspace, .lead-dossier, .detail-actions {
    grid-template-columns: 1fr;
  }
  .detail-stack {
    grid-template-rows: auto auto;
  }
  .visual-stack {
    grid-template-rows: minmax(220px, auto) auto;
  }
  .lead-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    min-height: 0;
    padding: 10px 12px;
  }
  .lead-title, .tag-stack {
    grid-column: 1 / -1;
  }
  .cell-label {
    font-size: 9px;
    margin-bottom: 2px;
  }
  .cell-value {
    font-size: 13px;
  }
}
