/* ============================================================
   QRTask Reusable Components
   ============================================================ */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5625rem 1.125rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  box-shadow: 0 4px 14px rgba(99,102,241,0.35);
  color: var(--color-white);
  text-decoration: none;
}

.btn-secondary {
  background: var(--color-white);
  color: var(--color-neutral-700);
  border-color: var(--color-neutral-300);
}
.btn-secondary:hover {
  background: var(--color-neutral-50);
  border-color: var(--color-neutral-400);
  color: var(--color-neutral-800);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 4px 14px rgba(239,68,68,0.3);
  color: var(--color-white);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--color-neutral-600);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-neutral-100);
  color: var(--color-neutral-800);
  text-decoration: none;
}

.btn-success {
  background: var(--color-success);
  color: var(--color-white);
  border-color: var(--color-success);
}
.btn-success:hover {
  background: #059669;
  color: var(--color-white);
  text-decoration: none;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  min-height: 32px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.875rem 1.75rem;
  font-size: 1.0625rem;
  min-height: 52px;
  border-radius: var(--radius-lg);
}

.btn-icon {
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm {
  min-width: 32px;
  min-height: 32px;
  padding: 0.25rem;
}

.btn-full { width: 100%; }

/* ---- Card ---- */
.card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  border: 1px solid var(--color-neutral-200);
}
.card-sm  { padding: 0.875rem; border-radius: var(--radius-md); }
.card-lg  { padding: 1.75rem; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.badge-default  { background: var(--color-neutral-100); color: var(--color-neutral-600); }
.badge-locked   { background: var(--color-neutral-100); color: var(--color-neutral-500); }
.badge-unlocked { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-completed { background: var(--color-success-light); color: #065f46; }
.badge-remote   { background: var(--color-warning-light); color: #92400e; }
.badge-danger   { background: var(--color-danger-light); color: #991b1b; }
.badge-primary  { background: var(--color-primary-light); color: var(--color-primary-darker); }
.badge-success  { background: var(--color-success-light); color: #065f46; }
.badge-warning  { background: var(--color-warning-light); color: #92400e; }

/* ---- Form elements ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.form-group:last-child { margin-bottom: 0; }

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-neutral-700);
}
.form-label-required::after {
  content: ' *';
  color: var(--color-danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--color-neutral-800);
  background: var(--color-white);
  border: 1.5px solid var(--color-neutral-300);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  min-height: 44px;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
  outline: none;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--color-neutral-400); }
.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid { border-color: var(--color-danger); }
.form-input.is-invalid:focus,
.form-select.is-invalid:focus,
.form-textarea.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(239,68,68,0.15);
}

.form-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 fill='%2364748B' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-textarea-mono { font-family: 'Courier New', Courier, monospace; font-size: 0.875rem; }

.form-error {
  font-size: 0.8125rem;
  color: var(--color-danger);
  margin-top: 0.25rem;
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--color-neutral-500);
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ---- Toggle Switch ---- */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--color-neutral-300);
  border-radius: var(--radius-full);
  transition: background 0.2s ease;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-white);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
}
.toggle-switch input:checked + .toggle-track { background: var(--color-primary); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(20px); }
.toggle-label { font-size: 0.9375rem; font-weight: 500; color: var(--color-neutral-700); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: 1rem;
  animation: fade-in 0.15s ease;
}

.modal {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: 100%;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  animation: slide-up 0.2s ease;
}

.modal-sm { max-width: 380px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-neutral-200);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--color-neutral-900);
}
.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--color-neutral-100);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--color-neutral-500);
  transition: background 0.15s;
}
.modal-close:hover { background: var(--color-neutral-200); color: var(--color-neutral-800); }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-neutral-200);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ---- Spinner ---- */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--color-neutral-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }
.spinner-white { border-color: rgba(255,255,255,0.3); border-top-color: var(--color-white); }

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: var(--z-overlay);
}
.spinner-overlay p { color: var(--color-neutral-600); font-weight: 500; }

/* ---- Toast ---- */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
  width: calc(100vw - 2rem);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--color-neutral-400);
  animation: slide-in-right 0.25s ease;
  pointer-events: auto;
}
.toast-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-size: 0.9rem; font-weight: 600; color: var(--color-neutral-900); margin-bottom: 0.1rem; }
.toast-msg { font-size: 0.825rem; color: var(--color-neutral-600); }
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--color-neutral-400);
  padding: 0;
  line-height: 1;
}
.toast-close:hover { color: var(--color-neutral-700); }

.toast-success { border-left-color: var(--color-success); }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error   { border-left-color: var(--color-danger); }
.toast-error   .toast-icon { color: var(--color-danger); }
.toast-info    { border-left-color: var(--color-primary); }
.toast-info    .toast-icon { color: var(--color-primary); }
.toast-warning { border-left-color: var(--color-warning); }
.toast-warning .toast-icon { color: var(--color-warning); }

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-neutral-500);
}
.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}
.empty-state h3 { color: var(--color-neutral-600); margin-bottom: 0.5rem; font-size: 1.125rem; }
.empty-state p  { color: var(--color-neutral-500); font-size: 0.9rem; max-width: 300px; }

/* ---- Avatar ---- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.avatar-sm { width: 28px; height: 28px; font-size: 0.75rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1.1rem; }

/* ---- Progress bar ---- */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-neutral-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}
.progress-bar-fill.success { background: var(--color-success); }
.progress-bar-fill.warning { background: var(--color-warning); }

/* ---- Divider ---- */
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--color-neutral-400);
  font-size: 0.8125rem;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-neutral-200);
}

/* ---- Section title ---- */
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-neutral-500);
  margin-bottom: 0.625rem;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--color-neutral-200);
  gap: 0;
}
.tab-btn {
  padding: 0.625rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-neutral-500);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--color-neutral-800); }
.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}
.tab-content { display: none; padding-top: 1.25rem; }
.tab-content.active { display: block; }

/* ---- Animations ---- */
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-scale {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.05); }
}
@keyframes checkmark {
  0%   { stroke-dashoffset: 100; }
  100% { stroke-dashoffset: 0; }
}
@keyframes fade-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Alert ---- */
.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
}
.alert-info    { background: var(--color-primary-light); color: var(--color-primary-darker); }
.alert-success { background: var(--color-success-light); color: #065f46; }
.alert-warning { background: var(--color-warning-light); color: #92400e; }
.alert-danger  { background: var(--color-danger-light);  color: #991b1b; }
