/* ============================================
   工程查驗 APP - Components
   ============================================ */

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}

.card-highlight {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.card-highlight.pending { background: var(--status-pending); }
.card-highlight.in-progress { background: var(--status-in-progress); }
.card-highlight.completed { background: var(--status-completed); }

.card-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary-900);
    color: var(--primary-300);
}

.card-icon .material-symbols-outlined {
    font-size: 24px;
}

.card-info {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-top: var(--space-sm);
}

.card-meta .material-symbols-outlined {
    font-size: 14px;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--divider);
}

/* Stats Row */
.stats-row {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-xl);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

.stat-chip.pending {
    background: var(--status-pending-bg);
    color: var(--status-pending);
}

.stat-chip.in-progress {
    background: var(--status-in-progress-bg);
    color: var(--status-in-progress);
}

.stat-chip.completed {
    background: var(--status-completed-bg);
    color: var(--status-completed);
}

.stat-chip .material-symbols-outlined {
    font-size: 14px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-fast);
    white-space: nowrap;
    min-height: 44px;
}

.btn .material-symbols-outlined {
    font-size: 20px;
}

.btn-primary {
    background: var(--primary-600);
    color: white;
}

.btn-primary:active {
    background: var(--primary-700);
    transform: scale(0.96);
}

.btn-accent {
    background: var(--accent-600);
    color: white;
}

.btn-accent:active {
    background: var(--accent-700);
    transform: scale(0.96);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:active {
    background: var(--border-color);
}

.btn-ghost {
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:active {
    background: var(--bg-tertiary);
}

.btn-danger {
    background: var(--status-pending);
    color: white;
}

.btn-danger:active {
    background: var(--status-overdue);
}

.btn-full {
    width: 100%;
}

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

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.btn-icon:active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + var(--space-lg));
    right: var(--space-lg);
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: var(--radius-xl);
    background: var(--accent-600);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    transition: all var(--transition-normal);
}

.fab:active {
    transform: scale(0.9);
    box-shadow: var(--shadow-xl);
}

.fab .material-symbols-outlined {
    font-size: 28px;
}

/* === Forms === */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 12px var(--space-lg);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    transition: border-color var(--transition-fast);
    min-height: 48px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.15);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

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

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* === Dialog === */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-lg);
    animation: fadeIn 0.2s ease;
}

.dialog-overlay.active {
    display: flex;
}

.dialog {
    background: var(--bg-card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-color);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xl) var(--space-xl) var(--space-md);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.dialog-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
}

.dialog-body {
    padding: 0 var(--space-xl) var(--space-xl);
}

.dialog-footer {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-lg) var(--space-xl) var(--space-xl);
    justify-content: flex-end;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + var(--space-xl));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-toast);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    max-width: calc(100% - 48px);
    pointer-events: none;
    border: 1px solid var(--border-color);
}

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

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-3xl) var(--space-xl);
    text-align: center;
    min-height: 300px;
}

.empty-state .empty-icon {
    font-size: 64px;
    color: var(--text-tertiary);
    margin-bottom: var(--space-xl);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.empty-state p {
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    max-width: 260px;
}

/* === Progress Bar === */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: var(--space-sm);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--status-completed), var(--primary-400));
    border-radius: 3px;
    transition: width var(--transition-slow);
}

/* === Status Badge === */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-xl);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
}

.status-badge.pending {
    background: var(--status-pending-bg);
    color: var(--status-pending);
}

.status-badge.in-progress {
    background: var(--status-in-progress-bg);
    color: var(--status-in-progress);
}

.status-badge.completed {
    background: var(--status-completed-bg);
    color: var(--status-completed);
}

/* === Quick Text Chips === */
.quick-text-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.quick-text-chip {
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.quick-text-chip:active {
    background: var(--primary-900);
    border-color: var(--primary-600);
    color: var(--primary-300);
}

/* === Photo Grid === */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-item .photo-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-item .photo-delete .material-symbols-outlined {
    font-size: 16px;
    color: white;
}

.photo-add {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    aspect-ratio: 1;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.photo-add:active {
    border-color: var(--primary-500);
    color: var(--primary-400);
    background: var(--primary-900);
}

.photo-add .material-symbols-outlined {
    font-size: 28px;
}

.photo-add span:last-child {
    font-size: var(--font-size-xs);
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-lg);
    z-index: var(--z-max);
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-400);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

/* === Swipe Actions === */
.swipe-container {
    position: relative;
    overflow: hidden;
}

.swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
}

.swipe-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    color: white;
}

.swipe-action.delete {
    background: var(--status-pending);
}

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

/* === Sidebar Panel === */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: var(--z-overlay);
    display: none;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.sidebar-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 380px;
    background: var(--bg-secondary);
    z-index: var(--z-modal);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-panel.active {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

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

.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

/* === Photo Action Buttons === */
.photo-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
    gap: 2px;
    padding: 4px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    opacity: 1;
}

.photo-action-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
}

.photo-action-btn:active {
    transform: scale(0.9);
}

.photo-action-btn .material-symbols-outlined {
    font-size: 16px;
}

.photo-action-btn.btn-share-photo {
    background: rgba(30, 136, 229, 0.7);
}

.photo-action-btn.btn-share-photo:active {
    background: rgba(30, 136, 229, 1);
}

/* === Toggle Switch (iOS style) === */
.watermark-settings {
    padding: var(--space-sm) var(--space-lg);
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--divider);
    cursor: pointer;
}

.toggle-row:last-child {
    border-bottom: none;
}

.toggle-row-icon {
    font-size: 22px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.toggle-row-label {
    flex: 1;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 14px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* === Watermark Preview === */
.watermark-preview {
    position: relative;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.watermark-preview-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.65);
    min-height: 32px;
}

.watermark-preview-left,
.watermark-preview-right {
    font-size: 11px;
    font-weight: bold;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.watermark-preview-left {
    flex: 1;
    min-width: 0;
}

.watermark-preview-right {
    flex-shrink: 0;
    margin-left: 8px;
    color: rgba(255, 255, 255, 0.85);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary-600);
    border-color: var(--primary-600);
}

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

/* === Pressure Test Components === */
.pressure-result-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.pressure-result-icon.completed {
    background: var(--status-completed-bg);
}

.pressure-result-icon.pending {
    background: var(--status-pending-bg);
}

.pressure-values-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--divider);
}

.pressure-value {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.pressure-label {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
}

.pressure-number {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.pressure-number.completed {
    color: var(--status-completed);
}

.pressure-number.pending {
    color: var(--status-pending);
}

/* Pressure calc result (form) */
.pressure-calc-result {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-top: var(--space-md);
    margin-bottom: var(--space-md);
}

.pressure-calc-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.pressure-calc-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
}

.pressure-calc-badge {
    padding: 2px 10px;
    border-radius: var(--radius-xl);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-sm);
}

.pressure-calc-badge.pass {
    background: var(--status-completed-bg);
    color: var(--status-completed);
}

.pressure-calc-badge.fail {
    background: var(--status-pending-bg);
    color: var(--status-pending);
}

/* Pressure detail grid (sidebar) */
.pressure-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.pressure-detail-item {
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    text-align: center;
}

.pressure-detail-label {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.pressure-detail-value {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.pressure-detail-value small {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-regular);
    color: var(--text-tertiary);
}

.pressure-detail-value.completed {
    color: var(--status-completed);
}

.pressure-detail-value.pending {
    color: var(--status-pending);
}

/* === Tool Cards === */
.tool-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-xl);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.tool-card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}

.tool-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tool-card-icon .material-symbols-outlined {
    font-size: 26px;
}

.tool-card-info {
    flex: 1;
    min-width: 0;
}

.tool-card-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tool-card-desc {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
}

.tool-card-badge {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
    flex-shrink: 0;
}

/* ============================================
   Responsive: Tablet (768px+)
   ============================================ */
@media (min-width: 768px) {
    /* Dashboard stats: 2-column grid */
    .stat-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-md);
    }

    /* Tool cards: 2-column grid */
    .tool-card {
        display: inline-flex;
        width: calc(50% - var(--space-sm));
        vertical-align: top;
    }
    .tool-card:nth-child(odd) {
        margin-right: var(--space-sm);
    }
    .tool-card:nth-child(even) {
        margin-left: var(--space-sm);
    }

    /* Photo grid: more columns */
    .photo-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Sidebar panel: wider */
    .sidebar-panel {
        width: 420px;
    }

    /* Dialog: wider */
    .dialog {
        max-width: 500px;
    }

    /* Form inputs: hover states */
    .form-input:hover,
    .form-textarea:hover,
    .form-select:hover {
        border-color: var(--primary-600);
    }

    /* Buttons: hover states */
    .btn:hover {
        filter: brightness(1.1);
    }

    /* Daily report cards: 2-column */
    .daily-report-card {
        display: inline-block;
        width: calc(50% - var(--space-sm));
        vertical-align: top;
    }
    .daily-report-card:nth-child(odd) {
        margin-right: var(--space-sm);
    }
    .daily-report-card:nth-child(even) {
        margin-left: var(--space-sm);
    }
}

/* ============================================
   Responsive: Desktop (1200px+)
   ============================================ */
@media (min-width: 1200px) {
    .sidebar-panel {
        width: 500px;
    }

    .dialog {
        max-width: 600px;
    }

    .photo-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}
