/**
 * Here - Component Library
 * 
 * Advanced UI Components for Mobile-First Experience
 */

/* ============================================
   MODAL / DIALOG
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  z-index: var(--z-modal);
  transform: translateY(100%);
  transition: transform var(--transition-slow) cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-area-bottom);
}

.modal.active {
  transform: translateY(0);
}

/* Centered Modal (for tablets/desktop) */
@media (min-width: 640px) {
  .modal.modal-centered {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    width: 90%;
    max-width: 480px;
    border-radius: var(--radius-2xl);
    max-height: 85vh;
  }
  
  .modal.modal-centered.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--neutral-300);
  border-radius: var(--radius-full);
  margin: var(--space-3) auto;
  flex-shrink: 0;
}

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

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

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--neutral-100);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--neutral-200);
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
}

.modal-footer .btn {
  flex: 1;
}

/* ============================================
   BOTTOM SHEET
   ============================================ */

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  z-index: var(--z-modal);
  transform: translateY(100%);
  transition: transform var(--transition-slow) cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: var(--safe-area-bottom);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

.bottom-sheet.active {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--neutral-300);
  border-radius: var(--radius-full);
  margin: var(--space-3) auto;
}

.bottom-sheet-content {
  padding: var(--space-4);
  padding-top: 0;
}

/* Action Sheet */
.action-sheet {
  padding: var(--space-2);
}

.action-sheet-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  text-decoration: none;
  transition: background var(--transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: var(--text-base);
}

.action-sheet-item:hover {
  background: var(--neutral-50);
}

.action-sheet-item.danger {
  color: var(--danger-500);
}

.action-sheet-divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--space-2) 0;
}

.action-sheet-cancel {
  margin-top: var(--space-2);
  background: var(--neutral-100);
  border-radius: var(--radius-lg);
}

.action-sheet-cancel .action-sheet-item {
  justify-content: center;
  font-weight: var(--font-semibold);
}

/* ============================================
   TABS
   ============================================ */

.tabs {
  display: flex;
  background: var(--neutral-100);
  border-radius: var(--radius-lg);
  padding: var(--space-1);
}

.tab {
  flex: 1;
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.tab.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Scrollable Tabs */
.tabs-scrollable {
  display: flex;
  overflow-x: auto;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  margin: 0 calc(var(--space-4) * -1);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs-scrollable::-webkit-scrollbar {
  display: none;
}

.tabs-scrollable .tab {
  flex: none;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.tabs-scrollable .tab.active {
  background: var(--primary-500);
  color: var(--text-inverse);
  border-color: var(--primary-500);
}

/* ============================================
   SWITCH / TOGGLE
   ============================================ */

.switch {
  position: relative;
  width: 52px;
  height: 32px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--neutral-300);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 26px;
  width: 26px;
  left: 3px;
  bottom: 3px;
  background: var(--surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.switch input:checked + .switch-slider {
  background: var(--primary-500);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch-slider {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* ============================================
   CHECKBOX & RADIO
   ============================================ */

.checkbox,
.radio {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.checkbox input,
.radio input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.checkbox-mark,
.radio-mark {
  width: 22px;
  height: 22px;
  border: 2px solid var(--neutral-300);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.checkbox-mark {
  border-radius: var(--radius-sm);
}

.radio-mark {
  border-radius: var(--radius-full);
}

.checkbox input:checked ~ .checkbox-mark,
.radio input:checked ~ .radio-mark {
  background: var(--primary-500);
  border-color: var(--primary-500);
}

.checkbox-mark::after {
  content: '';
  width: 6px;
  height: 10px;
  border: solid var(--surface);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform var(--transition-fast);
}

.checkbox input:checked ~ .checkbox-mark::after {
  transform: rotate(45deg) scale(1);
}

.radio-mark::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--surface);
  transform: scale(0);
  transition: transform var(--transition-fast);
}

.radio input:checked ~ .radio-mark::after {
  transform: scale(1);
}

/* ============================================
   CHIPS
   ============================================ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background: var(--neutral-100);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip:hover {
  background: var(--neutral-200);
}

.chip.active {
  background: var(--primary-100);
  border-color: var(--primary-300);
  color: var(--primary-700);
}

.chip-remove {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--neutral-300);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  margin-left: var(--space-1);
}

/* ============================================
   ACCORDION
   ============================================ */

.accordion {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.accordion-item {
  border-bottom: 1px solid var(--border-color);
}

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

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-4);
  background: var(--surface);
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.accordion-header:hover {
  background: var(--neutral-50);
}

.accordion-icon {
  transition: transform var(--transition-fast);
}

.accordion-item.active .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow) ease-out;
  background: var(--neutral-50);
}

.accordion-item.active .accordion-content {
  max-height: 500px;
}

.accordion-body {
  padding: var(--space-4);
  padding-top: 0;
}

/* ============================================
   TOOLTIP
   ============================================ */

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  padding: var(--space-2) var(--space-3);
  background: var(--neutral-800);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: var(--z-tooltip);
}

.tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--neutral-800);
}

.tooltip:hover .tooltip-content,
.tooltip:focus-within .tooltip-content {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

/* ============================================
   DATE/TIME PICKER STYLING
   ============================================ */

.datetime-picker {
  position: relative;
}

.datetime-picker input {
  padding-right: 44px;
}

.datetime-picker-icon {
  position: absolute;
  right: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

/* ============================================
   SEGMENTED CONTROL
   ============================================ */

.segmented-control {
  display: flex;
  background: var(--neutral-100);
  border-radius: var(--radius-lg);
  padding: 3px;
  position: relative;
}

.segmented-control::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  width: calc(50% - 3px);
  background: var(--surface);
  border-radius: calc(var(--radius-lg) - 2px);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base);
  z-index: 0;
}

.segmented-control.right::before {
  transform: translateX(100%);
}

.segmented-option {
  flex: 1;
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color var(--transition-fast);
}

.segmented-option.active {
  color: var(--text-primary);
}

/* ============================================
   DROPDOWN MENU
   ============================================ */

.dropdown {
  position: relative;
}

.dropdown-trigger {
  cursor: pointer;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all var(--transition-fast);
  z-index: var(--z-dropdown);
}

.dropdown.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: background var(--transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
}

.dropdown-item:hover {
  background: var(--neutral-50);
}

.dropdown-item.danger {
  color: var(--danger-500);
}

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

/* ============================================
   CHECK-IN BUTTON (Special Component)
   ============================================ */

.checkin-button {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-400) 0%, var(--primary-600) 100%);
  border: none;
  color: var(--text-inverse);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-shadow: 
    0 10px 30px rgba(37, 99, 235, 0.3),
    0 0 0 0 rgba(37, 99, 235, 0.5);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.checkin-button::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-300), var(--primary-600), var(--primary-300));
  z-index: -1;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.checkin-button:hover:not(:disabled) {
  transform: scale(1.03);
  box-shadow: 
    0 15px 40px rgba(37, 99, 235, 0.35),
    0 0 0 8px rgba(37, 99, 235, 0.15);
}

.checkin-button:hover:not(:disabled)::before {
  opacity: 1;
  animation: rotate 2s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.checkin-button:active:not(:disabled) {
  transform: scale(0.98);
}

.checkin-button:disabled {
  background: var(--neutral-300);
  cursor: not-allowed;
  box-shadow: none;
}

.checkin-button-icon {
  font-size: 3rem;
}

.checkin-button-text {
  font-size: var(--text-lg);
}

/* ============================================
   CALENDAR DATE SELECTOR
   ============================================ */

.calendar-strip {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-3) var(--space-4);
  margin: 0 calc(var(--space-4) * -1);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.calendar-strip::-webkit-scrollbar {
  display: none;
}

.calendar-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 64px;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.calendar-day.active {
  background: var(--primary-500);
  color: var(--text-inverse);
}

.calendar-day.today {
  border-color: var(--primary-500);
}

.calendar-day-name {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
}

.calendar-day.active .calendar-day-name {
  color: var(--primary-100);
}

.calendar-day-number {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

/* ============================================
   NOTIFICATION DOT
   ============================================ */

.notification-dot {
  position: relative;
}

.notification-dot::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 8px;
  background: var(--danger-500);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface);
}

.notification-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--danger-500);
  color: var(--text-inverse);
  font-size: 10px;
  font-weight: var(--font-bold);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}

/* ============================================
   SWIPE ACTIONS
   ============================================ */

.swipe-container {
  position: relative;
  overflow: hidden;
}

.swipe-content {
  transition: transform var(--transition-base);
  background: var(--surface);
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

.swipe-action {
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  font-weight: var(--font-medium);
}

.swipe-action.delete {
  background: var(--danger-500);
}

.swipe-action.edit {
  background: var(--primary-500);
}

