:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #6b7280;
  --line: #d9dee7;
  --soft: #eaf1fb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --warning: #b45309;
  --danger: #b42318;
  --ok: #1d4ed8;
  --shadow: 0 14px 34px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button,
.button-link {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  border-color: var(--accent);
}

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

.primary:hover {
  background: var(--accent-dark);
}

.ghost {
  color: var(--muted);
  background: transparent;
}

.danger-button {
  border-color: #f2b8b5;
  color: var(--danger);
  background: #fff7f6;
}

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

textarea {
  resize: vertical;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

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

.topbar h1,
.detail-head h2,
.modal h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 26px;
}

.topbar p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 4px;
  color: var(--muted);
}

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

.metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.metric strong {
  font-size: 18px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.customer-panel {
  position: sticky;
  top: 16px;
}

.list-tools {
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.customer-list {
  max-height: calc(100vh - 206px);
  overflow: auto;
}

.customer-card {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 13px 14px;
  text-align: left;
  background: #fff;
}

.customer-card.active {
  background: #eff6ff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.card-row,
.detail-head,
.modal-head,
.modal-actions,
.follow-row,
.analysis-score,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-row,
.detail-head,
.modal-head,
.modal-actions {
  justify-content: space-between;
}

.customer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  border-radius: 999px;
  padding: 2px 8px;
  color: #314052;
  background: var(--soft);
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: #eaf1ff;
}

.badge.warn {
  color: var(--warning);
  background: #fff4df;
}

.badge.danger {
  color: var(--danger);
  background: #fff0ee;
}

.detail-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

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

.detail-body {
  padding: 16px;
}

.empty-state {
  min-height: 300px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

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

.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.field span,
.score-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.field strong,
.score-card strong {
  display: block;
  margin-top: 5px;
}

.analysis-box,
.follow-box,
.timeline-box,
.records-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fbfcfd;
}

.analysis-score {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 12px;
}

.score-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.score-card strong {
  font-size: 22px;
}

.timeline {
  display: grid;
  gap: 10px;
}

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

.timeline-item p {
  margin: 4px 0 0;
  line-height: 1.55;
}

.follow-row {
  display: grid;
  grid-template-columns: 1fr 130px 160px;
  margin-bottom: 10px;
}

.follow-box textarea,
.analysis-box textarea {
  min-height: 86px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

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

.mini-form {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.mini-form h3,
.records-box h3 {
  margin: 0;
}

.record-row,
.data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.record-row {
  grid-template-columns: 1fr;
}

.record-row:last-child,
.data-row:last-child {
  border-bottom: 0;
}

.record-row p,
.data-row p {
  margin: 4px 0 0;
}

.record-row audio {
  width: 100%;
  max-width: 520px;
}

.audio-upload-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(110px, 0.6fr) minmax(190px, 1fr) auto;
  gap: 8px;
  align-items: center;
  max-width: 760px;
}

.audio-upload-form input {
  min-width: 0;
}

.data-list {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  max-height: 68vh;
  overflow: auto;
}

.data-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.duplicate-row {
  grid-template-columns: 1fr;
}

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

.module-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.module-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
}

.modal.wide-modal {
  width: min(980px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(24, 33, 47, 0.45);
}

.modal-card,
.login-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-body {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

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

.owner-table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.owner-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.owner-row:last-child {
  border-bottom: 0;
}

.owner-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(24, 33, 47, 0.48);
}

.login-overlay.visible {
  display: grid;
}

.login-box {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .metrics,
  .workspace,
  .summary-strip,
  .ops-grid,
  .module-grid {
    grid-template-columns: 1fr;
  }

  .customer-panel {
    position: static;
  }

  .customer-list {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .metrics,
  .analysis-score,
  .form-grid,
  .follow-row,
  .list-tools,
  .ops-grid,
  .module-grid,
  .record-row,
  .data-row,
  .audio-upload-form {
    grid-template-columns: 1fr;
  }

  .detail-head,
  .modal-head,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-actions,
  .modal-actions {
    width: 100%;
  }

  .detail-actions button,
  .modal-actions button {
    flex: 1;
  }
}
