/* ── Balance 7 Admin Dashboard ──────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --b7-primary: #1d6fb3;
  --b7-primary-dark: #155a91;
  --b7-secondary: #2a9d6e;
  --b7-bg: #f5f7fa;
  --b7-card: #ffffff;
  --b7-text: #1a1a2e;
  --b7-text-secondary: #6b7280;
  --b7-border: #e5e7eb;
  --b7-danger: #ef4444;
  --b7-warning: #f59e0b;
  --b7-success: #10b981;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--b7-bg);
  color: var(--b7-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Navigation ───────────────────────────────────────────────────────────── */

.nav {
  background: var(--b7-card);
  border-bottom: 1px solid var(--b7-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--b7-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand span { font-weight: 400; color: var(--b7-text-secondary); font-size: 14px; }

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-links a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--b7-text-secondary);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}

.nav-links a:hover { background: var(--b7-bg); color: var(--b7-text); }
.nav-links a.active { background: var(--b7-primary); color: white; }

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

.btn-logout {
  padding: 6px 14px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--b7-text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover { border-color: var(--b7-danger); color: var(--b7-danger); }

/* ── Page Layout ──────────────────────────────────────────────────────────── */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--b7-text);
}

/* ── Cards ────────────────────────────────────────────────────────────────── */

.card {
  background: var(--b7-card);
  border-radius: var(--radius);
  border: 1px solid var(--b7-border);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--b7-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ── Stat Cards ───────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--b7-card);
  border-radius: var(--radius);
  border: 1px solid var(--b7-border);
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--b7-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--b7-text);
  margin-top: 4px;
  line-height: 1.2;
}

.stat-card.highlight { border-left: 4px solid var(--b7-primary); }
.stat-card.success { border-left: 4px solid var(--b7-success); }
.stat-card.warning { border-left: 4px solid var(--b7-warning); }

/* ── Tables ───────────────────────────────────────────────────────────────── */

.table-wrapper {
  background: var(--b7-card);
  border-radius: var(--radius);
  border: 1px solid var(--b7-border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--b7-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-header h3 { font-size: 16px; font-weight: 600; }

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

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--b7-text-secondary);
  border-bottom: 1px solid var(--b7-border);
  background: var(--b7-bg);
}

tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--b7-border);
}

tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: #f0f4ff; }
tbody tr:last-child td { border-bottom: none; }

.mood-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}

.mood-high { background: #dcfce7; color: #166534; }
.mood-mid { background: #fef9c3; color: #854d0e; }
.mood-low { background: #fee2e2; color: #991b1b; }
.mood-none { background: #f3f4f6; color: #6b7280; }

/* ── Search ───────────────────────────────────────────────────────────────── */

.search-input {
  padding: 10px 14px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  width: 280px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.search-input:focus {
  outline: none;
  border-color: var(--b7-primary);
  box-shadow: 0 0 0 3px rgba(29, 111, 179, 0.1);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

.btn-primary {
  background: var(--b7-primary);
  color: white;
}

.btn-primary:hover { background: var(--b7-primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--b7-bg);
  color: var(--b7-text);
  border: 1px solid var(--b7-border);
}

.btn-secondary:hover { background: var(--b7-border); }

.btn-danger {
  background: var(--b7-danger);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-danger-outline {
  background: transparent;
  color: var(--b7-danger);
  border: 1px solid var(--b7-danger);
}

.btn-danger-outline:hover { background: #fef2f2; }

.btn-load-more {
  display: block;
  margin: 16px auto;
  padding: 10px 32px;
}

/* ── Login Page ───────────────────────────────────────────────────────────── */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d6fb3 0%, #2a9d6e 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
  color: var(--b7-primary);
}

.login-card .subtitle {
  text-align: center;
  color: var(--b7-text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--b7-text);
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--b7-primary);
  box-shadow: 0 0 0 3px rgba(29, 111, 179, 0.1);
}

.login-btn {
  width: 100%;
  margin-top: 8px;
}

.login-error {
  color: var(--b7-danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  display: none;
}

.login-error.visible { display: block; }

/* ── Customer Detail ──────────────────────────────────────────────────────── */

.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-header .back-link {
  color: var(--b7-primary);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}

.detail-header .back-link:hover { text-decoration: underline; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-field {
  padding: 12px 0;
  border-bottom: 1px solid var(--b7-border);
}

.detail-field:last-child { border-bottom: none; }

.detail-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--b7-text-secondary);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 15px;
  color: var(--b7-text);
  word-break: break-word;
}

.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--b7-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .count {
  background: var(--b7-bg);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--b7-text-secondary);
}

.collapsible-header {
  cursor: pointer;
  padding: 12px 16px;
  background: var(--b7-bg);
  border-radius: var(--radius-sm);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  transition: background 0.15s;
}

.collapsible-header:hover { background: var(--b7-border); }

.collapsible-content {
  display: none;
  padding: 12px 16px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.collapsible-content.open { display: block; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  margin: 2px;
  background: #e8f4fd;
  color: var(--b7-primary);
}

/* ── Chart ────────────────────────────────────────────────────────────────── */

.chart-card {
  margin-bottom: 24px;
}

.chart-container {
  position: relative;
  height: 280px;
}

/* ── Info Note ────────────────────────────────────────────────────────────── */

.info-note {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: #4338ca;
  margin-bottom: 24px;
}

/* ── Loading ──────────────────────────────────────────────────────────────── */

.loading {
  text-align: center;
  padding: 40px;
  color: var(--b7-text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--b7-border);
  border-top-color: var(--b7-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ──────────────────────────────────────────────────────────── */

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

/* ── Messaging Page ──────────────────────────────────────────────────────── */

.compose-card {
  margin-bottom: 24px;
}

.compose-card textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.15s;
}

.compose-card textarea:focus {
  outline: none;
  border-color: var(--b7-primary);
  box-shadow: 0 0 0 3px rgba(29, 111, 179, 0.1);
}

.compose-card input[type="text"],
.compose-card select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.compose-card input[type="text"]:focus,
.compose-card select:focus {
  outline: none;
  border-color: var(--b7-primary);
  box-shadow: 0 0 0 3px rgba(29, 111, 179, 0.1);
}

.radio-group {
  display: flex;
  gap: 20px;
  margin: 8px 0;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--b7-text);
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--b7-text-secondary);
  margin-top: 4px;
}

.char-count.warning { color: var(--b7-warning); }
.char-count.danger { color: var(--b7-danger); }

.user-select-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--b7-border);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.user-select-item {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  border-bottom: 1px solid var(--b7-border);
  cursor: pointer;
  transition: background 0.1s;
}

.user-select-item:last-child { border-bottom: none; }
.user-select-item:hover { background: var(--b7-bg); }

.user-select-item input[type="checkbox"] {
  accent-color: var(--b7-primary);
}

.send-result {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: none;
}

.send-result.visible { display: block; }
.send-result.success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.send-result.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.compose-field {
  margin-bottom: 16px;
}

.compose-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--b7-text);
}

/* ── Analytics Page ────────────────────────────────────────────────────────── */

.stats-grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card.info { border-left: 4px solid var(--b7-primary); }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.funnel-card {
  margin-bottom: 24px;
}

.funnel-step {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--b7-border);
}

.funnel-step:last-child { border-bottom: none; }

.funnel-label {
  flex: 0 0 140px;
  font-size: 14px;
  font-weight: 500;
  color: var(--b7-text);
}

.funnel-bar-wrapper {
  flex: 1;
  height: 28px;
  background: var(--b7-bg);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.funnel-bar {
  height: 100%;
  background: var(--b7-primary);
  border-radius: 6px;
  transition: width 0.6s ease;
  min-width: 2px;
}

.funnel-bar.step-0 { background: #3b82f6; }
.funnel-bar.step-1 { background: #8b5cf6; }
.funnel-bar.step-2 { background: #10b981; }
.funnel-bar.step-3 { background: #f59e0b; }
.funnel-bar.step-4 { background: #ef4444; }

.funnel-count {
  flex: 0 0 80px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--b7-text);
}

.funnel-pct {
  font-weight: 400;
  color: var(--b7-text-secondary);
  font-size: 13px;
  margin-left: 4px;
}

.event-list {
  list-style: none;
  padding: 0;
}

.event-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--b7-border);
  font-size: 14px;
}

.event-list li:last-child { border-bottom: none; }

.event-name {
  font-weight: 500;
  color: var(--b7-text);
}

.event-count {
  font-weight: 600;
  color: var(--b7-primary);
  background: rgba(29, 111, 179, 0.1);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
}
