/* ===================================================
   Vaachan – Shared Design System & Responsive Framework
   =================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --ink: #14203B;
  --ink-soft: #4A5578;
  --ink-muted: #8A94AB;
  --paper: #FBF7EE;
  --paper-panel: #FFFFFF;
  --paper-hover: #F5F1E8;
  --line: #E4DCC8;
  --line-soft: rgba(228,220,200,0.5);
  
  --marigold: #E8A33D;
  --marigold-deep: #C9791B;
  --marigold-light: rgba(232,163,61,0.12);
  
  --indigo: #1B2A4A;
  --indigo-soft: #2C3D63;
  --indigo-light: rgba(27,42,74,0.08);
  
  --coral: #D6584F;
  --coral-light: rgba(214,88,79,0.1);
  
  --mint: #4F9B72;
  --mint-light: rgba(79,155,114,0.1);
  
  --sky: #3E7CB1;
  --sky-light: rgba(62,124,177,0.1);
  
  --shadow-xs: 0 1px 4px rgba(20,32,59,0.06);
  --shadow-sm: 0 2px 8px -2px rgba(20,32,59,0.08);
  --shadow: 0 8px 24px -8px rgba(20,32,59,0.14);
  --shadow-lg: 0 16px 40px -12px rgba(20,32,59,0.20);
  
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: all 0.12s ease-out;

  /* Safe Area Insets for Mobile / Notches */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* ---------- Global Resets & Mobile Ergonomics ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  overflow-x: hidden;
  max-width: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100%;
  min-height: 100vh;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding-left: var(--sal);
  padding-right: var(--sar);
}

/* ---------- Layout & Grid Containers ---------- */
.page-wrapper {
  padding-bottom: calc(60px + var(--sab));
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-header {
  padding: 24px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

.page-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--indigo);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-2col-wide { display: grid; grid-template-columns: 1.8fr 1fr; gap: 24px; }
.grid-2col-narrow { display: grid; grid-template-columns: 1fr 1.6fr; gap: 24px; }
.grid-3col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4col { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }

/* Responsive Grid Breakpoints */
@media (max-width: 1024px) {
  .grid-4col { grid-template-columns: repeat(2, 1fr); }
  .grid-3col { grid-template-columns: repeat(2, 1fr); }
  .grid-2col-wide, .grid-2col-narrow { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .grid-2col, .grid-2col-wide, .grid-2col-narrow, .grid-3col, .grid-4col {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .container {
    padding: 0 14px;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .form-row .form-col {
    margin-bottom: 12px;
  }
  .form-row .form-col:last-child {
    margin-bottom: 0;
  }
}

/* ---------- Cards & Panels ---------- */
.card {
  background: var(--paper-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.section-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--indigo);
  margin: 0 0 6px 0;
}

.section-desc {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 18px;
  line-height: 1.55;
}

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

.stat-card {
  background: var(--paper-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--marigold);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stat-icon.indigo { background: var(--indigo-light); color: var(--indigo); }
.stat-icon.marigold { background: var(--marigold-light); color: var(--marigold-deep); }
.stat-icon.mint { background: var(--mint-light); color: var(--mint); }
.stat-icon.coral { background: var(--coral-light); color: var(--coral); }
.stat-icon.sky { background: var(--sky-light); color: var(--sky); }

.stat-val {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--indigo);
  line-height: 1;
}

.stat-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* ---------- Forms & Interactive Elements ---------- */
.field-group {
  margin-bottom: 16px;
}

.field-group label, label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 7px;
  letter-spacing: 0.01em;
}

.form-row {
  display: flex;
  gap: 14px;
}

.form-row .form-col {
  flex: 1;
  min-width: 0;
}

/* Mobile-friendly Inputs */
.text-input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--paper);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  color: var(--ink);
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
  min-height: 44px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1.5 1.5l4.5 4.5 4.5-4.5' stroke='%234A5578' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  cursor: pointer;
}

.text-input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--marigold);
  background: var(--paper-panel);
  box-shadow: 0 0 0 3.5px rgba(232,163,61,0.18);
}

textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

/* ---------- Buttons & Touch Hitboxes ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  min-height: 44px;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(140deg, var(--marigold), var(--marigold-deep));
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(201,121,27,0.5);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px -4px rgba(201,121,27,0.65);
  transform: translateY(-1px);
}

.btn-admin {
  background: linear-gradient(140deg, var(--indigo-soft), var(--indigo));
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(27,42,74,0.45);
}

.btn-admin:hover:not(:disabled) {
  box-shadow: 0 6px 20px -4px rgba(27,42,74,0.65);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--ink-soft);
  color: var(--ink);
  background: var(--paper-hover);
}

.btn-danger {
  background: var(--coral);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #c04840;
}

.btn-success {
  background: var(--mint);
  color: #fff;
}

.btn-sm {
  font-size: 0.82rem;
  padding: 6px 13px;
  min-height: 36px;
  border-radius: var(--radius-xs);
}

.btn-lg {
  font-size: 1.1rem;
  padding: 14px 28px;
  min-height: 50px;
  border-radius: var(--radius);
}

.btn-full {
  width: 100%;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 11px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-mint { background: var(--mint-light); color: #236544; border: 1px solid rgba(79,155,114,0.28); }
.badge-coral { background: var(--coral-light); color: #9e3931; border: 1px solid rgba(214,88,79,0.28); }
.badge-marigold { background: var(--marigold-light); color: var(--marigold-deep); border: 1px solid rgba(232,163,61,0.28); }
.badge-indigo { background: var(--indigo-light); color: var(--indigo); border: 1px solid rgba(27,42,74,0.18); }
.badge-sky { background: var(--sky-light); color: var(--sky); border: 1px solid rgba(62,124,177,0.25); }

/* ---------- Smooth Tables & Horizontal Scrolling ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  position: relative;
  background: var(--paper-panel);
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 580px; /* Ensures columns never get squished into vertical 1-word towers! */
}

.list-table thead {
  background: var(--paper);
}

.list-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  border-bottom: 1.5px solid var(--line);
  white-space: nowrap;
}

.list-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  white-space: nowrap; /* Prevents text and names from breaking awkwardly into vertical towers */
}

.list-table tr:last-child td {
  border-bottom: none;
}

.list-table tbody tr {
  transition: background 0.12s ease;
}

.list-table tbody tr:hover {
  background: var(--paper-hover);
}

.roster-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 580px;
}
.roster-table th, .roster-table td {
  white-space: nowrap;
}

.empty-row td {
  text-align: center;
  padding: 36px 16px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  white-space: normal;
}

/* ---------- Alerts ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert-success { background: var(--mint-light); color: #236544; border: 1px solid rgba(79,155,114,0.3); }
.alert-danger { background: var(--coral-light); color: #9e3931; border: 1px solid rgba(214,88,79,0.3); }
.alert-warning { background: var(--marigold-light); color: var(--marigold-deep); border: 1px solid rgba(232,163,61,0.3); }
.alert-info { background: var(--sky-light); color: var(--sky); border: 1px solid rgba(62,124,177,0.3); }

/* ---------- List Groups ---------- */
.list-group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-panel);
  overflow: hidden;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.12s ease;
}

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

.list-item:hover {
  background: var(--paper-hover);
}

.list-item-meta {
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-top: 3px;
}

/* ---------- Dropzones ---------- */
.csv-dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  background: var(--paper);
  cursor: pointer;
  transition: var(--transition);
}

.csv-dropzone:hover {
  border-color: var(--marigold);
  background: rgba(232,163,61,0.06);
}

.solid-icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  vertical-align: -0.16em;
}

.solid-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.solid-icon-lg {
  width: 2.2rem;
  height: 2.2rem;
  margin: 0 auto 8px;
  color: var(--marigold-deep);
}

/* ---------- Heatmap Module ---------- */
.heatmap-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

.heatmap-table {
  border-collapse: separate;
  border-spacing: 6px;
  min-width: 440px;
  width: 100%;
}

.heatmap-table th {
  font-family: 'Baloo 2', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  padding: 6px 8px;
}

.heatmap-table th.row-hd {
  text-align: left;
  color: var(--indigo);
  font-size: 0.92rem;
  padding-right: 12px;
  position: sticky;
  left: 0;
  background: var(--paper-panel);
  z-index: 2;
}

.heatmap-cell {
  border-radius: 10px;
  padding: 12px 6px;
  text-align: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  cursor: default;
}

.heatmap-cell:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow);
}

.heatmap-cell .c-count {
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.75;
  margin-top: 2px;
  display: block;
}

.heatmap-none { background: #F2F2F5; color: var(--ink-soft); border: 1px solid #E4E4E9; }
.heatmap-low  { background: #FBECEA; color: #9B3830; border: 1px solid rgba(214,88,79,0.25); }
.heatmap-mid  { background: #FEF5E7; color: #9A5D10; border: 1px solid rgba(232,163,61,0.25); }
.heatmap-high { background: #EDF6F1; color: #2E6848; border: 1px solid rgba(79,155,114,0.25); }

/* ---------- Passage Cards ---------- */
.passage-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--paper-panel);
  margin-bottom: 14px;
  transition: var(--transition);
}

.passage-card:hover {
  border-color: var(--marigold);
  box-shadow: var(--shadow-sm);
}

.passage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.passage-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--indigo);
}

.passage-meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.passage-body {
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.7;
  max-height: 80px;
  overflow: hidden;
  position: relative;
}

.passage-body::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28px;
  background: linear-gradient(transparent, var(--paper-panel));
}

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

/* ---------- Toast Notifications ---------- */
#toast-container {
  position: fixed;
  bottom: calc(24px + var(--sab));
  right: calc(24px + var(--sar));
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--indigo);
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  pointer-events: auto;
  animation: toastSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(8px);
}

.toast.toast-success { background: #2D6E4F; border-left: 4px solid var(--mint); }
.toast.toast-error   { background: #9E3931; border-left: 4px solid var(--coral); }
.toast.toast-warning { background: #B26A18; border-left: 4px solid var(--marigold); }
.toast.toast-info    { background: var(--indigo); border-left: 4px solid var(--sky); }

@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.divider { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-soft); }

/* Logo Layouts */
.logo-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}

.logo-row img {
  height: 56px;
  max-width: 45%;
  object-fit: contain;
}

/* ---------- Mobile & Tablet Responsive Engine ---------- */
@media (max-width: 768px) {
  html { font-size: 15.5px; }
  .page-wrapper { padding-bottom: calc(40px + var(--sab)); }
  .container { padding-left: 14px; padding-right: 14px; }
  .page-header { padding: 18px 0 14px; margin-bottom: 18px; }
  .page-title { font-size: 1.45rem; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .card { border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
  .section-title { font-size: 1.15rem; }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 18px;
  }
  
  .stat-card {
    padding: 14px 14px;
    gap: 10px;
  }
  
  .stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 1.15rem;
  }
  
  .stat-val { font-size: 1.65rem; }
  .stat-label { font-size: 0.68rem; }
  
  .btn { min-height: 44px; padding: 10px 16px; font-size: 0.92rem; }
  .btn-lg { min-height: 48px; padding: 12px 20px; font-size: 1rem; }
  
  .list-item { align-items: flex-start; gap: 10px; padding: 12px; }
  .passage-card { padding: 14px; }
  .passage-header { flex-direction: column; }
  .passage-actions { width: 100%; }
  .passage-actions .btn { flex: 1; }
  .csv-dropzone { padding: 22px 14px; }
  
  #toast-container {
    bottom: calc(16px + var(--sab));
    right: 14px;
    left: 14px;
  }
  
  .toast {
    max-width: none;
    width: 100%;
  }
  
  .list-table, .roster-table { min-width: 560px; }
}

@media (max-width: 480px) {
  html { font-size: 15px; }
  .logo-row img { height: 46px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 12px 10px; }
  .stat-val { font-size: 1.5rem; }
  .stat-label { font-size: 0.64rem; letter-spacing: 0.04em; }
  .btn { font-size: 0.88rem; }
  .badge { font-size: 0.7rem; padding: 3px 8px; }
  .card { padding: 16px 14px; border-radius: 14px; }
}
