/* Saberly — Components */

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 10px 18px; border-radius: var(--radius-btn);
  font-size: 14px; font-weight: 600;
  transition: all .15s ease; white-space: nowrap; border: 1px solid transparent;
}
.btn-primary { background: var(--indigo); color: var(--white); }
.btn-primary:hover { background: var(--indigo-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,70,229,.25); }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--indigo); color: var(--indigo); }
.btn-ghost { background: transparent; color: var(--navy); }
.btn-ghost:hover { background: var(--light); }
.btn-navy { background: var(--navy); color: var(--white); }
.btn-navy:hover { background: var(--navy-dark); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* ========== Chips / Pills / Badges ========== */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  font-size: 12.5px; font-weight: 500;
  background: var(--light); color: var(--navy); border: 1px solid var(--border);
}
.chip-indigo { background: var(--indigo-light); color: var(--indigo-dark); border-color: transparent; }
.chip-success { background: var(--success-light); color: #046C4E; border-color: transparent; }
.chip-warning { background: var(--warning-light); color: #92400E; border-color: transparent; }
.chip-danger { background: var(--danger-light); color: #B42318; border-color: transparent; }
.chip-navy { background: var(--navy); color: var(--white); border-color: transparent; }
.chip-dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.chip-live {
  background: var(--success-light); color: #046C4E; border: 0;
  font-weight: 600; letter-spacing: .05em; text-transform: uppercase; font-size: 11.5px;
}
.chip-live::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(18,183,106,.5); }
  50% { opacity: .7; transform: scale(1.2); box-shadow: 0 0 0 6px rgba(18,183,106,0); }
}

/* ========== Cards ========== */
.card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: var(--space-6);
}
.card-flat { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--space-6); }
.card-hover { transition: all .2s ease; cursor: pointer; }
.card-hover:hover { box-shadow: var(--shadow-elev); transform: translateY(-2px); border-color: var(--indigo-soft); }

/* ========== KPI Card ========== */
.kpi-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: var(--space-5) var(--space-6);
  position: relative;
}
.kpi-card .kpi-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--indigo-light); color: var(--indigo);
  margin-bottom: var(--space-3);
}
.kpi-card .kpi-value { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; letter-spacing: -0.02em; }
.kpi-card .kpi-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.kpi-card .kpi-delta { position: absolute; top: var(--space-5); right: var(--space-5); font-size: 12px; font-weight: 600; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* ========== Tables ========== */
.table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  background: var(--light); border-bottom: 1px solid var(--border);
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--navy); }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; transition: background .1s ease; }
.table tr.clickable:hover td { background: var(--light); }

/* ========== Progress bar ========== */
.bar {
  width: 100%; height: 8px; border-radius: var(--radius-pill);
  background: var(--light); overflow: hidden; position: relative;
}
.bar-fill { height: 100%; border-radius: var(--radius-pill); background: var(--indigo); transition: width .4s ease; }
.bar-fill.success { background: var(--success); }
.bar-fill.warning { background: var(--warning); }
.bar-fill.danger { background: var(--danger); }
.bar-fill.indigo { background: var(--indigo); }
.bar-sm { height: 6px; }
.bar-lg { height: 10px; }

/* ========== Quota bar (label + progress + % side-by-side) ========== */
.quota-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: var(--space-4); align-items: center; padding: var(--space-3) 0; }
.quota-row .q-label { font-size: 14px; font-weight: 500; }
.quota-row .q-pct { font-size: 14px; font-weight: 600; color: var(--navy); min-width: 44px; text-align: right; }

/* ========== Input ========== */
.input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 14px; color: var(--navy); background: var(--white);
  transition: border .15s ease;
}
.input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.input::placeholder { color: var(--muted-light); }
.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 40px; }
.input-with-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.textarea { min-height: 72px; resize: vertical; }

/* ========== AI Chat bubbles ========== */
.bubble { max-width: 82%; padding: 12px 16px; border-radius: 14px; font-size: 14px; line-height: 1.55; }
.bubble-ai { background: var(--indigo-light); color: var(--navy); border-bottom-left-radius: 4px; align-self: flex-start; }
.bubble-user { background: var(--light); color: var(--navy); border-bottom-right-radius: 4px; align-self: flex-end; border: 1px solid var(--border); }
.bubble-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }

/* ========== Stage chip (study progress) ========== */
.stage-chip { display: inline-flex; padding: 4px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; }
.stage-brief { background: #F3E8FF; color: #6B21A8; }
.stage-instrument { background: #DBEAFE; color: #1E40AF; }
.stage-field { background: var(--warning-light); color: #92400E; }
.stage-quality { background: var(--danger-light); color: #B42318; }
.stage-coding { background: var(--indigo-light); color: var(--indigo-dark); }
.stage-report { background: var(--success-light); color: #046C4E; }

/* ========== Avatars ========== */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--indigo-light); color: var(--indigo-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }

/* ========== Flag (quality) ========== */
.flag-card {
  display: grid; grid-template-columns: 10px 1fr auto;
  gap: var(--space-4); align-items: center;
  padding: var(--space-4) var(--space-5);
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-card); margin-bottom: var(--space-3);
  transition: border-color .15s ease;
}
.flag-card:hover { border-color: var(--border-strong); }
.flag-card .flag-rail { width: 4px; height: 32px; border-radius: 2px; }
.flag-card.flag-warn .flag-rail { background: var(--warning); }
.flag-card.flag-danger .flag-rail { background: var(--danger); }
.flag-card .flag-title { font-weight: 600; font-size: 14.5px; }
.flag-card .flag-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ========== Theme bar (coding) ========== */
.theme-row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); margin-bottom: var(--space-3); }
.theme-row .theme-label { font-size: 13.5px; font-weight: 500; margin-bottom: 4px; }
.theme-row .theme-count { font-size: 13px; color: var(--muted); font-weight: 600; }
.theme-row .theme-bar {
  height: 28px; border-radius: var(--radius-sm); background: var(--indigo);
  display: flex; align-items: center; justify-content: flex-end; padding: 0 10px;
  color: var(--white); font-size: 12px; font-weight: 600;
  grid-column: 1 / 3;
}

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27,42,74,.5);
  display: none; align-items: center; justify-content: center; z-index: 100;
  padding: var(--space-6);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius-card);
  max-width: 640px; width: 100%; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-pop);
}
.modal-header { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; }
.modal-body { padding: var(--space-6); }
.modal-close { padding: 6px; color: var(--muted); border-radius: 4px; }
.modal-close:hover { background: var(--light); color: var(--navy); }

/* ========== Alert inline ========== */
.alert { padding: var(--space-4); border-radius: var(--radius-card); border: 1px solid; display: flex; gap: var(--space-3); align-items: flex-start; }
.alert-danger { background: var(--danger-light); border-color: #FCA5A5; color: #7F1D1D; }
.alert-warning { background: var(--warning-light); border-color: #FCD34D; color: #78350F; }
.alert-info { background: var(--indigo-light); border-color: var(--indigo-soft); color: var(--indigo-dark); }
.alert-icon { flex-shrink: 0; margin-top: 2px; }
.alert-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.alert-text { font-size: 13.5px; }

/* ========== Tabs ========== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); }
.tab { padding: 10px 14px; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--navy); }
.tab.active { color: var(--indigo); border-bottom-color: var(--indigo); font-weight: 600; }
