/* ==========================================================================
   CX Portal — Global Design System
   ========================================================================== */

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

/* ─── CSS Custom Properties — Light Mode (default) ───────────────────────── */
:root {
  --color-bg:            #ffffff;
  --color-bg-secondary:  #f9f9f9;
  --color-bg-tertiary:   #f3f3f3;
  --color-border:        #e5e5e5;
  --color-text-primary:  #111111;
  --color-text-secondary:#666666;
  --color-text-muted:    #999999;
  --color-accent:        #7C3AED;
  --color-accent-light:  #EDE9FE;
  --color-accent-dark:   #5B21B6;
  --color-success:       #22c55e;
  --color-success-bg:    #f0fdf4;
  --color-warning:       #eab308;
  --color-warning-bg:    #fefce8;
  --color-danger:        #ef4444;
  --color-danger-bg:     #fef2f2;
  --color-white:         #ffffff;
  --color-sidebar-bg:    #111111;
  --color-sidebar-text:  #e5e5e5;
  --color-sidebar-muted: #888888;
  --sidebar-width:       240px;
  --header-height:       60px;
  --radius-sm:           6px;
  --radius-md:           8px;
  --radius-lg:           12px;
  --shadow-sm:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:           0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:           0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
  --transition:          all 0.15s ease;
}

/* ─── Dark Mode overrides ─────────────────────────────────────────────────── */
[data-theme="dark"] {
  --color-bg:            #0f0f12;
  --color-bg-secondary:  #18181c;
  --color-bg-tertiary:   #222228;
  --color-border:        #2e2e38;
  --color-text-primary:  #f0f0f0;
  --color-text-secondary:#9a9aaa;
  --color-text-muted:    #5a5a6e;
  --color-accent:        #8b5cf6;
  --color-accent-light:  #2d1f4e;
  --color-accent-dark:   #a78bfa;
  --color-success:       #22c55e;
  --color-success-bg:    #0d2818;
  --color-warning:       #eab308;
  --color-warning-bg:    #2a2000;
  --color-danger:        #f87171;
  --color-danger-bg:     #2c0f0f;
  --color-white:         #0f0f12;
  --color-sidebar-bg:    #0a0a0e;
  --color-sidebar-text:  #d4d4e0;
  --color-sidebar-muted: #5a5a6e;
  --shadow-sm:           0 1px 3px rgba(0,0,0,.4),  0 1px 2px rgba(0,0,0,.3);
  --shadow-md:           0 4px 12px rgba(0,0,0,.5),  0 2px 4px rgba(0,0,0,.3);
  --shadow-lg:           0 10px 30px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);
}

/* Dark mode table alternating rows */
[data-theme="dark"] .data-table tbody tr:hover {
  background: var(--color-accent-light);
}

/* Dark mode card/input surfaces */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border);
  color-scheme: dark;
}

[data-theme="dark"] .form-select {
  background-color: var(--color-bg-secondary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239a9aaa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px 6px;
}

[data-theme="dark"] .modal {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .modal-footer,
[data-theme="dark"] .card-footer {
  background: var(--color-bg-tertiary);
}

[data-theme="dark"] .sidebar {
  border-right: 1px solid var(--color-border);
}

[data-theme="dark"] .header {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .summary-card {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .contact-card {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .timeline-card {
  background: var(--color-bg-secondary);
}

[data-theme="dark"] .custom-field-item {
  background: var(--color-bg-tertiary);
}

[data-theme="dark"] .toast {
  background: #2a2a35;
  border: 1px solid var(--color-border);
}
[data-theme="dark"] .toast-success { background: #0d2818; border-color: #166534; }
[data-theme="dark"] .toast-error   { background: #2c0f0f; border-color: #991b1b; }
[data-theme="dark"] .toast-info    { background: var(--color-accent-light); border-color: var(--color-accent); }

[data-theme="dark"] .page-btn {
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

[data-theme="dark"] .health-score-circle.green  { background: var(--color-success-bg); }
[data-theme="dark"] .health-score-circle.yellow { background: var(--color-warning-bg); }
[data-theme="dark"] .health-score-circle.red    { background: var(--color-danger-bg); }

[data-theme="dark"] .alert-warning { background: var(--color-warning-bg); border-color: #713f12; }
[data-theme="dark"] .alert-danger  { background: var(--color-danger-bg);  border-color: #991b1b; }
[data-theme="dark"] .alert-success { background: var(--color-success-bg); border-color: #166534; }
[data-theme="dark"] .alert-info    { background: var(--color-accent-light); border-color: var(--color-accent); color: var(--color-accent-dark); }

/* ─── Theme toggle button ─────────────────────────────────────────────────── */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border-color: var(--color-accent);
}

/* Smooth theme transitions */
body, .sidebar, .header, .card, .summary-card, .modal,
.form-input, .form-select, .form-textarea, .data-table tbody td,
.data-table thead th, .contact-card, .timeline-card, .badge {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-primary);
  background: var(--color-bg);
}
a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-dark); }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: 14px; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1400px;
  width: 100%;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar-brand {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-logo {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-logo img {
  height: 100%;
  width: auto;
  object-fit: contain;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-sidebar-muted);
  padding: 16px 20px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--color-sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  transition: var(--transition);
  position: relative;
}

.nav-link:hover {
  background: rgba(255,255,255,0.07);
  color: #ffffff;
}

.nav-link.active {
  background: var(--color-accent);
  color: #ffffff;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(255,255,255,0.6);
  border-radius: 0 2px 2px 0;
}

.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.75;
}

.nav-link.active svg,
.nav-link:hover svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* ─── Header bar ─────────────────────────────────────────────────────────── */
.header {
  height: var(--header-height);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-accent-light);
}

.user-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

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

.card-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── Summary cards ──────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.summary-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.summary-card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.summary-card-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.summary-card-sub {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mom-up   { color: var(--color-success); font-weight: 500; }
.mom-down { color: var(--color-danger);  font-weight: 500; }
.mom-flat { color: var(--color-text-muted); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  line-height: 1;
}

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

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

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-tertiary); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
  padding: 8px 10px;
}
.btn-ghost:hover { background: var(--color-bg-tertiary); color: var(--color-text-primary); }

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
  border-color: var(--color-danger);
}
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 9px;  font-size: 11px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── Form elements ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: 13.5px;
  transition: border-color 0.12s;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.10);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--color-text-muted); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px 6px;
  padding-right: 32px;
}

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

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

.form-hint {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 3px;
}

.form-error {
  font-size: 11px;
  color: var(--color-danger);
  margin-top: 3px;
}

/* ─── Data table ─────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.data-table thead th.sortable {
  cursor: pointer;
}

.data-table thead th.sortable:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.data-table thead th .sort-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.4;
  font-size: 10px;
}

.data-table thead th.sort-asc .sort-icon::after  { content: ' ▲'; opacity: 1; }
.data-table thead th.sort-desc .sort-icon::after { content: ' ▼'; opacity: 1; }

.data-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
  cursor: default;
}

.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-accent-light); }
.data-table tbody tr.clickable { cursor: pointer; }

.data-table tbody td {
  padding: 11px 14px;
  color: var(--color-text-primary);
  vertical-align: middle;
}

.data-table tbody td.text-muted { color: var(--color-text-muted); }

/* ─── Health dot ─────────────────────────────────────────────────────────── */
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.health-dot.green  { background: var(--color-success); box-shadow: 0 0 0 3px rgba(34,197,94,0.18); }
.health-dot.yellow { background: var(--color-warning); box-shadow: 0 0 0 3px rgba(234,179,8,0.18); }
.health-dot.red    { background: var(--color-danger);  box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }

.health-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-green  { background: var(--color-success-bg); color: #16a34a; }
.badge-yellow { background: var(--color-warning-bg); color: #a16207; }
.badge-red    { background: var(--color-danger-bg);  color: #dc2626; }
.badge-gray   { background: var(--color-bg-tertiary); color: var(--color-text-secondary); }
.badge-purple { background: var(--color-accent-light); color: var(--color-accent-dark); }

/* ─── Progress bar ───────────────────────────────────────────────────────── */
.progress-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar-track {
  flex: 1;
  height: 7px;
  background: var(--color-bg-tertiary);
  border-radius: 20px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 20px;
  transition: width 0.4s ease;
  background: var(--color-accent);
}

.progress-bar-fill.usage-safe    { background: var(--color-success); }
.progress-bar-fill.usage-warning { background: var(--color-warning); }
.progress-bar-fill.usage-danger  { background: var(--color-danger); }

.progress-bar-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  min-width: 65px;
  text-align: right;
}

/* ─── Health score gauge ─────────────────────────────────────────────────── */
.health-score-display {
  display: flex;
  align-items: center;
  gap: 16px;
}

.health-score-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  border: 4px solid currentColor;
  flex-shrink: 0;
}

.health-score-circle.green  { color: var(--color-success); background: var(--color-success-bg); }
.health-score-circle.yellow { color: var(--color-warning); background: var(--color-warning-bg); }
.health-score-circle.red    { color: var(--color-danger);  background: var(--color-danger-bg); }

.health-score-details { flex: 1; }
.health-score-label   { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }

.health-factor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}

.health-factor-row:last-child { border-bottom: none; }

.health-factor-name  { color: var(--color-text-secondary); }
.health-factor-impact {
  font-weight: 600;
  min-width: 55px;
  text-align: right;
}
.health-factor-impact.positive { color: var(--color-success); }
.health-factor-impact.negative { color: var(--color-danger); }
.health-factor-impact.neutral  { color: var(--color-text-muted); }

/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-10px) scale(0.98);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-lg { max-width: 720px; }
.modal-sm { max-width: 420px; }

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

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

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--color-bg-tertiary);
  border-radius: 50%;
  font-size: 16px;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: var(--color-border); color: var(--color-text-primary); }

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--color-bg-secondary);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── Toast notifications ────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-text-primary);
  color: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  min-width: 260px;
  max-width: 420px;
  pointer-events: all;
  animation: toastIn 0.25s ease;
}

.toast-success { background: #15803d; }
.toast-error   { background: #dc2626; }
.toast-info    { background: var(--color-accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast.toast-fadeout {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

.toast-icon { font-size: 15px; flex-shrink: 0; }
.toast-message { flex: 1; }
.toast-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 16px;
  padding: 0 2px;
  flex-shrink: 0;
}
.toast-close:hover { color: #fff; }

/* ─── Confirm dialog ─────────────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-dialog {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.confirm-icon { font-size: 36px; margin-bottom: 14px; }
.confirm-message { font-size: 14px; color: var(--color-text-secondary); margin-bottom: 22px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 2px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-btn {
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.page-btn:hover:not(:disabled) { border-color: var(--color-accent); color: var(--color-accent); }
.page-btn.active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Filter bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  flex: 1;
  min-width: 160px;
  max-width: 260px;
}

.filter-bar .search-input {
  max-width: 320px;
}

/* ─── Page header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header-left h1 { font-size: 22px; font-weight: 700; }
.page-header-left p  { color: var(--color-text-secondary); font-size: 13.5px; margin-top: 2px; }

.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ─── Tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  gap: 0;
  margin-bottom: 24px;
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: var(--transition);
}

.tab-btn:hover { color: var(--color-text-primary); }
.tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
  font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Section dividers ───────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ─── Key-value detail rows ──────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px 24px;
}

.detail-item {}
.detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 3px;
}
.detail-value {
  font-size: 14px;
  color: var(--color-text-primary);
}

/* ─── Timeline (check-ins) ───────────────────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--color-border);
}

.timeline-item {
  position: relative;
  margin-bottom: 20px;
}

.timeline-dot {
  position: absolute;
  left: -24px;
  top: 5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 2px var(--color-accent);
}

.timeline-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.timeline-date {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.timeline-title {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 4px;
}

.timeline-body {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* ─── Stars ──────────────────────────────────────────────────────────────── */
.stars { display: inline-flex; gap: 1px; }
.star { font-size: 14px; }
.star-filled { color: var(--color-warning); }
.star-empty  { color: var(--color-border); }

/* ─── Spinner ────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

.spinner-dark {
  border: 2.5px solid rgba(0,0,0,0.12);
  border-top-color: var(--color-accent);
}

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

.loading-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.empty-state-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--color-text-secondary); }
.empty-state-sub   { font-size: 13px; margin-top: 4px; }

/* ─── Contact card ───────────────────────────────────────────────────────── */
.contact-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.contact-card.is-primary {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 14px; font-weight: 600; }
.contact-title { font-size: 12px; color: var(--color-text-secondary); }
.contact-links { display: flex; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.contact-link  { font-size: 12px; color: var(--color-accent); display: flex; align-items: center; gap: 3px; }

.contact-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ─── Login page ─────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-secondary);
}

.login-card {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  height: 64px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  padding: 12px 20px;
  border-radius: 12px;
  width: fit-content;
}

.login-logo img {
  height: 100%;
  width: auto;
  object-fit: contain;
}

.login-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.login-sub   { font-size: 13.5px; color: var(--color-text-secondary); margin-bottom: 32px; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 12px 20px;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.btn-google:hover { border-color: var(--color-accent); background: var(--color-accent-light); }

.login-footer { font-size: 11.5px; color: var(--color-text-muted); margin-top: 24px; }

.login-error {
  background: var(--color-danger-bg);
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 20px;
}

/* ─── Inline editable ────────────────────────────────────────────────────── */
.inline-edit-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-edit-display {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: var(--transition);
}

.inline-edit-display:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

/* ─── Section divider ────────────────────────────────────────────────────── */
hr.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 20px 0;
}

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-warning { background: var(--color-warning-bg); color: #a16207; border: 1px solid #fde047; }
.alert-danger  { background: var(--color-danger-bg);  color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: var(--color-success-bg); color: #16a34a; border: 1px solid #bbf7d0; }
.alert-info    { background: var(--color-accent-light); color: var(--color-accent-dark); border: 1px solid #c4b5fd; }

/* ─── Custom field list ──────────────────────────────────────────────────── */
.custom-field-list { display: flex; flex-direction: column; gap: 8px; }

.custom-field-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.custom-field-name  { font-weight: 500; min-width: 140px; color: var(--color-text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
.custom-field-value { flex: 1; font-size: 13.5px; }
.custom-field-type  { font-size: 11px; color: var(--color-text-muted); background: var(--color-bg-tertiary); padding: 2px 7px; border-radius: 10px; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

/* Tablet: 768–1024px */
@media (max-width: 1024px) {
  .sidebar {
    width: 200px;
    min-width: 200px;
  }
  .main-wrapper { margin-left: 200px; }
  .main-content { padding: 20px; }
  .form-row-3  { grid-template-columns: 1fr 1fr; }

  #overviewGrid {
    grid-template-columns: 1fr !important;
  }
}

/* ─── Mobile hamburger button (hidden on desktop) ─────────────────────────── */
.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 18px;
}

/* Bottom nav hidden on desktop */
.bottom-nav { display: none; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
}

.sidebar-overlay.active { display: block; }

/* Mobile: ≤768px */
@media (max-width: 768px) {

  /* ── Layout ──────────────────────────────────────────────────────────── */
  .sidebar {
    position: fixed;
    left: -260px;
    width: 260px;
    min-width: 260px;
    height: 100vh;
    z-index: 200;
    transition: left 0.25s ease;
  }

  .sidebar.open { left: 0; }

  .main-wrapper { margin-left: 0; }

  .main-content {
    padding: 14px 14px 80px; /* bottom padding for bottom nav */
  }

  /* ── Header ─────────────────────────────────────────────────────────── */
  .header {
    padding: 0 14px;
    gap: 8px;
  }

  .header-left { gap: 8px; flex: 1; min-width: 0; }

  .header-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-menu-btn { display: flex; }

  /* Hide text username on mobile, keep avatar */
  .user-name { display: none; }

  .header-right { gap: 8px; }

  /* Hide sign-out text link in header (accessible via sidebar) */
  .header-right > a.btn { display: none; }

  /* ── Bottom navigation bar ───────────────────────────────────────────── */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    z-index: 90;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    padding: 6px 4px;
    transition: color 0.15s;
    cursor: pointer;
  }

  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
  }

  .bottom-nav-item.active {
    color: var(--color-accent);
  }

  .bottom-nav-item:active {
    background: var(--color-bg-tertiary);
  }

  [data-theme="dark"] .bottom-nav {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
  }

  /* ── Summary cards ───────────────────────────────────────────────────── */
  .summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }

  .summary-card { padding: 14px 14px; }
  .summary-card-value { font-size: 20px; }

  /* ── Page header ─────────────────────────────────────────────────────── */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
  }

  .page-header-left h1 { font-size: 18px; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { width: 100%; justify-content: center; }

  /* ── Tables — horizontal scroll on mobile ────────────────────────────── */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    min-width: 600px;
  }

  /* Dashboard customer table — slightly wider */
  #customerTableBody ~ * .data-table,
  .card .data-table { min-width: 580px; }

  /* ── Cards ───────────────────────────────────────────────────────────── */
  .card-header {
    padding: 14px 14px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-body { padding: 14px; }
  .card-footer { padding: 10px 14px; }

  /* ── Forms ───────────────────────────────────────────────────────────── */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  .form-input, .form-select, .form-textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px;
  }

  .form-select { padding: 10px 32px 10px 12px; }

  /* ── Filter bar ─────────────────────────────────────────────────────── */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .filter-bar .form-input,
  .filter-bar .form-select {
    max-width: 100% !important;
    min-width: 0;
    width: 100% !important;
  }

  /* ── Modals — full screen on mobile ──────────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal, .modal-lg, .modal-sm {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal-header { padding: 16px 16px 12px; }
  .modal-body   { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }

  /* ── Tabs ────────────────────────────────────────────────────────────── */
  .tabs {
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .tab-btn {
    padding: 10px 14px;
    font-size: 12.5px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Detail grid ─────────────────────────────────────────────────────── */
  .detail-grid { grid-template-columns: 1fr 1fr; }

  /* ── Customer overview — stack panels ────────────────────────────────── */
  #overviewGrid {
    grid-template-columns: 1fr !important;
  }

  /* ── Contacts grid ───────────────────────────────────────────────────── */
  #contactsList {
    grid-template-columns: 1fr !important;
  }

  /* ── Billing summary layout ──────────────────────────────────────────── */
  #tab-billing > div {
    grid-template-columns: 1fr !important;
  }

  /* ── Pagination ──────────────────────────────────────────────────────── */
  .pagination {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* ── Buttons — bigger tap targets ────────────────────────────────────── */
  .btn { min-height: 36px; }
  .btn-sm { min-height: 32px; }

  /* ── Health score display ────────────────────────────────────────────── */
  .health-score-display {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  .health-score-circle {
    width: 80px;
    height: 80px;
    font-size: 26px;
    margin: 0 auto;
  }

  /* ── Toast — full width on mobile ────────────────────────────────────── */
  #toast-container {
    bottom: 70px; /* above bottom nav */
    left: 12px;
    right: 12px;
  }

  .toast { min-width: 0; max-width: 100%; }

  /* ── Login page ──────────────────────────────────────────────────────── */
  .login-card {
    padding: 32px 20px;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

/* Extra small: ≤400px */
@media (max-width: 400px) {
  .summary-grid { grid-template-columns: 1fr; }
  .detail-grid  { grid-template-columns: 1fr; }
  .summary-card-value { font-size: 18px; }
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-small  { font-size: 12px; }
.fw-600      { font-weight: 600; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-12       { margin-top: 12px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-8        { margin-bottom: 8px; }
.mb-12       { margin-bottom: 12px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.gap-8       { gap: 8px; }
.flex        { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap   { flex-wrap: wrap; }
.hidden      { display: none !important; }
