:root {
  --bg: #f4f7f8;
  --panel: #ffffff;
  --panel-2: #f9fbfb;
  --ink: #11191a;
  --muted: #607174;
  --line: #d7dee0;
  --line-strong: #8aa8ad;
  --brand: #003a3d;
  --brand-2: #007980;
  --brand-3: #b4ccd0;
  --fresh: #0f9f8f;
  --fresh-soft: #e7f5f3;
  --blue: #005e9c;
  --blue-soft: #e7f1fb;
  --amber: #b35a00;
  --amber-soft: #fff1dc;
  --red: #b3261e;
  --red-soft: #ffe7e4;
  --shadow: 0 16px 32px rgba(17, 25, 26, .08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(0, 58, 61, .05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 58, 61, .045) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-logo,
.brand-mark {
  width: 48px;
  height: 48px;
  display: block;
  border-radius: var(--radius);
  background: #fff;
  object-fit: contain;
  padding: 5px;
  box-shadow: 0 8px 18px rgba(0, 58, 61, .13);
}

.brand-mark {
  width: 54px;
  height: 54px;
}

.login h1 {
  margin: 16px 0 4px;
  font-size: 30px;
  letter-spacing: 0;
}

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

.login-form {
  margin-top: 20px;
  display: grid;
  gap: 10px;
}

.field,
.field-row {
  display: grid;
  gap: 6px;
}

.field-row {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

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

textarea {
  min-height: 88px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(0, 144, 150, .14);
}

.btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  text-decoration: none;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.btn:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

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

.btn.wa {
  background: #1fd064;
  border-color: #1fd064;
  color: #082915;
}

.btn.subtle {
  background: var(--panel-2);
  color: var(--muted);
}

.btn.danger {
  background: var(--red-soft);
  border-color: #ffb4ae;
  color: var(--red);
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px 1fr;
}

.sidebar {
  background: #062f32;
  color: #c7d5d2;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 20px;
  min-height: 54px;
}

.brand-title {
  color: #fff;
  font-weight: 900;
}

.brand-sub {
  font-size: 12px;
  color: #8aa19d;
}

.nav-label {
  padding: 10px 8px 6px;
  color: #748b87;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.nav-item {
  border: 1px solid transparent;
  width: 100%;
  background: transparent;
  color: #c7d5d2;
  border-radius: var(--radius);
  padding: 10px 10px;
  text-align: left;
  font-weight: 800;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .12);
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: #8aa19d;
  font-size: 12px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.top-tabs {
  grid-column: 1 / -1;
  display: none;
  gap: 6px;
  overflow-x: auto;
}

.top-tabs .nav-item {
  width: auto;
  min-width: 92px;
  text-align: center;
  color: var(--ink);
  background: var(--panel-2);
  border-color: var(--line);
}

.top-tabs .nav-item.active {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

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

.content {
  padding: 18px 20px 28px;
}

.install-hint {
  margin: 14px 20px 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #edf7f6;
  border: 1px solid #b8dbd8;
  border-radius: var(--radius);
  color: var(--ink);
}

.install-hint strong,
.install-hint span {
  display: block;
}

.install-hint span {
  margin-top: 2px;
  color: var(--muted);
  font-weight: 700;
}

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

.notification-control {
  margin: 10px 20px 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgba(17, 25, 26, .04);
}

.notification-control.enabled {
  border-left-color: var(--fresh);
}

.notification-control.blocked {
  border-left-color: var(--red);
}

.notification-control strong,
.notification-control span {
  display: block;
}

.notification-control span {
  margin-top: 2px;
  color: var(--muted);
  font-weight: 700;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  box-shadow: 0 10px 18px rgba(17, 25, 26, .04);
}

.metric strong {
  display: block;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: 0;
}

.metric span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.view-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

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

.view-head h2,
.view-head p {
  margin: 0;
}

.view-head h2 {
  font-size: 17px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.segmented button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 900;
  padding: 6px 9px;
}

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

.lead-table {
  display: grid;
  overflow-x: auto;
}

.lead-row {
  min-width: 920px;
  display: grid;
  grid-template-columns: minmax(230px, 1.4fr) 110px minmax(120px, .9fr) 100px 130px 230px;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
}

.lead-row:first-child {
  border-top: 0;
}

.lead-row.head {
  color: var(--muted);
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.lead-row strong,
.lead-row small {
  display: block;
}

.lead-row small {
  color: var(--muted);
  margin-top: 2px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.dual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .8fr);
  gap: 14px;
}

.detail-grid.compact {
  padding: 14px;
  margin: 0;
  grid-template-columns: repeat(3, 1fr);
}

.mini-list {
  display: grid;
}

.mini-list > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.mini-list > div:first-child {
  border-top: 0;
}

.mini-list span {
  color: var(--muted);
  font-weight: 800;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 10px;
  padding: 14px;
}

.review-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand-2);
  border-radius: var(--radius);
  padding: 13px;
  background: #fff;
  display: grid;
  gap: 12px;
}

.review-card strong {
  display: block;
  font-size: 15px;
}

.review-card p {
  margin: 5px 0;
  color: var(--ink);
}

.review-card small {
  color: var(--muted);
  font-weight: 800;
}

.breakdown {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

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

.breakdown-head h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.breakdown-table {
  display: grid;
}

.breakdown-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) repeat(5, minmax(76px, 1fr));
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.breakdown-row:first-child {
  border-top: 0;
}

.breakdown-row.head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--panel-2);
}

.breakdown-row strong,
.breakdown-row small {
  display: block;
}

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

.stream,
.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: calc(100vh - 168px);
}

.stream-head,
.detail-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stream-head h2,
.detail h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.sections {
  max-height: calc(100vh - 228px);
  overflow: auto;
  padding: 12px;
}

.section {
  margin-bottom: 12px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 7px;
}

.lead-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  background: #fff;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.lead-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(0, 78, 82, .08);
}

.lead-card.selected {
  border-color: var(--brand-2);
  border-left-color: var(--brand-2);
}

.lead-card.overdue {
  border-left-color: var(--red);
}

.lead-card.today {
  border-left-color: var(--fresh);
}

.lead-card.wait {
  border-left-color: var(--amber);
}

.lead-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.lead-title {
  font-weight: 900;
  font-size: 15.5px;
}

.lead-meta,
.lead-line {
  color: var(--muted);
  font-size: 13px;
}

.lead-task {
  margin: 9px 0;
  color: var(--ink);
  font-weight: 750;
}

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

.badge {
  border-radius: 6px;
  padding: 3px 8px;
  background: #eef2f3;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--fresh-soft); color: #0d9488; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }

.lead-actions {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}

.fallback-line {
  margin-top: 6px;
  font-size: 12px;
}

.fallback-line a,
.web-link {
  color: var(--brand-2);
  font-weight: 900;
  text-decoration: none;
}

.lead-actions .btn {
  flex: 1;
}

.detail {
  overflow: hidden;
}

.detail-body {
  padding: 16px;
  max-height: calc(100vh - 228px);
  overflow: auto;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}

.fact {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel-2);
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: .04em;
}

.fact strong {
  display: block;
  margin-top: 2px;
  font-size: 15px;
}

.panel {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 12px;
  margin-top: 12px;
  background: #fff;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0;
}

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

.event {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.event:first-child {
  border-top: 0;
}

.event time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.event strong {
  display: block;
  margin-bottom: 2px;
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 33, 31, .45);
  z-index: 10;
}

.modal[hidden] {
  display: none;
}

.modal-box {
  width: min(720px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.modal-head h2 {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.full {
  grid-column: 1 / -1;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 800;
  z-index: 11;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .top-tabs {
    display: flex;
  }
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .breakdown-table {
    overflow-x: auto;
  }
  .breakdown-row {
    min-width: 760px;
  }
  .workbench {
    grid-template-columns: 1fr;
  }
  .dual-grid,
  .review-grid {
    grid-template-columns: 1fr;
  }
  .stream,
  .detail {
    min-height: auto;
  }
  .sections,
  .detail-body {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }
  .content {
    padding: 12px;
  }
  .metrics,
  .detail-grid,
  .form-grid,
  .quick-grid,
  .field-row {
    grid-template-columns: 1fr;
  }
  .lead-actions {
    flex-direction: column;
  }
  .top-actions,
  .install-hint,
  .notification-control,
  .view-head,
  .mini-list > div {
    align-items: stretch;
    flex-direction: column;
  }
  .install-actions,
  .notification-actions {
    width: 100%;
  }
  .install-actions .btn,
  .notification-actions .btn {
    flex: 1;
  }
  .segmented {
    justify-content: flex-start;
  }
  .detail-grid.compact {
    grid-template-columns: 1fr;
  }
  .top-tabs .nav-item {
    min-width: 82px;
  }
}
