/* ================================================================
   CAAE Organic — Design System
   ================================================================ */

/* Fuentes custom ya cargadas via Google Fonts en layout.php */

/* ---- Reset suave ---- */
*, *::before, *::after { box-sizing: border-box; }

/* ---- Scrollbar personalizada ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #52B788; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #2D6A4F; }

/* ---- [x-cloak] para Alpine.js ---- */
[x-cloak] { display: none !important; }

/* ---- Cards ---- */
.card {
    background: white;
    border-radius: 1rem;
    border: 1px solid #e5e7eb;
    padding: 1.5rem;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / .07);
    transition: box-shadow 0.2s;
}
.dark .card {
    background: #111827;
    border-color: #1f2937;
}
.card:hover { box-shadow: 0 4px 12px 0 rgb(45 106 79 / .1); }

/* ---- KPI Cards ---- */
.kpi-card {
    background: white;
    border-radius: 1.25rem;
    padding: 1.5rem;
    border: 1px solid #e5e7eb;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}
.dark .kpi-card { background: #111827; border-color: #1f2937; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px 0 rgb(45 106 79 / .12); }
.kpi-card::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #2D6A4F, #52B788);
}

/* ---- Badge de estado ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.7;
}

/* ---- Tabla de datos ---- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: #f9fafb;
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.dark .data-table th { background: #1f2937; border-color: #374151; color: #9ca3af; }
.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.875rem;
    vertical-align: middle;
}
.dark .data-table td { border-color: #1f2937; }
.data-table tbody tr { transition: background-color 0.1s; }
.data-table tbody tr:hover { background: #f0f9f4; }
.dark .data-table tbody tr:hover { background: #0a2419; }

/* ---- Formularios ---- */
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.375rem;
}
.dark .form-label { color: #d1d5db; }

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1.5px solid #d1d5db;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    background: white;
    color: #111827;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
.dark .form-input, .dark .form-select, .dark .form-textarea {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: #2D6A4F;
    box-shadow: 0 0 0 3px rgb(45 106 79 / .12);
}
.form-input.error { border-color: #ef4444; }
.form-error { font-size: 0.75rem; color: #ef4444; margin-top: 0.25rem; }

/* ---- Botones ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2D6A4F; color: white; }
.btn-primary:hover:not(:disabled) { background: #1f5439; box-shadow: 0 4px 12px rgb(45 106 79 / .3); }
.btn-accent { background: #D4A017; color: #1A2E1E; }
.btn-accent:hover:not(:disabled) { background: #b88a13; }
.btn-outline { background: transparent; color: #2D6A4F; border: 1.5px solid #2D6A4F; }
.btn-outline:hover:not(:disabled) { background: #f0f9f4; }
.dark .btn-outline { color: #52B788; border-color: #52B788; }
.dark .btn-outline:hover:not(:disabled) { background: #0a2419; }
.btn-ghost { background: transparent; color: #6b7280; }
.btn-ghost:hover:not(:disabled) { background: #f3f4f6; color: #111827; }
.dark .btn-ghost:hover:not(:disabled) { background: #1f2937; color: #f9fafb; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }
.btn-secondary:hover:not(:disabled) { background: #e5e7eb; }
.dark .btn-secondary { background: #1f2937; color: #d1d5db; border-color: #374151; }
.dark .btn-secondary:hover:not(:disabled) { background: #374151; }
.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8125rem; border-radius: 0.5rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1rem; border-radius: 1rem; }

/* ---- Tabs ---- */
.tabs { border-bottom: 2px solid #e5e7eb; display: flex; gap: 0.25rem; }
.dark .tabs { border-color: #374151; }
.tab {
    padding: 0.625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.tab:hover { color: #2D6A4F; }
.tab.active { color: #2D6A4F; border-bottom-color: #2D6A4F; font-weight: 600; }
.dark .tab.active { color: #52B788; border-bottom-color: #52B788; }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before {
    content: '';
    position: absolute;
    left: 0.625rem;
    top: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, #2D6A4F, #52B788, #e5e7eb);
}
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.4375rem;
    top: 0.125rem;
    width: 0.75rem; height: 0.75rem;
    border-radius: 50%;
    background: #2D6A4F;
    border: 2px solid white;
    box-shadow: 0 0 0 3px rgb(45 106 79 / .2);
}
.dark .timeline-item::before { border-color: #111827; }

/* ---- Kanban ---- */
.kanban-col {
    min-width: 280px;
    background: #f9fafb;
    border-radius: 1rem;
    padding: 1rem;
}
.dark .kanban-col { background: #111827; }
.kanban-card {
    background: white;
    border-radius: 0.75rem;
    padding: 0.875rem;
    margin-bottom: 0.5rem;
    border: 1px solid #e5e7eb;
    cursor: grab;
    transition: box-shadow 0.15s, transform 0.1s;
}
.dark .kanban-card { background: #1f2937; border-color: #374151; }
.kanban-card:hover { box-shadow: 0 4px 12px rgb(0 0 0 / .1); transform: translateY(-1px); }
.kanban-card:active { cursor: grabbing; }

/* ---- Skeleton loaders ---- */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 0.5rem;
}
.dark .skeleton { background: linear-gradient(90deg, #1f2937 25%, #374151 50%, #1f2937 75%); }
@keyframes skeleton-loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Upload zone ---- */
.upload-zone {
    border: 2px dashed #d1d5db;
    border-radius: 1rem;
    padding: 2.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
}
.dark .upload-zone { border-color: #374151; background: #111827; }
.upload-zone:hover, .upload-zone.dragover {
    border-color: #2D6A4F;
    background: #f0f9f4;
    box-shadow: 0 0 0 4px rgb(45 106 79 / .08);
}

/* ---- Animaciones de entrada ---- */
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.slide-in { animation: slideIn 0.25s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

/* ---- Focus visible (accessibility) ---- */
:focus-visible {
    outline: 2px solid #2D6A4F;
    outline-offset: 2px;
}

/* ---- Form validation states ---- */
.form-input:invalid:not(:placeholder-shown),
.form-input[aria-invalid="true"] {
    border-color: #ef4444;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23ef4444' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}
.form-input:valid:not(:placeholder-shown):not([type="file"]) {
    border-color: #22c55e;
}

/* ---- Toast notifications ---- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(0,0,0,.2);
    animation: toastIn 0.25s ease-out;
    white-space: nowrap;
}
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 1rem; height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty states ---- */
.empty-state-icon {
    width: 3.5rem; height: 3.5rem;
    background: #f3f4f6;
    border-radius: 1rem;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1rem;
    color: #9ca3af;
}
.dark .empty-state-icon { background: #1f2937; }

/* ---- Mobile responsive helpers ---- */
@media (max-width: 640px) {
    .card { padding: 1rem; border-radius: 0.75rem; }
    .form-input, .form-select, .form-textarea { font-size: 1rem; /* Prevent zoom on iOS */ }
    .hide-mobile { display: none !important; }
    .data-table th, .data-table td { padding: 0.625rem 0.75rem; }

    /* Reduce heading size on very small screens */
    h1.font-heading { font-size: 1.125rem; }

    /* Buttons full-width on forms in mobile */
    .form-actions-mobile { flex-direction: column; }
    .form-actions-mobile .btn { width: 100%; justify-content: center; }

    /* Tables horizontal scroll */
    .table-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- Bottom nav bar (móvil) ---- */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 40;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: none;
    padding-bottom: env(safe-area-inset-bottom, 0); /* iPhone notch */
    box-shadow: 0 -4px 16px rgb(0 0 0 / .06);
}
.dark .mobile-bottom-nav {
    background: #111827;
    border-color: #1f2937;
}
@media (max-width: 1023px) {
    .mobile-bottom-nav { display: flex; }
    /* Push page content up so it's not hidden behind the bottom nav */
    body > .flex.h-full > div:last-of-type > main {
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0));
    }
}
.mobile-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.25rem;
    gap: 0.2rem;
    font-size: 0.65rem;
    font-weight: 500;
    color: #9ca3af;
    text-decoration: none;
    transition: color 0.15s;
}
.mobile-bottom-nav a.active { color: #2D6A4F; }
.dark .mobile-bottom-nav a.active { color: #52B788; }
.mobile-bottom-nav a svg { width: 1.25rem; height: 1.25rem; }

/* ---- Print ---- */
@media print {
    .sidebar, header, footer, .btn, button, form { display: none !important; }
    .card { box-shadow: none !important; border: 1px solid #e5e7eb !important; }
    body { background: white !important; }
    .fade-in { animation: none !important; }
}

/* ---- Pulse indicator ---- */
.pulse-dot {
    position: relative;
}
.pulse-dot::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid currentColor;
    animation: pulse-ring 1.5s ease-out infinite;
    opacity: 0;
}
@keyframes pulse-ring { 0% { transform:scale(0.8); opacity:0.8; } 100% { transform:scale(1.5); opacity:0; } }

/* ---- Número operador / código destacado ---- */
.code-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    background: #f0f9f4;
    color: #2D6A4F;
    border-radius: 0.375rem;
    border: 1px solid #b9e5cc;
}
.dark .code-badge { background: #0a2419; color: #52B788; border-color: #1a6644; }
