:root {
  --navy: #0e0a26;
  --ink: #111827;
  --muted: #6b7280;
  --soft: #f4f5f9;
  --surface: #ffffff;
  --line: #e5e7eb;
  --blue: #4f6ef7;
  --blue-soft: #eef1fe;
  --green: #10b981;
  --green-soft: #d1fae5;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --red: #ef4444;
  --red-soft: #fee2e2;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08), 0 12px 30px rgb(15 23 42 / 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--soft);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.topbar {
  height: 64px;
  padding: 0 28px;
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand,
.top-actions,
.head-actions,
.toolbar,
.panel-head,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fff;
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
  line-height: 1;
}

.brand-subtitle {
  color: rgb(255 255 255 / 0.58);
  font-size: 12px;
}

.top-actions,
.head-actions {
  gap: 10px;
}

.user-pill {
  font-size: 12px;
  color: rgb(255 255 255 / 0.72);
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 999px;
  padding: 6px 10px;
}

main {
  max-width: 1380px;
  margin: 0 auto;
  padding: 28px;
}

.login-view {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.login-panel,
.panel,
.stat-card,
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(100%, 380px);
  padding: 28px;
  display: grid;
  gap: 16px;
}

.login-title {
  font-size: 22px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  outline: none;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
}

.primary-button,
.secondary-button,
.quiet-button,
.icon-button {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
}

.primary-button {
  background: var(--navy);
  color: white;
  padding: 0 16px;
  font-weight: 800;
}

.secondary-button {
  background: var(--blue-soft);
  color: #27378f;
  padding: 0 14px;
  font-weight: 800;
}

.quiet-button {
  background: rgb(255 255 255 / 0.1);
  color: inherit;
  border: 1px solid rgb(255 255 255 / 0.16);
  padding: 0 14px;
  font-weight: 700;
}

.app-view .quiet-button,
.modal .quiet-button {
  color: var(--muted);
  background: #f3f4f6;
  border-color: var(--line);
}

.icon-button {
  width: 38px;
  background: rgb(255 255 255 / 0.1);
  color: inherit;
  border: 1px solid rgb(255 255 255 / 0.16);
  font-weight: 900;
}

.modal .icon-button {
  background: #f3f4f6;
  color: var(--muted);
  border-color: var(--line);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.page-head p {
  margin-top: 4px;
  color: var(--muted);
}

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

.stat-card {
  padding: 18px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: 32px;
  line-height: 1;
}

.stat-card.warning strong {
  color: var(--amber);
}

.stat-card.success strong {
  color: var(--green);
}

.toolbar {
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar input {
  flex: 1;
}

.toolbar select {
  width: 190px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  align-items: start;
}

.panel {
  overflow: hidden;
}

.panel-head {
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

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

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  font-size: 14px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #f7f8ff;
}

.subtext {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.badge.active,
.badge.closed_won {
  background: var(--green-soft);
  color: #047857;
}

.badge.conflict {
  background: var(--amber-soft);
  color: #92400e;
}

.badge.pending_crm,
.badge.paused {
  background: #f3f4f6;
  color: var(--muted);
}

.badge.closed_lost {
  background: var(--red-soft);
  color: #991b1b;
}

.empty-state,
.detail-empty {
  color: var(--muted);
  padding: 32px 18px;
  text-align: center;
}

.detail-panel {
  position: sticky;
  top: 82px;
}

#detailContent {
  padding: 18px;
}

.detail-title {
  font-size: 18px;
  font-weight: 900;
}

.detail-meta {
  color: var(--muted);
  margin-top: 4px;
  font-size: 13px;
}

.alert-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #78350f;
  font-size: 13px;
  font-weight: 700;
}

.timeline {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.timeline-item {
  border-left: 3px solid var(--blue);
  padding-left: 12px;
}

.timeline-title {
  font-weight: 800;
  font-size: 13px;
}

.timeline-body,
.timeline-date {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.admin-panel {
  margin-top: 16px;
}

.cards-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.rep-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.rep-actions {
  display: flex;
  gap: 8px;
}

.rep-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  background: #f9fafb;
  border-radius: 6px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(14 10 38 / 0.55);
  display: grid;
  place-items: start center;
  padding: 34px 18px;
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(100%, 740px);
  padding: 22px;
}

.modal-card.compact {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
}

.modal-head {
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.span-2 {
  grid-column: span 2;
}

.modal-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  background: var(--navy);
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: 0.18s ease;
}

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

@media (max-width: 940px) {
  main {
    padding: 18px;
  }

  .page-head,
  .content-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .detail-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 0 16px;
  }

  .brand-subtitle,
  .user-pill {
    display: none;
  }

  .stats-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .toolbar {
    display: grid;
  }

  .toolbar select {
    width: 100%;
  }
}
