:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-border: #e2e8f0;
  --sidebar-bg: #0f172a;
  --sidebar-text: #f8fafc;
  --sidebar-text-muted: #94a3b8;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-hover: #1d4ed8;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

.sidebar {
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-kicker {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #38bdf8;
}

.sidebar h1 {
  margin: 20px 0 12px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-copy {
  color: var(--sidebar-text-muted);
  line-height: 1.6;
  font-size: 14px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 32px;
}

.nav-link {
  border: 0;
  background: transparent;
  color: var(--sidebar-text-muted);
  padding: 12px 16px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--sidebar-text);
}

.nav-link.is-active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sidebar-footer {
  margin-top: 20px;
  display: grid;
  gap: 12px;
}

.sidebar-user {
  display: grid;
  gap: 8px;
}

.muted-light {
  color: var(--sidebar-text-muted);
  font-size: 12px;
}

.sidebar-logout {
  width: 100%;
  justify-content: center;
}

.badge {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text-muted);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.content {
  padding: 40px 48px;
  overflow-y: auto;
  height: 100vh;
}

.tab-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.tab-section.is-active {
  display: block;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.page-header h2 {
  margin: 0 0 6px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.page-header p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.stats-grid,
.overview-panels,
.runtime-grid,
.logs-layout {
  display: grid;
  gap: 24px;
}

.stats-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 24px;
}

.overview-panels,
.runtime-grid {
  grid-template-columns: 1fr 1fr;
}

.logs-layout {
  grid-template-columns: 1fr 380px;
}

.panel-card,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.panel-card {
  padding: 24px;
}

.panel-card h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.auth-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(0, 0, 0, 0.08), transparent 30%),
    linear-gradient(180deg, #f6f6f6 0%, #efefef 100%);
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-shell {
  width: 100%;
  max-width: 520px;
}

.auth-card {
  padding: 36px 32px 28px;
  background: #ffffff;
  border: 1px solid #ececec;
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);
}

.auth-title {
  margin: 0 0 24px;
  text-align: center;
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.04em;
  color: #111111;
}

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

.auth-form label {
  font-size: 16px;
  font-weight: 600;
  color: #2f3745;
}

.auth-submit {
  margin-top: 10px;
  min-height: 56px;
  border-radius: 12px;
  background: linear-gradient(180deg, #3f75ff 0%, #275ae0 100%);
  color: #ffffff;
  border: 0;
  font-size: 20px;
  font-weight: 700;
}

.auth-form input {
  min-height: 56px;
  border: 1px solid #d2d7e0;
  border-radius: 12px;
  background: #ffffff;
  color: #000000;
  padding: 0 16px;
  font-size: 18px;
}

.auth-form input::placeholder {
  color: #9aa3b4;
}

.auth-form input:focus {
  outline: none;
  border-color: #275ae0;
  box-shadow: 0 0 0 4px rgba(39, 90, 224, 0.12);
}

.auth-submit:hover {
  filter: brightness(1.03);
}

.auth-submit:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(39, 90, 224, 0.18);
}

#loginStatus {
  min-height: 24px;
  margin: 0;
  color: #b91c1c;
  font-size: 16px;
  text-align: center;
}

@media (max-width: 768px) {
  .auth-shell {
    max-width: 100%;
  }

  .auth-card {
    padding: 28px 20px 22px;
    border-radius: 16px;
  }

  .auth-title {
    margin-bottom: 20px;
    font-size: 32px;
  }

  .auth-form label {
    font-size: 15px;
  }

  .auth-form input {
    min-height: 52px;
    font-size: 17px;
  }

  .auth-submit {
    min-height: 52px;
    font-size: 18px;
  }
}

.stat-card {
  padding: 20px 24px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card strong {
  font-size: 32px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}

.summary-list,
.recent-calls {
  margin: 0;
  padding: 0;
  list-style: none;
}

.summary-list li,
.recent-call {
  padding: 14px 0;
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
}

.recent-call {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recent-call:last-child,
.summary-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.summary-list li:first-child,
.recent-call:first-child {
  padding-top: 0;
}

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

.large-panel {
  grid-row: span 2;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
  margin-top: 16px;
}

label:first-child {
  margin-top: 0;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #ffffff;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) inset;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.runtime-save-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 1rem;
}

.small-hint {
  font-size: 12px;
  margin-top: 0.5rem;
  line-height: 1.45;
}

.transfer-panel {
  grid-column: 1 / -1;
}

.mailing-panel {
  min-height: 100%;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0;
}

.switch-row.compact {
  margin-bottom: 0;
}

.switch-row input[type="checkbox"] {
  width: auto;
}

.rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  margin-bottom: 10px;
}

.transfer-rules-list {
  display: grid;
  gap: 12px;
}

.transfer-rule-card {
  border: 1px solid var(--panel-border);
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
}

.transfer-rule-card.is-disabled {
  opacity: 0.65;
}

.transfer-rule-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.transfer-rule-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.primary-button,
.ghost-button {
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-button {
  border: 0;
  background-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

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

.ghost-button {
  border: 1px solid var(--panel-border);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover {
  background: var(--bg);
  border-color: #cbd5e1;
}

.save-status,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.voice-cards {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

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

.voice-card strong {
  font-size: 14px;
  font-weight: 600;
}

.voice-card .muted {
  font-size: 12px;
  margin-top: 2px;
}

.mailing-grid {
  align-items: start;
}

.mailing-recipient-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.sales-plan-recipients-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.sales-plan-recipient-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.sales-plan-recipient-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.sales-plan-recipient-card strong {
  font-size: 15px;
}

.sales-plan-recipient-card .badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.sales-plan-recipient-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sales-plan-recipient-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filters {
  display: flex;
  align-items: end;
  gap: 16px;
  margin-bottom: 24px;
  background: var(--panel);
  padding: 16px 24px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.filters label {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
}

.table-panel {
  overflow: auto;
  padding: 0;
}

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

.calls-table th {
  background: #f8fafc;
  padding: 14px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
}

.calls-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: middle;
}

.calls-table tbody tr {
  cursor: pointer;
  transition: background-color 0.15s;
}

.calls-table tbody tr:hover {
  background: #f1f5f9;
}

.calls-table tbody tr.selected-row {
  background: var(--accent-soft);
}

.calls-table tbody tr:last-child td {
  border-bottom: 0;
}

.primary-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
}

.primary-text.font-medium {
  font-weight: 600;
}

.secondary-text {
  font-size: 12px;
  color: var(--muted);
}

.status-reason {
  font-size: 13px;
  color: var(--ink);
  display: inline-block;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-pill {
  display: inline-flex;
  min-width: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 4px 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.score-pill.low {
  background: var(--red-soft);
  color: var(--red);
}

.score-pill.high {
  background: var(--green-soft);
  color: var(--green);
}

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

.call-detail {
  display: grid;
  gap: 20px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 0;
  font-size: 14px;
}

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

.detail-box {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
}

.detail-box strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.detail-box div {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
}

.transcript {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 8px;
}

.transcript::-webkit-scrollbar {
  width: 6px;
}
.transcript::-webkit-scrollbar-track {
  background: transparent;
}
.transcript::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.turn {
  padding: 12px 14px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--panel-border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.turn strong {
  display: block;
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
  text-transform: none;
  letter-spacing: normal;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
  }
  .logs-layout {
    grid-template-columns: 1fr;
  }
  .detail-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    padding: 20px;
  }
  .nav {
    display: flex;
    overflow-x: auto;
  }
  .nav-link {
    white-space: nowrap;
  }
  .content {
    padding: 24px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .overview-panels,
  .runtime-grid,
  .form-grid,
  .mailing-recipient-grid {
    grid-template-columns: 1fr;
  }
}
