/**
 * iOS-Style Card Design System
 * Enhanced Work Order Cards with Visual Hierarchy
 * October 2025
 */

/* === CARD-BASED LAYOUT === */
@media (max-width: 767px) {
  /* Work Order Card Container */
  .work-order-item {
    background: white;
    border-radius: 12px;
    margin: 12px 8px;
    padding: 0;
    box-shadow: var(--shadow-sm-layered, 0 1px 3px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.08));
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: all var(--transition-speed, 0.2s) var(--transition-ease, cubic-bezier(0.4, 0, 0.2, 1));
    position: relative;
    overflow: hidden;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .work-order-item:active {
    transform: scale(0.98);
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.12);
  }

  /* Priority Indicator - Left Border */
  .work-order-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #C7C7CC; /* Default gray */
  }

  /* Priority Colors - Binary System (Emergency Only) */
  .work-order-item[data-urgency="1"]::before,
  .work-order-item[data-emergency="true"]::before,
  .work-order-item.priority-emergency::before {
    background: #FF3B30; /* iOS Red - Emergency Only */
    box-shadow: 0 0 8px rgba(255, 59, 48, 0.3);
  }
  /* Normal priority work orders have default gray indicator */

  /* Card Header */
  .work-order-header {
    padding: 12px 16px 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }

  /* Ticket ID & Title */
  .work-order-title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: #000;
    line-height: 1.3;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
  }

  .work-order-id {
    font-size: 12px;
    color: #8E8E93;
    font-weight: 500;
    margin-bottom: 2px;
  }

  /* Status Chip */
  .status-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
  }

  /* Status Colors - Using Design Refresh Pastel System */
  .status-chip.status-pending,
  .status-chip.status-new {
    background: var(--status-pending-bg, rgba(255, 149, 0, 0.15));
    color: var(--status-pending-text, #FF9500);
  }

  .status-chip.status-active,
  .status-chip.status-in-progress {
    background: var(--status-in-progress-bg, rgba(0, 122, 255, 0.15));
    color: var(--status-in-progress-text, #007AFF);
  }

  .status-chip.status-assigned {
    background: var(--status-assigned-bg, rgba(88, 86, 214, 0.15));
    color: var(--status-assigned-text, #5856D6);
  }

  .status-chip.status-resolved,
  .status-chip.status-completed {
    background: var(--status-resolved-bg, rgba(52, 199, 89, 0.15));
    color: var(--status-resolved-text, #34C759);
  }

  .status-chip.status-cancelled {
    background: var(--status-cancelled-bg, rgba(142, 142, 147, 0.15));
    color: var(--status-cancelled-text, #8E8E93);
  }

  /* Status Icon */
  .status-chip i {
    font-size: 10px;
  }

  /* Card Body */
  .work-order-body {
    padding: 0 16px 12px 20px;
  }

  /* Assignment Info with Avatar */
  .work-order-assignment {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .assignment-avatar {
    width: 24px;
    height: 24px;
    border-radius: 12px;
    background: #007AFF;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
  }

  .assignment-avatar.unassigned {
    background: #C7C7CC;
  }

  .assignment-info {
    flex: 1;
    font-size: 13px;
    color: #3C3C43;
  }

  .assignment-name {
    font-weight: 500;
  }

  /* Location & Time */
  .work-order-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: #8E8E93;
    margin-bottom: 8px;
  }

  .meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .meta-item i {
    font-size: 11px;
    color: #C7C7CC;
  }

  /* Issue Preview */
  .work-order-preview {
    font-size: 13px;
    color: #3C3C43;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
  }

  /* Attachment Indicator */
  .attachment-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 24px;
    height: 24px;
    background: rgba(0, 122, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #007AFF;
    font-size: 12px;
  }

  /* Urgency Badge */
  .urgency-badge {
    position: absolute;
    top: 12px;
    right: 44px;
    padding: 2px 8px;
    background: #FF3B30;
    color: white;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    animation: pulse-urgent 2s infinite;
  }

  @keyframes pulse-urgent {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
  }

  /* Swipe Actions Container */
  .work-order-item {
    position: relative;
    overflow: visible;
  }

  .swipe-actions {
    position: absolute;
    top: 0;
    right: -200px;
    height: 100%;
    display: flex;
    align-items: stretch;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .work-order-item.swiped-left .swipe-actions {
    transform: translateX(-200px);
  }

  .swipe-action {
    width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    padding: 8px;
    transition: width 0.2s ease;
  }

  .swipe-action:active {
    width: 100px;
  }

  .swipe-action i {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .swipe-action span {
    font-size: 11px;
    font-weight: 600;
  }

  /* Swipe Action Colors */
  .swipe-action.action-complete {
    background: #34C759;
  }

  .swipe-action.action-assign {
    background: #007AFF;
  }

  .swipe-action.action-details {
    background: #5856D6;
  }

  .swipe-action.action-delete {
    background: #FF3B30;
  }
}

/* === LOADING SKELETON === */
@media (max-width: 767px) {
  .skeleton-card {
    background: white;
    border-radius: 12px;
    margin: 12px 8px;
    padding: 12px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
  }

  .skeleton-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #E5E5EA;
  }

  .skeleton {
    background: linear-gradient(90deg, #F2F2F7 25%, #E5E5EA 50%, #F2F2F7 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
  }

  @keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  .skeleton-title {
    height: 20px;
    width: 60%;
    margin-bottom: 8px;
  }

  .skeleton-meta {
    height: 14px;
    width: 40%;
    margin-bottom: 4px;
  }

  .skeleton-text {
    height: 12px;
    width: 80%;
    margin-bottom: 4px;
  }

  .skeleton-text:last-child {
    width: 65%;
  }
}

/* === TOAST NOTIFICATIONS === */
.ios-toast {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1050;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: calc(100% - 32px);
  text-align: center;
}

.ios-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.ios-toast.success {
  background: rgba(52, 199, 89, 0.9);
}

.ios-toast.error {
  background: rgba(255, 59, 48, 0.9);
}

.ios-toast.info {
  background: rgba(0, 122, 255, 0.9);
}

/* Undo button in toast */
.toast-undo {
  margin-left: 12px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  text-decoration: none;
  color: white;
  font-weight: 600;
  display: inline-block;
}

.toast-undo:active {
  background: rgba(255, 255, 255, 0.3);
}

/* === FILTER CHIPS === */
@media (max-width: 767px) {
  .filter-chips-container {
    padding: 12px 8px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .filter-chips-container::-webkit-scrollbar {
    display: none;
  }

  .filter-chips {
    display: flex;
    gap: 8px;
    padding-bottom: 4px;
  }

  .filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    background: white;
    border: 1.5px solid #E5E5EA;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    color: #3C3C43;
    white-space: nowrap;
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }

  .filter-chip:active {
    transform: scale(0.95);
  }

  .filter-chip.active {
    background: #007AFF;
    border-color: #007AFF;
    color: white;
  }

  .filter-chip i {
    font-size: 12px;
  }

  .filter-chip .count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 4px;
  }

  .filter-chip.active .count {
    background: rgba(255, 255, 255, 0.25);
  }
}

/* === SEARCH BAR === */
@media (max-width: 767px) {
  .ios-search-bar {
    position: sticky;
    top: 0;
    background: rgba(248, 248, 248, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 8px;
    z-index: 100;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  }

  .ios-search-input {
    width: 100%;
    padding: 10px 16px 10px 36px;
    background: rgba(142, 142, 147, 0.12);
    border: none;
    border-radius: 10px;
    font-size: 16px; /* Prevents zoom on iOS */
    color: #000;
    transition: background 0.2s ease;
  }

  .ios-search-input:focus {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    outline: none;
  }

  .ios-search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #8E8E93;
    font-size: 14px;
    pointer-events: none;
  }

  .ios-search-voice {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #007AFF;
    font-size: 16px;
    cursor: pointer;
  }
}