/* LivesGuide Overseas — Layout System */

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--surface-secondary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--brand-dark); }

img { max-width: 100%; height: auto; }
svg { display: block; }

/* ── App Shell (Desktop Three-Column) ── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--chat-panel-width);
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--transition-base);
}

/* ── Top Header ── */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-sticky);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
}

.header-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--brand-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
  font-weight: 700;
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
}

.app-header-logo svg { width: 32px; height: 32px; }

.app-header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.app-header-nav a {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.app-header-nav a:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}
.app-header-nav a.active {
  color: var(--brand);
  background: var(--info-light);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ── Left Sidebar ── */
.app-sidebar {
  grid-row: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: var(--z-modal-backdrop);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  gap: var(--space-2);
  flex: 1;
}

.sidebar-section {
  margin-bottom: var(--space-4);
}

.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
}
.sidebar-link:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}
.sidebar-link.active {
  background: var(--info-light);
  color: var(--brand);
  font-weight: 600;
}
.sidebar-link-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-stage-badge {
  margin-top: auto;
  padding: var(--space-3);
  background: var(--brand-gradient);
  border-radius: var(--radius-lg);
  color: var(--text-inverse);
  text-align: center;
}
.sidebar-stage-badge .label {
  font-size: var(--text-xs);
  opacity: 0.8;
}
.sidebar-stage-badge .value {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-top: var(--space-1);
}

/* ── Main Content Area ── */
.app-main {
  grid-row: 2;
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--surface-secondary);
}

.page-header {
  margin-bottom: var(--space-6);
}
.page-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Right Chat Panel ── */
.app-chat-panel {
  grid-row: 2;
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-panel-header h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}
.chat-panel-header .status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--success);
}
.chat-panel-header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.chat-message {
  display: flex;
  gap: var(--space-3);
  max-width: 85%;
}
.chat-message.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-message.advisor { align-self: flex-start; }

.chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--text-sm);
  font-weight: 600;
  flex-shrink: 0;
}
.chat-message.user .chat-message-avatar {
  background: var(--surface-tertiary);
  color: var(--text-secondary);
}

.chat-message-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.chat-message.advisor .chat-message-bubble {
  background: var(--surface-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
}
.chat-message.user .chat-message-bubble {
  background: var(--brand);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-input-area {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chat-input-row {
  display: flex;
  gap: var(--space-2);
}
.chat-input-row input {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition-fast);
}
.chat-input-row input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-voice-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.chat-voice-btn:hover {
  background: var(--surface-tertiary);
  border-color: var(--brand);
}

.chat-quick-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.chat-quick-btn {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.chat-quick-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--info-light);
}

/* ── Bottom Tab Bar (Mobile) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: var(--z-sticky);
  justify-content: space-around;
  align-items: center;
  padding: 0 var(--space-2);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  text-decoration: none;
}
.bottom-nav-item.active {
  color: var(--brand);
}
.bottom-nav-item svg {
  width: 24px;
  height: 24px;
}

/* ── Floating Chat Button (Mobile) ── */
.floating-chat-btn {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--brand-gradient);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  font-size: 24px;
  z-index: var(--z-modal);
  transition: transform var(--transition-fast);
}
.floating-chat-btn:hover {
  transform: scale(1.1);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) 1fr;
  }
  .app-chat-panel {
    display: none;
  }
  .app-chat-panel.open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    grid-column: 1 / -1;
    grid-row: 1 / -1;
  }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: 64px;
  }
  .app-sidebar {
    position: fixed;
    left: -280px;
    top: var(--header-height);
    bottom: 0;
    width: 280px;
    z-index: var(--z-modal);
    transition: left var(--transition-base);
    box-shadow: var(--shadow-xl);
  }
  .app-sidebar.open {
    left: 0;
  }
  .app-sidebar.open .sidebar-overlay {
    display: block;
  }
  .app-header-nav { display: none; }
  .app-header { padding: 0 var(--space-4); }
  .app-main { padding: var(--space-4); }
  .bottom-nav { display: flex; }
  .floating-chat-btn { display: flex; }
  
  .page-title {
    font-size: var(--text-2xl);
  }
}

/* ── Utility Classes ── */
.page-container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  width: 100%;
}

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  transition: box-shadow var(--transition-base);
}
.card:hover {
  box-shadow: var(--shadow-md);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  line-height: 1;
}
.btn-primary {
  background: var(--brand);
  color: white;
}
.btn-primary:hover {
  background: var(--brand-dark);
  box-shadow: var(--shadow-md);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--surface-tertiary);
  border-color: var(--text-muted);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--surface-tertiary);
  color: var(--text-primary);
}
.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
}
.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-base);
}

/* ── Inputs ── */
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
}
.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.input-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
}
.badge-brand { background: var(--info-light); color: var(--brand); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }

/* ── Toast / Notification ── */
.toast {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  animation: slideInRight 0.3s ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-2xl);
  padding: var(--space-8);
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}