:root {
  --sidebar-bg: #06294f;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: #041b38;
  --primary-color: #034a98;
  --primary-hover: #023a7a;
  --accent-color: #fec502;
  --bg-color: #f8fafc;
  --text-dark: #0f172a;
  --text-gray: #64748b;
  --border-color: #e2e8f0;
  --chat-bg: #f1f5f9;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
  --radius-md: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-dark);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-container { display: flex; height: 100vh; width: 100vw; }

/* --- SIDEBAR --- */
.sidebar {
  width: 90px;
  background-color: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 4px 0 15px rgba(0,0,0,0.05);
  z-index: 100;
}
.sidebar-logo {
  padding: 24px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
.sidebar-logo svg { filter: drop-shadow(0 2px 4px rgba(3, 74, 152, 0.3)); }
.nav-links { list-style: none; display: flex; flex-direction: column; gap: 8px; padding: 0 12px; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  cursor: pointer;
  color: #94a3b8;
  border-radius: var(--radius-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 11px;
  font-weight: 500;
  gap: 8px;
}
.nav-item:hover { color: white; background-color: var(--sidebar-hover); transform: translateY(-1px); }
.nav-item.active { color: var(--primary-color); background-color: var(--sidebar-active); box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--sidebar-bg); box-shadow: 0 0 0 2px var(--primary-color); }
.sidebar-bottom { margin-bottom: 20px; }

/* --- MAIN CONTENT & TABS --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-color);
  overflow: hidden;
}
.tab-content { display: none; height: 100%; flex-direction: column; }
.tab-content.active { display: flex; animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- TOP BAR --- */
.top-bar {
  height: 70px;
  background-color: var(--white);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 32px;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.top-bar h2 { font-size: 20px; font-weight: 700; color: var(--text-dark); letter-spacing: -0.5px; }
.search-wrap { position: relative; }
.search-wrap::before {
  content: '🔍'; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 12px; opacity: 0.4; filter: grayscale(100%);
}
.search-wrap input {
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border-color);
  border-radius: 30px;
  width: 320px;
  font-size: 14px;
  background-color: #f8fafc;
  transition: all 0.3s ease;
}
.search-wrap input:focus { outline: none; border-color: var(--primary-color); background-color: var(--white); box-shadow: 0 0 0 4px rgba(3, 74, 152, 0.1); }

/* --- BUTTONS --- */
.btn-primary {
  background-color: var(--primary-color);
  color: white; border: none; padding: 10px 20px; border-radius: var(--radius-md);
  cursor: pointer; font-weight: 600; font-size: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 0 4px 6px rgba(3, 74, 152, 0.2);
}
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 6px 10px rgba(3, 74, 152, 0.3); }
.btn-primary.sm { padding: 8px 16px; font-size: 13px; }

.btn-outline {
  background-color: var(--primary-color);
  color: #ffffff; border: 1px solid var(--primary-color);
  padding: 10px 20px; border-radius: var(--radius-md); cursor: pointer;
  font-weight: 500; font-size: 14px; transition: all 0.2s; box-shadow: var(--shadow-sm);
}
.btn-outline:hover { background-color: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline.sm { padding: 8px 16px; font-size: 13px; }

/* --- LIVE CHAT LAYOUT --- */
.chat-layout-3col { display: flex; flex: 1; overflow: hidden; }

/* COL 1: Chat List */
.chat-list-col {
  width: 360px;
  background-color: var(--white);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  z-index: 5;
}
.chat-tabs { display: flex; border-bottom: 1px solid var(--border-color); padding: 0 16px; gap: 8px; }
.chat-tab {
  flex: 1; text-align: center; padding: 16px 0;
  font-size: 12px; font-weight: 700; color: var(--text-gray);
  cursor: pointer; position: relative; letter-spacing: 0.5px;
  transition: color 0.2s;
}
.chat-tab:hover { color: var(--text-dark); }
.chat-tab.active { color: var(--primary-color); }
.chat-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 3px; background-color: var(--primary-color); border-radius: 3px 3px 0 0;
}
.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.chat-item {
  display: flex; padding: 14px 16px; border-radius: var(--radius-md);
  cursor: pointer; align-items: center; transition: all 0.2s ease;
  border: 1px solid transparent;
}
.chat-item:hover { background-color: #f8fafc; border-color: #f1f5f9; }
.chat-item.active { background-color: #eaf1fb; border-color: #b8cdec; box-shadow: var(--shadow-sm); }
.avatar {
  width: 46px; height: 46px; border-radius: 14px;
  background-color: #f59e0b; color: white; display: flex;
  align-items: center; justify-content: center; font-weight: 700;
  font-size: 18px; margin-right: 16px; flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.chat-info { flex: 1; overflow: hidden; }
.chat-info h4 { margin: 0 0 6px 0; font-size: 15px; font-weight: 600; color: var(--text-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-info p { margin: 0; font-size: 13px; color: var(--text-gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* COL 2: Chat Thread */
.chat-thread-col {
  flex: 1; background-color: var(--chat-bg); position: relative;
  display: flex; flex-direction: column;
}
.chat-bg-pattern {
  position: absolute; top:0; left:0; right:0; bottom:0; opacity: 0.5;
  background-image: url('data:image/svg+xml;utf8,<svg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><g fill="%2394a3b8" fill-opacity="0.15"><path d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/></g></g></svg>');
  z-index: 1;
}
.chat-msgs {
  flex: 1; overflow-y: auto; padding: 32px; position: relative;
  z-index: 2; display: flex; flex-direction: column; gap: 16px;
}
.empty-state {
  text-align: center; margin: auto; color: var(--text-gray);
  background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(8px);
  padding: 48px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); z-index: 10;
  border: 1px solid rgba(255,255,255,0.5);
}
.empty-state h3 { margin-top: 20px; color: var(--text-dark); font-size: 20px; font-weight: 700; }
.msg-row { display: flex; width: 100%; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }
.msg-bubble {
  max-width: 65%; padding: 12px 16px; border-radius: 12px;
  position: relative; font-size: 14px; line-height: 1.6;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.msg-row.in .msg-bubble { background-color: var(--white); border-top-left-radius: 0; }
.msg-row.out .msg-bubble { background-color: #d1fae5; border-top-right-radius: 0; color: #064e3b; }
.msg-row.in .msg-bubble::before {
  content: ''; position: absolute; top: 0; left: -10px;
  width: 0; height: 0; border-top: 12px solid var(--white); border-left: 12px solid transparent;
}
.msg-row.out .msg-bubble::before {
  content: ''; position: absolute; top: 0; right: -10px;
  width: 0; height: 0; border-top: 12px solid #d1fae5; border-right: 12px solid transparent;
}
.msg-time {
  font-size: 11px; opacity: 0.6; text-align: right;
  margin-top: 6px; display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  font-weight: 500;
}
.tick { color: #9ca3af; font-size: 14px; display: flex; align-items: center; }
.tick.read { color: #3b82f6; }

/* Chat Input */
.chat-input-area {
  background: var(--white); padding: 16px 24px;
  display: flex; align-items: center; z-index: 2;
  border-top: 1px solid var(--border-color); gap: 16px;
  box-shadow: 0 -4px 6px rgba(0,0,0,0.02);
}
.chat-input-area input {
  flex: 1; border: 1px solid var(--border-color); outline: none;
  padding: 14px 20px; font-size: 15px; border-radius: 30px;
  background: var(--bg-color); transition: all 0.3s;
}
.chat-input-area input:focus { border-color: var(--primary-color); background: var(--white); box-shadow: 0 0 0 4px rgba(3, 74, 152, 0.1); }
.input-actions { display: flex; align-items: center; gap: 12px; }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 20px;
  color: var(--text-gray); transition: all 0.2s; padding: 8px; border-radius: 50%;
}
.icon-btn:hover { color: var(--primary-color); background: #eaf1fb; }
.btn-send-round {
  background: linear-gradient(135deg, #034a98, #023a7a); color: white;
  border: none; width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px; box-shadow: 0 4px 6px rgba(3, 74, 152, 0.3); transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-send-round:hover { transform: scale(1.1) rotate(5deg); box-shadow: 0 6px 12px rgba(3, 74, 152, 0.4); }

/* COL 3: Chat Profile */
.chat-profile-col {
  width: 360px; background-color: var(--white);
  border-left: 1px solid var(--border-color); display: flex; flex-direction: column;
  box-shadow: -4px 0 15px rgba(0,0,0,0.02); z-index: 5;
}
.profile-header {
  padding: 24px; font-weight: 700; border-bottom: 1px solid var(--border-color);
  font-size: 16px; display: flex; justify-content: space-between; align-items: center; color: var(--text-dark);
}
.profile-card { padding: 32px 24px; display: flex; flex-direction: column; align-items: center; overflow-y: auto; }
.avatar-lg {
  width: 100px; height: 100px; border-radius: 24px;
  background: linear-gradient(135deg, #f59e0b, #d97706); color: white; display: flex;
  align-items: center; justify-content: center; font-size: 40px;
  font-weight: 700; margin-bottom: 20px; box-shadow: 0 8px 16px rgba(245, 158, 11, 0.2);
}
.profile-card h3 { font-size: 22px; font-weight: 700; color: var(--text-dark); margin-bottom: 6px; letter-spacing: -0.5px; }
.profile-card p { color: var(--text-gray); font-size: 15px; font-weight: 500; margin-bottom: 24px; }

/* Custom Accordion for Coaching Data */
.coaching-section { width: 100%; display: flex; flex-direction: column; gap: 12px; }
details.acc-item {
  width: 100%; border: 1px solid var(--border-color); border-radius: var(--radius-md);
  background: var(--white); transition: box-shadow 0.2s;
}
details.acc-item[open] { box-shadow: var(--shadow-md); border-color: #cbd5e1; }
details.acc-item summary {
  padding: 16px; cursor: pointer; font-size: 14px; font-weight: 600;
  color: var(--text-dark); list-style: none; display: flex; justify-content: space-between;
  align-items: center; background: #f8fafc; border-radius: var(--radius-md); transition: background 0.2s;
}
details.acc-item summary:hover { background: #f1f5f9; }
details.acc-item[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 1px solid var(--border-color); background: var(--white); }
details.acc-item summary::-webkit-details-marker { display: none; }
details.acc-item summary::after { content: '▾'; color: var(--text-gray); font-size: 14px; transition: transform 0.3s; }
details.acc-item[open] summary::after { transform: rotate(180deg); }
.acc-content { padding: 16px; font-size: 13px; color: var(--text-gray); background: var(--white); border-radius: 0 0 var(--radius-md) var(--radius-md); line-height: 1.6; }
.acc-content .kv-row { display: flex; justify-content: space-between; margin-bottom: 8px; border-bottom: 1px dashed #e2e8f0; padding-bottom: 8px; }
.acc-content .kv-row:last-child { margin-bottom: 0; border-bottom: none; padding-bottom: 0; }
.acc-content .kv-row span:first-child { font-weight: 500; }
.acc-content .kv-row span:last-child { color: var(--text-dark); font-weight: 600; }

.btn-danger-text {
  color: #ef4444; background: #fef2f2; border: 1px solid #fee2e2; cursor: pointer;
  margin-top: 40px; font-weight: 600; font-size: 14px; padding: 12px; border-radius: var(--radius-md);
  width: 100%; transition: all 0.2s;
}
.btn-danger-text:hover { background: #fee2e2; border-color: #fca5a5; }

/* UTILITIES */
.p-20 { padding: 32px; }
.mt-20 { margin-top: 24px; }
.badge { padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; letter-spacing: 0.3px; display: inline-flex; align-items: center; gap: 4px; }
.badge.green { background-color: #d1fae5; color: #047857; }
.badge.blue { background-color: #dbeafe; color: #1d4ed8; }
.badge.orange { background-color: #fef3c7; color: #b45309; }
.badge.outline { border: 1px solid var(--border-color); color: var(--text-dark); background: var(--white); }
.badge.lg { padding: 8px 16px; font-size: 14px; }
.card { background: white; border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-sm); transition: box-shadow 0.3s; }
.card:hover { box-shadow: var(--shadow-md); }
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 32px; margin-bottom: 32px; }
.dash-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.promo { color: white; border: none; }
.promo.teal { background: linear-gradient(135deg, #0f766e, #115e59); box-shadow: 0 10px 15px -3px rgba(15, 118, 110, 0.3); }
.promo.emerald { background: linear-gradient(135deg, #034a98, #023a7a); box-shadow: 0 10px 15px -3px rgba(3, 74, 152, 0.3); }
.offer-banner { background: #f0fdf4; border: 1px solid #bbf7d0; padding: 20px 32px; border-radius: var(--radius-lg); display: flex; align-items: center; gap: 20px; margin-bottom: 32px; color: #166534; font-weight: 500; box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; background: white; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.data-table th, .data-table td { padding: 16px 24px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 14px; }
.data-table th { background: #f8fafc; font-weight: 700; color: var(--text-gray); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.2s; }
.data-table tbody tr:hover { background-color: #f1f5f9; cursor: pointer; }
.active-contact-header { display: flex; align-items: center; }
.active-contact-header .avatar { width: 40px; height: 40px; font-size: 16px; margin-right: 16px; border-radius: 12px; }
.table-actions { display: flex; gap: 16px; align-items: center; margin: 32px 0; }
.table-actions .spacer { flex: 1; }

/* --- Login screen --- */
.login-screen {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-color);
}
.login-card { width: 360px; padding: 32px; }
.field-label { display: block; font-size: 13px; color: var(--text-gray); margin-bottom: 6px; font-weight: 600; }
.login-card input[type="text"], .login-card input[type="password"] {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 14px; font-family: inherit;
}
#profile-tag, #profile-note-in {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 13px; font-family: inherit; margin-bottom: 4px;
}
.login-error { color: #ef4444; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1500;
  background: rgba(15, 23, 42, 0.4);
  display: flex; align-items: center; justify-content: center;
}
.modal-card { width: 440px; max-height: 80vh; overflow-y: auto; padding: 28px; }
.modal-card .field-label { margin-top: 16px; }
.modal-card input, .modal-card select, .modal-card textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 14px; font-family: inherit; margin-top: 4px;
}
.modal-actions { display: flex; gap: 12px; margin-top: 24px; justify-content: flex-end; }
.note-item { background: #f8fafc; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; }
.note-item .note-ts { color: var(--text-gray); font-size: 11px; display: block; margin-top: 2px; }

/* --- Login logo --- */
.login-logo { width: 72px; height: 72px; border-radius: 50%; display: block; margin: 0 auto 16px auto; object-fit: cover; box-shadow: 0 4px 10px rgba(3, 74, 152, 0.25); }

/* --- Dashboard --- */
.dash-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: var(--white); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); }
.stat-value { font-size: 30px; font-weight: 700; color: var(--primary-color); line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-gray); margin-top: 4px; font-weight: 500; }

/* --- Templates grid --- */
.templates-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }

/* --- Appointment status badges --- */
.badge.pending { background-color: #fef3c7; color: #92400e; }
.badge.confirmed { background-color: #d1fae5; color: #047857; }
.badge.cancelled { background-color: #fee2e2; color: #b91c1c; }

/* --- Mobile back button (hidden on desktop) --- */
#btn-chat-back { display: none; }

/* ═══════════════ MOBILE / PWA RESPONSIVE ═══════════════ */
@media (max-width: 768px) {
  body { overflow: auto; }
  .app-container { flex-direction: column; height: 100vh; }

  .sidebar {
    width: 100%; height: 60px; flex-direction: row; justify-content: center;
    order: 2; position: fixed; bottom: 0; left: 0; right: 0;
    padding: 0; box-shadow: 0 -4px 15px rgba(0,0,0,0.08);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: auto;
  }
  .sidebar-top, .sidebar-bottom { display: flex; flex-direction: row; align-items: center; margin: 0; flex-shrink: 0; }
  .sidebar-logo { display: none; }
  .nav-links { flex-direction: row; gap: 0; padding: 0; }
  .nav-item { padding: 8px 7px; font-size: 0; flex-shrink: 0; }
  .nav-item svg { width: 22px; height: 22px; }
  .nav-item .nav-label { display: none; }
  .nav-avatar { width: 26px; height: 26px; }

  .main-content { order: 1; flex: 1; overflow-y: auto; padding-bottom: 64px; }

  .templates-grid { grid-template-columns: 1fr; }
  .dash-stats-grid { grid-template-columns: repeat(2, 1fr); }

  .top-bar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .top-bar h2 { font-size: 18px; }
  .table-actions { flex-wrap: wrap; }
  .table-actions .spacer { display: none; }

  .modal-card { width: 92vw; max-height: 85vh; padding: 20px; }
  .login-card { width: 90vw; max-width: 360px; }

  /* Chat: show one column at a time, toggled via .mobile-show-* on chat-layout-3col */
  .chat-layout-3col { position: relative; }
  .chat-list-col, .chat-thread-col, .chat-profile-col { width: 100%; }
  .chat-layout-3col:not(.mobile-show-thread) .chat-thread-col { display: none; }
  .chat-layout-3col.mobile-show-thread .chat-list-col { display: none; }
  .chat-profile-col { position: fixed; inset: 0; z-index: 900; height: 100vh; }
  #btn-chat-back { display: inline-flex; margin-right: 8px; }
}
