/* ==========================================================================
   ISTQB CT-GenAI Master - Global Design System & Variables
   ========================================================================== */

:root {
  /* Color Palette - Light Theme (default matching user reference) */
  --bg-app: #f4f6fb;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-subtle: #f1f5f9;
  --bg-sidebar: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: #edf2f7;

  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --text-inverse: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;

  --success: #10b981;
  --success-hover: #059669;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;

  --error: #ef4444;
  --error-hover: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme Palette */
[data-theme="dark"] {
  --bg-app: #0b1120;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --bg-subtle: #172033;
  --bg-sidebar: #131d2f;
  --border-color: #334155;
  --border-subtle: #1e293b;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --text-inverse: #0f172a;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: rgba(59, 130, 246, 0.15);
  --primary-border: #1d4ed8;

  --success: #10b981;
  --success-hover: #34d399;
  --success-bg: rgba(16, 185, 129, 0.15);
  --success-border: rgba(16, 185, 129, 0.3);
  --success-text: #6ee7b7;

  --error: #f43f5e;
  --error-hover: #fb7185;
  --error-bg: rgba(244, 63, 94, 0.15);
  --error-border: rgba(244, 63, 94, 0.3);
  --error-text: #fda4af;

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-border: rgba(245, 158, 11, 0.3);
  --warning-text: #fcd34d;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  -webkit-font-smoothing: antialiased;
}

/* Header & Top Navigation */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-full);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Header Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ctrl-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--text-muted);
}

.lang-select {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

/* Main Layout Viewport */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.view-section {
  display: none;
  flex: 1;
  width: 100%;
}

.view-section.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease-out;
}

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

/* Generic Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-color);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-primary { background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary-border); }
.badge-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.badge-error { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.badge-neutral { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border-color); }

/* Common modal backdrop */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  max-width: 650px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform var(--transition-fast);
}

.modal-overlay.active .modal-container {
  transform: scale(1);
}

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

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  color: var(--text-main);
  background: var(--bg-subtle);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Glossary Cards Layout */
.glossary-view-container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 80px 20px;
}

.glossary-hero {
  margin-bottom: 24px;
}

.glossary-hero h1 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.glossary-filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.glo-filter-btn {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.glo-filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.grid-glossary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.glossary-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: all var(--transition-fast);
}

.glossary-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
}

.glo-card-top {
  margin-bottom: 8px;
}

.glo-badge {
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-subtle);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.glo-term-en {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.glo-term-vn {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 10px;
}

.glo-exp {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Stats View Layout */
.stats-view-container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 80px 20px;
}

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

.stat-metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-metric-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.stat-metric-lbl {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ==========================================================================
   MOBILE BOTTOM NAVIGATION & APP-LIKE CONTROLS
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.07);
  z-index: 1000;
  padding: 4px 12px calc(4px + env(safe-area-inset-bottom, 0px)) 12px;
  justify-content: space-around;
  align-items: center;
}

[data-theme="dark"] .mobile-bottom-nav {
  background: rgba(15, 23, 42, 0.95);
  border-top-color: #334155;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mobile-nav-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item.active .mobile-nav-icon {
  transform: scale(1.18) translateY(-1px);
}

/* --------------------------------------------------------------------------
   RESPONSIVE LAYOUT & AUTO-DEVICE ADAPTATIONS
   -------------------------------------------------------------------------- */
@media (max-width: 768px), (pointer: coarse) and (max-width: 900px) {
  body {
    padding-bottom: calc(65px + env(safe-area-inset-bottom, 0px));
  }

  .app-header {
    height: 56px;
    padding: 0 12px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .brand-title {
    font-size: 0.92rem;
    font-weight: 800;
  }

  .brand-subtitle {
    display: none;
  }

  .nav-tabs {
    display: none !important;
  }

  .header-controls {
    gap: 6px;
  }

  .lang-select {
    padding: 4px 6px;
    font-size: 0.78rem;
    max-width: 92px;
  }

  .ctrl-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .user-profile-chip {
    padding: 3px 8px 3px 3px;
  }

  .user-avatar-circle {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
  }

  .user-chip-name {
    max-width: 75px;
    font-size: 0.75rem;
  }

  .badge-expiry {
    display: none;
  }

  /* Input fields: 16px to prevent iOS auto-zoom */
  input[type="text"],
  input[type="password"],
  input[type="tel"],
  input[type="email"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Glossary Grid on Mobile */
  .grid-glossary {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .glossary-view-container {
    padding: 16px 12px 40px 12px;
  }

  .glossary-hero h1 {
    font-size: 1.35rem;
  }

  /* Stats Grid on Mobile */
  .stats-view-container {
    padding: 16px 12px 40px 12px;
  }

  .stats-grid-summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-metric-card {
    padding: 14px 10px;
  }

  .stat-metric-val {
    font-size: 1.5rem;
  }
}

