/**
 * FieldOps - Design System
 * shadcn/ui inspired components for PHP/HTML
 * Works alongside Tailwind CSS CDN
 */

/* ===== CSS VARIABLES (shadcn-inspired tokens) ===== */
:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 239 84% 67%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 239 84% 67%;
    --radius: 0.5rem;
    --sidebar-width: 260px;
    --header-height: 56px;
    --mobile-nav-height: 64px;
    --gradient: linear-gradient(135deg, hsl(var(--primary)), #764ba2);
    --success: 160 84% 39%;
    --warning: 38 92% 50%;
}

.dark {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 6%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 6%;
    --popover-foreground: 0 0% 98%;
    --primary: 239 84% 67%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 239 84% 67%;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== LAYOUT ===== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: var(--header-height);
}

.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--border));
    z-index: 50;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    backdrop-filter: blur(12px);
}

.app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
    z-index: 40;
    overflow-y: auto;
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height));
    padding: 1.5rem;
    transition: margin-left 0.2s ease;
}

.app-mobile-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mobile-nav-height);
    background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
    z-index: 50;
    padding: 0.25rem 0.5rem;
    padding-bottom: env(safe-area-inset-bottom, 0.25rem);
}

/* Mobile layout */
@media (max-width: 1023px) {
    .app-sidebar { transform: translateX(-100%); z-index: 55; }
    .app-sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.15); }
    .app-main { margin-left: 0; padding-bottom: calc(var(--mobile-nav-height) + 1rem); }
    .app-mobile-nav { display: flex; align-items: center; justify-content: space-around; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 54; }
    .sidebar-overlay.show { display: block; }
}

/* ===== SIDEBAR NAV ===== */
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.sidebar-section { padding: 0.5rem 1rem; font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: hsl(var(--muted-foreground)); }
.sidebar-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.55rem 1rem; margin: 0.1rem 0.5rem;
    border-radius: var(--radius); font-size: 0.88rem; font-weight: 500;
    color: hsl(var(--muted-foreground)); text-decoration: none;
    transition: all 0.15s;
}
.sidebar-link:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.sidebar-link.active { background: hsl(var(--primary) / 0.1); color: hsl(var(--primary)); font-weight: 600; }
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; }

/* Mobile nav items */
.mobile-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
    padding: 0.35rem 0.5rem; border-radius: var(--radius);
    font-size: 0.62rem; font-weight: 500; color: hsl(var(--muted-foreground));
    text-decoration: none; transition: color 0.15s; flex: 1;
}
.mobile-nav-item i { font-size: 1.2rem; }
.mobile-nav-item.active { color: hsl(var(--primary)); }

/* ===== SHADCN-STYLE COMPONENTS ===== */

/* Button */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.5rem 1rem; border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 500; line-height: 1.25;
    transition: all 0.15s; cursor: pointer; border: 1px solid transparent;
    white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { opacity: 0.9; }
.btn-gradient { background: var(--gradient); color: white; border: none; }
.btn-gradient:hover { opacity: 0.9; box-shadow: 0 4px 12px hsl(var(--primary) / 0.3); }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover { background: hsl(var(--secondary) / 0.8); }
.btn-outline { border-color: hsl(var(--border)); background: transparent; color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; aspect-ratio: 1; }

/* Card */
.card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) * 1.5);
    box-shadow: 0 1px 3px 0 rgba(0,0,0,0.04);
}
.card-header { padding: 1.25rem 1.5rem 0.75rem; }
.card-title { font-size: 1.05rem; font-weight: 600; line-height: 1.3; }
.card-description { font-size: 0.85rem; color: hsl(var(--muted-foreground)); margin-top: 0.15rem; }
.card-content { padding: 0 1.5rem 1.25rem; }
.card-footer { padding: 0.75rem 1.5rem; border-top: 1px solid hsl(var(--border)); display: flex; align-items: center; gap: 0.75rem; }

/* Stat Card */
.stat-card { padding: 1.25rem; position: relative; overflow: hidden; }
.stat-card .stat-icon { position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); font-size: 2.5rem; opacity: 0.08; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: 0.8rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }

/* Input */
.input {
    display: flex; width: 100%;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--input));
    background: transparent;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem; line-height: 1.5;
    color: hsl(var(--foreground));
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
.input:focus { border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2); }
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }
textarea.input { min-height: 5rem; resize: vertical; }
select.input { 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='%236b7280' d='M2.22 4.47a.75.75 0 0 1 1.06 0L6 7.19l2.72-2.72a.75.75 0 1 1 1.06 1.06L6 9.31 2.22 5.53a.75.75 0 0 1 0-1.06z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }

/* Label */
.label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; color: hsl(var(--foreground)); }
.label-required::after { content: ' *'; color: hsl(var(--destructive)); }

/* Badge */
.badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.15rem 0.6rem; border-radius: 9999px;
    font-size: 0.72rem; font-weight: 500; line-height: 1.4;
    border: 1px solid transparent;
}
.badge-primary { background: hsl(var(--primary) / 0.1); color: hsl(var(--primary)); border-color: hsl(var(--primary) / 0.2); }
.badge-success { background: hsl(var(--success) / 0.1); color: hsl(var(--success)); border-color: hsl(var(--success) / 0.2); }
.badge-warning { background: hsl(38 92% 50% / 0.1); color: hsl(38 92% 50%); border-color: hsl(38 92% 50% / 0.2); }
.badge-danger { background: hsl(var(--destructive) / 0.1); color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.2); }
.badge-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-outline { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }

/* Avatar */
.avatar {
    width: 2rem; height: 2rem; border-radius: 9999px;
    display: inline-flex; align-items: center; justify-content: center;
    background: hsl(var(--primary) / 0.1); color: hsl(var(--primary));
    font-weight: 600; font-size: 0.75rem; overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 3rem; height: 3rem; font-size: 1rem; }
.avatar-xl { width: 4rem; height: 4rem; font-size: 1.25rem; }

/* Table */
.table-wrapper { overflow-x: auto; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) * 1.5); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 0.75rem 1rem; text-align: left;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: hsl(var(--muted-foreground));
    background: hsl(var(--muted) / 0.5); border-bottom: 1px solid hsl(var(--border));
}
.data-table td { padding: 0.75rem 1rem; border-bottom: 1px solid hsl(var(--border)); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: hsl(var(--muted) / 0.3); }

/* Dialog / Modal (Alpine.js powered) */
.dialog-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.dialog-content {
    background: hsl(var(--card)); border-radius: calc(var(--radius) * 2);
    box-shadow: 0 20px 60px rgba(0,0,0,0.2); max-width: 480px; width: 100%;
    max-height: 90vh; overflow-y: auto; animation: dialogIn 0.2s ease;
}
@keyframes dialogIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.dialog-header { padding: 1.5rem 1.5rem 0.5rem; }
.dialog-body { padding: 0.5rem 1.5rem 1.5rem; }
.dialog-footer { padding: 0.75rem 1.5rem; border-top: 1px solid hsl(var(--border)); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Empty State */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-state i { font-size: 3rem; color: hsl(var(--muted-foreground) / 0.3); margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.empty-state p { font-size: 0.9rem; color: hsl(var(--muted-foreground)); }

/* Toast */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; max-width: 400px; }
.toast {
    padding: 0.75rem 1rem; border-radius: var(--radius);
    background: hsl(var(--card)); border: 1px solid hsl(var(--border));
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-size: 0.88rem; display: flex; align-items: center; gap: 0.75rem;
    animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
.toast-success { border-left: 3px solid hsl(var(--success)); }
.toast-error { border-left: 3px solid hsl(var(--destructive)); }
.toast-warning { border-left: 3px solid hsl(var(--warning)); }

/* Progress */
.progress { height: 0.5rem; background: hsl(var(--muted)); border-radius: 9999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--gradient); border-radius: 9999px; transition: width 0.3s ease; }

/* Checklist Item */
.checklist-item {
    display: flex; align-items: flex-start; gap: 0.75rem;
    padding: 1rem; border: 1px solid hsl(var(--border));
    border-radius: var(--radius); margin-bottom: 0.5rem; transition: all 0.2s;
    background: hsl(var(--card));
}
.checklist-item:hover { border-color: hsl(var(--primary) / 0.3); }
.checklist-item.completed { background: hsl(var(--success) / 0.04); border-color: hsl(var(--success) / 0.2); }
.checklist-check { width: 1.5rem; height: 1.5rem; border-radius: var(--radius); border: 2px solid hsl(var(--border)); display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; transition: all 0.2s; }
.checklist-item.completed .checklist-check { background: hsl(var(--success)); border-color: hsl(var(--success)); color: white; }

/* Work Order Card */
.wo-card { border-left: 4px solid hsl(var(--primary)); transition: all 0.2s; cursor: pointer; }
.wo-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.wo-card.priority-high { border-left-color: hsl(var(--warning)); }
.wo-card.priority-urgent { border-left-color: hsl(var(--destructive)); }

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.page-description { font-size: 0.9rem; color: hsl(var(--muted-foreground)); margin-top: 0.15rem; }

/* Utility animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn 0.3s ease; }
.animate-slide-up { animation: slideUp 0.3s ease; }

/* Notification dot */
.notification-dot {
    position: absolute; top: -2px; right: -2px;
    width: 8px; height: 8px; border-radius: 50%;
    background: hsl(var(--destructive)); border: 2px solid hsl(var(--card));
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.4); }

/* Print */
@media print {
    .app-header, .app-sidebar, .app-mobile-nav, .btn, .no-print { display: none !important; }
    .app-main { margin: 0; padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}
