/* ==========================================================================
   CODEORBIT — REUSABLE UI COMPONENTS
   Buttons, cards, form fields, modals, toasts, badges, progress bars, menus
   ========================================================================== */

/* ==========================================================================
   BUTTONS
   One crimson button per area (the main action). Everything else is outlined.
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 44px;
  padding: 0 20px;
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-full);
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border: 1px solid transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.btn-secondary,
.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-primary);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: var(--text-xs);
}

.btn-lg {
  min-height: 52px;
  padding: 0 28px;
  font-size: var(--text-base);
}

.btn-icon-only {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   CARDS: flat, 1px line, generous padding
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  min-width: 0;
  transition: border-color var(--transition-fast);
}

.card:hover {
  border-color: var(--border-hover);
}

.card-elevated {
  background: var(--bg-card-elevated);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  gap: var(--space-sm);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* ==========================================================================
   FORMS & INPUTS
   ========================================================================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-md);
}

.form-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label-required {
  color: var(--accent-text);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  outline: none;
  box-shadow: 0 0 0 3px var(--tint);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

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

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238F8F95' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

.form-select option {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Range slider */
.range-slider {
  flex: 1;
  accent-color: var(--primary);
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
}

.range-val-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--text-primary);
  min-width: 45px;
  text-align: right;
}

/* Tag Input */
.tag-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  min-height: 42px;
}

.tag-container:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--tint);
}

.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: var(--bg-card-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
}

.tag-remove-btn {
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
}

.tag-remove-btn:hover {
  color: var(--danger);
}

.tag-input-field {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: var(--text-sm);
  padding: 4px;
}

/* ==========================================================================
   BADGES & PILLS
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 500;
  padding: 3px 7px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.badge-primary {
  background: var(--primary);
  color: #ffffff;
  border: 1px solid var(--primary);
}

.badge-muted {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.badge-accent {
  background: transparent;
  color: var(--accent-text);
  border: 1px solid var(--accent-text);
}

.badge-warning {
  background: transparent;
  color: var(--warning);
  border: 1px solid var(--warning);
}

/* ==========================================================================
   PROGRESS BARS & GAUGES
   ========================================================================== */
.progress-bar-container {
  width: 100%;
  height: 4px;
  background-color: var(--border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--text-primary);
  transition: width 0.6s var(--ease-swiss);
  position: relative;
}

.progress-bar-fill.fill-primary {
  background: var(--primary);
}

.progress-bar-fill.fill-success {
  background: var(--success);
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

/* Open/close motion. Keyframes (not transitions) because the backdrop goes from
   display: none to flex in one step, and transitions never run across that. */
.modal-backdrop.active {
  display: flex;
  animation: modalFadeIn 0.2s ease-out both;
}

.modal-backdrop.active .modal-container {
  animation: modalRiseIn 0.34s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.modal-backdrop.closing {
  animation: modalFadeOut 0.16s ease-in both;
}

.modal-backdrop.closing .modal-container {
  animation: modalDropOut 0.16s ease-in both;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
}

@keyframes modalFadeOut {
  to {
    opacity: 0;
  }
}

@keyframes modalRiseIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
}

@keyframes modalDropOut {
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
}

.modal-container {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-container.modal-lg {
  max-width: 760px;
}

.modal-container.modal-sm {
  max-width: 440px;
}

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

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.modal-icon-badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-card-elevated);
}

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ==========================================================================
   TOAST NOTIFICATION SYSTEM
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  z-index: 300;
  pointer-events: none;
  max-width: 380px;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card-elevated);
  border: 1px solid var(--border);
  box-shadow:
    var(--shadow-lg),
    0 0 20px rgba(0, 0, 0, 0.4);
  animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  position: relative;
  overflow: hidden;
}

.toast.hiding {
  animation: slideOutToast 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideInToast {
  from {
    opacity: 0;
    transform: translateX(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes slideOutToast {
  to {
    opacity: 0;
    transform: translateX(40px) scale(0.95);
  }
}

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.toast-message {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast-close {
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast-success {
  border-left: 4px solid var(--success);
}
.toast-success .toast-icon {
  color: var(--success);
}

.toast-error {
  border-left: 4px solid var(--danger);
}
.toast-error .toast-icon {
  color: var(--danger);
}

.toast-warning {
  border-left: 4px solid var(--warning);
}
.toast-warning .toast-icon {
  color: var(--warning);
}

.toast-info {
  border-left: 4px solid var(--text-primary);
}
.toast-info .toast-icon {
  color: var(--text-primary);
}

/* "You earned a badge" toast */
.toast-achievement {
  border: 1px solid var(--accent-text);
  background: var(--bg-card-elevated);
}

.toast-achievement .toast-icon {
  color: var(--accent-text);
}

.toast-achievement .toast-title {
  color: var(--accent-text);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   MENUS (the "…" menu on skill cards)
   ========================================================================== */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow:
    var(--shadow-lg),
    0 0 20px rgba(0, 0, 0, 0.4);
  padding: 6px;
  min-width: 220px;
  z-index: 150;
  display: none;
  animation: fadeInDown 0.15s ease-out forwards;
}

.dropdown-menu.active {
  display: block;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background-color: var(--bg-card-elevated);
  color: var(--text-primary);
}

.dropdown-item.danger:hover {
  background-color: var(--danger-subtle);
  color: var(--danger);
}

.dropdown-divider {
  height: 1px;
  background-color: var(--border);
  margin: 4px 0;
}

/* ==========================================================================
   EMPTY STATES
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2xs);
}

.empty-state-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: var(--space-lg);
}

/* ==========================================================================
   FILTER BARS & CONTROLS
   ========================================================================== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.filter-left,
.filter-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
}

.search-box {
  position: relative;
  min-width: 240px;
}

.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.search-box input {
  padding-left: 36px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
}

.pill-btn {
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.pill-btn:hover {
  color: var(--text-primary);
}

.pill-btn.active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--text-inverse);
}

/* ==========================================================================
   STUDY SESSIONS LIST (grouped by day)
   ========================================================================== */
.timeline-date-group {
  margin-bottom: var(--space-xl);
  position: relative;
}

.timeline-date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}

.timeline-date-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-strong);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

.timeline-date-summary {
  font-size: 0.725rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.timeline-stream {
  position: relative;
  padding-left: 20px;
}

.timeline-stream::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: var(--border);
}

.activity-timeline-item {
  position: relative;
  margin-bottom: var(--space-md);
  transition: all var(--transition-fast);
}

.activity-timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 20px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-main);
  z-index: 2;
}

.activity-timeline-item:hover {
  transform: translateX(3px);
  border-color: var(--border-hover);
}

/* ==========================================================================
   GOAL CARDS: progress ring
   ========================================================================== */
.goal-ring-wrap {
  position: relative;
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.goal-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.goal-ring-bg {
  stroke: var(--border);
  stroke-width: 4;
  fill: none;
}

.goal-ring-fill {
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
  stroke: var(--accent-text);
  transition: stroke-dashoffset 0.6s ease;
}

.goal-ring-fill.fill-done {
  stroke: var(--success);
}

.goal-ring-text {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ==========================================================================
   SETTINGS SECTION NAVIGATION BAR
   ========================================================================== */
.settings-nav-bar {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-xl);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-xs);
  overflow-x: auto;
}

.settings-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.settings-nav-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.settings-nav-btn.active {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

/* ==========================================================================
   SKILL CARDS (Skills page)
   One loud thing per card: the percentage. Everything else is quieter
   (greys, normal-case labels, no mono digits) so the card does not glare.
   ========================================================================== */
.skill-item-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.skill-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

/* Category: plain small text instead of wide-spaced uppercase mono */
.skill-card-top .label-mono {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}

.skill-card-top-right {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
}

.skill-card-top-right .btn-icon-only {
  color: var(--text-muted);
}

.skill-card-id {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.skill-planet {
  flex: none;
  border-radius: 50%;
  background: var(--border-strong);
  border: 1px solid var(--text-muted);
}

.skill-item-card.is-done .skill-planet {
  background: var(--primary);
  border-color: var(--primary);
}

.skill-card-name {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.skill-card-name h3 {
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.skill-card-name span {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.skill-card-figure {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-sm);
}

.skill-pct {
  font-weight: 800;
  font-size: 2.75rem;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.skill-pct small {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-muted);
  margin-left: 2px;
}

.skill-steps {
  display: flex;
  gap: 6px;
}

.skill-steps .btn {
  min-width: 56px;
  min-height: 40px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-color: var(--border);
  border-radius: var(--radius-sm);
}

.skill-steps .btn:hover {
  color: var(--text-primary);
}

.skill-ticks {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
}

.skill-tick {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.skill-tick.is-on {
  background: var(--text-muted);
}

.skill-item-card.is-done .skill-tick.is-on {
  background: var(--primary);
}

/* ==========================================================================
   BADGE CARDS (Badges page)
   ========================================================================== */
.achievement-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.achievement-card:not(.is-earned) {
  opacity: 0.85;
}

.achievement-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.achievement-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.achievement-card.is-earned .achievement-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.achievement-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.achievement-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
}

.achievement-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border-light);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* Profile picture choices (Settings) */
.avatar-option-btn {
  overflow: hidden;
}

.avatar-option-btn.selected {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 2px var(--primary);
}
