:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #16201b;
  --muted: #64706a;
  --line: #d8dfda;
  --brand: #116149;
  --brand-2: #0f8060;
  --accent: #c88a2d;
  --danger: #b33b35;
  --warn: #b97616;
  --ok: #28764b;
  --shadow: 0 16px 42px rgba(28, 42, 34, 0.11);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body.auth-locked .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

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

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--brand-2);
}

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

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 244, 0.92);
  padding: 18px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

.auth-card p {
  color: var(--muted);
  margin-bottom: 18px;
}

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

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 650;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width, 280px) 8px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #fbfcfb;
  border-right: 1px solid var(--line);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.brand span,
.eyebrow,
.metric span,
.side-block label,
.panel-header p,
.empty-state p,
.form-panel p,
.today-box span,
#list-summary {
  color: var(--muted);
}

.nav-stack,
.side-actions,
.button-row {
  display: grid;
  gap: 8px;
}

.nav-button {
  text-align: left;
}

.nav-button.active {
  background: var(--surface-2);
  border-color: var(--brand-2);
  color: var(--brand);
  font-weight: 700;
}

.side-block {
  display: grid;
  gap: 7px;
}

label {
  display: grid;
  gap: 7px;
  color: #2b3932;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.workspace {
  padding: 26px;
  min-width: 0;
}

.resize-handle {
  background: transparent;
  position: relative;
  z-index: 3;
  touch-action: none;
  user-select: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(17, 97, 73, 0.18);
  transition: background 0.15s ease;
}

.resize-handle:hover::after,
body.resizing .resize-handle::after {
  background: rgba(17, 97, 73, 0.52);
}

.sidebar-resizer,
.panel-resizer {
  cursor: col-resize;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

.today-box {
  min-width: 142px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.today-box strong {
  display: block;
  font-size: 28px;
  margin-top: 2px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric,
.lead-list-panel,
.detail-panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric:has(#metric-quoted) {
  cursor: pointer;
}

.metric:has(#metric-quoted):hover {
  border-color: var(--brand-2);
}

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 6px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(560px, var(--list-width, 64%)) 14px minmax(380px, 1fr);
  gap: 6px;
  align-items: start;
}

.panel-resizer {
  align-self: stretch;
  min-height: calc(100vh - 170px);
  border-radius: 8px;
}

.panel-resizer:hover {
  background: rgba(17, 97, 73, 0.06);
}

.lead-list-panel,
.detail-panel,
.form-panel {
  padding: 16px;
}

.detail-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-header p {
  margin-bottom: 0;
}

.table-wrap {
  max-height: calc(100vh - 290px);
  min-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 9px;
  text-align: left;
  vertical-align: top;
}

.demand-cell,
.demand-text {
  white-space: pre-line;
}

.demand-cell {
  width: 24%;
  outline: none;
  border-radius: 6px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.demand-cell:focus {
  background: #fffdf3;
  box-shadow: inset 0 0 0 1px #d4a94f;
}

th {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  width: 26%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 96px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 25%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 86px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 92px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 118px;
}

.status-cell,
.quote-cell,
.follow-cell {
  white-space: nowrap;
}

.follow-cell {
  width: 118px;
}

tr.lead-row {
  cursor: pointer;
}

tr.lead-row:hover,
tr.lead-row.selected {
  background: #f0f5f1;
}

.company-cell strong {
  display: block;
}

.company-cell span,
.subtle {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #e8eee9;
  color: #2e4439;
  white-space: nowrap;
}

.tag.new {
  background: #e3f1ed;
  color: var(--brand);
}

.tag.warn {
  background: #fff1da;
  color: var(--warn);
}

.tag.danger {
  background: #fde8e6;
  color: var(--danger);
}

.tag.ok {
  background: #e5f2e9;
  color: var(--ok);
}

.quoted-cell {
  color: var(--brand);
  font-weight: 800;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-content: center;
  text-align: center;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.detail-title h2 {
  font-size: 22px;
  margin-bottom: 3px;
}

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

.quote-banner {
  border: 1px solid var(--line);
  background: #f7faf7;
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0;
}

.quote-banner.has-quote {
  border-color: #e1b464;
  background: #fff7e8;
}

.quote-banner span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.quote-banner strong {
  display: block;
  color: var(--brand);
  font-size: 26px;
  line-height: 1.15;
  margin-bottom: 4px;
}

.field-box {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 10px;
}

.field-box.wide-field {
  grid-column: 1 / -1;
  min-height: 96px;
}

.field-box.wide-field strong {
  font-size: 18px;
}

.field-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.field-box strong {
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.editable-detail {
  outline: none;
  border-radius: 5px;
  cursor: text;
}

.editable-detail:focus {
  background: #fffdf3;
  box-shadow: inset 0 0 0 1px #d4a94f;
}

.editable-box {
  cursor: text;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 13px;
  margin-top: 13px;
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  border-left: 3px solid var(--brand-2);
  background: #f7faf7;
  padding: 9px 10px;
}

.history-list time {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.quick-log {
  display: grid;
  gap: 9px;
}

.file-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fbfcfb;
  border-radius: 6px;
  padding: 10px;
}

.file-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

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

.file-actions a {
  color: var(--brand);
  font-weight: 700;
  text-decoration: none;
}

.file-upload {
  border: 1px dashed var(--brand-2);
  border-radius: 6px;
  padding: 10px;
  background: #f4faf7;
}

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

form,
.import-layout,
.backup-grid {
  display: grid;
  gap: 14px;
}

.import-layout {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
}

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

.button-row {
  grid-template-columns: repeat(2, max-content);
  margin-top: 10px;
}

.danger-button {
  color: var(--danger);
  border-color: #efc4c0;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #10231b;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 5;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .resize-handle {
    display: none;
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content-grid,
  .import-layout,
  .backup-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .detail-title {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .form-row,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }
}
