* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #375622;
    --primary-light: #4a7a2e;
    --primary-dark: #2a4218;
    --danger: #cd2027;
    --danger-light: #f8d7da;
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-muted: #636466;
    --border: #d1d5db;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --font-base: clamp(0.875rem, 1.5vw, 1rem);
    --font-sm: clamp(0.7rem, 1.2vw, 0.85rem);
    --font-xs: clamp(0.6rem, 1vw, 0.75rem);
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: var(--font-base);
    line-height: 1.5;
    overflow-x: hidden;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 1rem;
}

.login-container { width: 100%; max-width: 400px; }

.login-box {
    background: var(--bg-card);
    padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1rem, 3vw, 2rem);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}

.login-header { text-align: center; margin-bottom: 2rem; }

.logo-preview {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    font-weight: 800;
    color: var(--primary);
    letter-spacing: 0.15em;
}

.login-subtitle { color: var(--text-muted); font-size: var(--font-sm); margin-top: 0.25rem; }

.login-form .form-group { margin-bottom: 1.25rem; }

.login-form label {
    display: block;
    font-size: var(--font-xs);
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.login-form input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-base);
    transition: border-color 0.2s;
    
}

.login-form input:focus { outline: none; border-color: var(--primary); }

/* Navbar */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-brand { display: flex; align-items: baseline; gap: 0.75rem; }

.nav-logo {
    font-size: clamp(1.1rem, 3vw, 1.5rem);
    font-weight: 800;
    letter-spacing: 0.1em;
}

.nav-brand small { font-size: 0.7rem; opacity: 0.8; }

.nav-steps {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.step {
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
}

.step.active { background: rgba(255,255,255,0.25); color: white; font-weight: 600; }

.step.completed { background: var(--primary-light); color: white; }

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-sm);
    flex-wrap: wrap;
}

/* Main Layout */
.main-layout { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - 56px);
}

.sidebar-header { margin-bottom: 1rem; }

.sidebar-header h3 { font-size: var(--font-sm); text-transform: uppercase; color: var(--primary); }

.sidebar-hint { font-size: var(--font-xs); color: var(--text-muted); }

.search-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

.search-form input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    min-width: 80px;
}

.entries-list { display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto; }

.entry-card {
    display: block;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
}

.entry-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

.entry-name { font-weight: 600; font-size: var(--font-sm); }

.entry-date { font-size: var(--font-xs); color: var(--text-muted); }

.entry-status { display: inline-block; font-size: 0.6rem; padding: 0.15rem 0.5rem; border-radius: 999px; margin-top: 0.25rem; }

.entry-status.completado { background: #d1fae5; color: #065f46; }

.entry-status.borrador { background: #fef3c7; color: #92400e; }

/* Content */
.content { flex: 1; padding: 1.5rem 2rem; overflow-x: auto; }

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.content-header h2 { font-size: clamp(0.9rem, 2vw, 1.1rem); color: var(--primary); }

.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 2rem; }

.action-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
}

.action-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }

.action-card.action-search { flex-direction: column; gap: 0.5rem; }

.action-card.action-search input { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: var(--font-sm); }

.action-icon { font-size: 1.5rem; font-weight: 700; color: var(--primary); flex-shrink: 0; }

.action-text { font-size: var(--font-sm); font-weight: 600; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
    
    touch-action: manipulation;
}

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

.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); }

.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }

.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

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

.btn-danger:hover { background: #a0181e; }

.btn-small { padding: 0.35rem 0.65rem; font-size: 0.75rem; }

.btn-large { padding: 0.75rem 1.5rem; font-size: var(--font-base); }

.btn-full { width: 100%; }

/* Forms */
.form-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
}

.segumas-form { display: flex; flex-direction: column; gap: 1.5rem; }

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1rem, 2.5vw, 1.5rem);
}

.section-title {
    font-size: clamp(0.85rem, 2vw, 1rem);
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.section-desc { font-size: var(--font-sm); color: var(--text-muted); margin-bottom: 1rem; }

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group { flex: 1; min-width: 150px; }

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: var(--font-xs);
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="datetime-local"],
.form-group input[type="tel"],
.form-group textarea,
.form-select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-base);
    
    transition: border-color 0.2s;
    
}

.form-group input:focus,
.form-group textarea:focus,
.form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(55,86,34,0.1); }

.form-group textarea {
    resize: both;
    min-height: 80px;
    max-height: 400px;
    overflow: auto;
    line-height: 1.5;
}

/* Larger textareas for content-heavy fields */
textarea.revision-obs,
textarea[name="anotaciones"],
textarea[name^="custom_text"],
.form-group textarea[name="direccion"] {
    min-height: 100px;
}

.form-select { background: white; }

.form-file { padding: 0.5rem 0; }

.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

/* Revision items */
.revision-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.revision-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; flex-wrap: wrap; }

.revision-name { font-weight: 600; font-size: var(--font-sm); }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.checkbox-large { font-size: 0.9rem; }

.ok-badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    background: var(--primary);
    color: white;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
}

.revision-obs {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    resize: both;
    min-height: 60px;
    max-height: 300px;
    overflow: auto;
    
}

/* Vehiculos */
.vehiculo-row { display: flex; gap: 0.5rem; align-items: center; }

.vehiculo-row input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    min-width: 120px;
}

/* Consideraciones */
.consideraciones-box {
    background: #f9fafb;
    border-left: 4px solid var(--primary);
    padding: 1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    overflow-y: auto;
    max-height: 400px;
}

.consideraciones-box p { margin-bottom: 0.75rem; font-size: var(--font-sm); line-height: 1.6; }

.consideraciones-box p:last-child { margin-bottom: 0; }

/* Contenidos PRL */
.contenido-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.contenido-item.custom { border-color: var(--primary-light); background: #f9fafb; }

.contenido-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; flex-wrap: wrap; }

.contenido-nombre { font-weight: 600; font-size: var(--font-sm); }

.contenido-item textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    resize: both;
    min-height: 80px;
    overflow: auto;
    
}

.contenido-item.custom .contenido-header input {
    flex: 1;
    min-width: 120px;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-sm);
}

/* Trabajadores */
.trabajador-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.trabajador-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }

.trabajador-num { font-weight: 700; color: var(--primary); font-size: var(--font-sm); }

/* Firmas */
.firmas-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

.firma-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.firma-box h3 { font-size: var(--font-sm); color: var(--primary); margin-bottom: 0.75rem; }

.signature-pad-wrapper { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; touch-action: none; }

.signature-pad { display: block; width: 100%; height: 150px; cursor: crosshair; background: white; touch-action: none; }

.signature-actions { padding: 0.5rem; display: flex; justify-content: flex-end; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: var(--font-sm);
    overflow-wrap: break-word;
}

.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger); }

/* Success */
.success-box {
    text-align: center;
    padding: clamp(2rem, 5vw, 3rem) clamp(1rem, 3vw, 2rem);
}

.success-icon {
    width: clamp(48px, 10vw, 64px);
    height: clamp(48px, 10vw, 64px);
    margin: 0 auto 1rem;
    background: #d1fae5;
    color: #065f46;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
}

.success-box h2 { color: var(--primary); margin-bottom: 0.75rem; font-size: clamp(1rem, 2.5vw, 1.25rem); }

.success-box p { color: var(--text-muted); margin-bottom: 0.5rem; font-size: var(--font-sm); }

/* Tables */
.entries-table,
.users-table,
.view-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
    min-width: 600px;
}

.entries-table th, .entries-table td,
.users-table th, .users-table td,
.view-table th, .view-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.entries-table th,
.users-table th,
.view-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: var(--font-xs);
    text-transform: uppercase;
}

.view-table th { background: var(--primary); color: white; }

.entries-table td:last-child { white-space: nowrap; }

.recent-entries { overflow-x: auto; margin-top: 1rem; }

/* Badges */
.badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; }

.badge-completado { background: #d1fae5; color: #065f46; }

.badge-borrador { background: #fef3c7; color: #92400e; }

.badge-admin { display: inline-block; background: var(--primary); color: #fff; font-size: 0.65rem; padding: 1px 6px; border-radius: 3px; }

.badge-user { display: inline-block; background: var(--text-muted); color: #fff; font-size: 0.65rem; padding: 1px 6px; border-radius: 3px; }
.badge-recolector { display: inline-block; background: #636466; color: #fff; font-size: 0.65rem; padding: 1px 6px; border-radius: 3px; }

/* Pagination */
.pagination { display: flex; gap: 0.25rem; margin-top: 1rem; justify-content: center; flex-wrap: wrap; }

.page-link {
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: var(--font-sm);
}

.page-link.active { background: var(--primary); color: white; border-color: var(--primary); }

/* View mode */
.view-mode .view-table td {
    white-space: normal;
    word-break: break-word;
}

.view-contenido {
    padding: 0.5rem 0.75rem;
    border-left: 3px solid var(--primary);
    background: #f9fafb;
    margin-bottom: 0.5rem;
    font-size: var(--font-sm);
    overflow-y: auto;
    max-height: 200px;
}

/* Empty state */
.empty-state { text-align: center; color: var(--text-muted); padding: 2rem; font-size: var(--font-sm); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c5c9; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a5a9; }

/* Responsive */
@media (max-width: 768px) {
    .main-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 40vh;
    }
    .firmas-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    .form-row .form-group { width: 100%; }
    .nav-steps { display: none; }
    .content { padding: 1rem; }
    .actions-grid { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
    .content-header { flex-direction: column; align-items: stretch; text-align: center; }
    .content-header .btn { width: 100%; text-align: center; }
    .entries-table,
    .users-table { min-width: unset; font-size: var(--font-xs); }
    .entries-table td, .entries-table th,
    .users-table td, .users-table th { padding: 0.4rem 0.5rem; }
    .login-container { padding: 0; }
    .login-box { border-radius: 0; box-shadow: none; }
    .login-page { padding: 0; }
}

@media (max-width: 480px) {
    .navbar { padding: 0.5rem 0.75rem; }
    .nav-user { width: 100%; justify-content: flex-end; }
    .nav-brand small { display: none; }
    .sidebar { max-height: 35vh; }
    .form-section { padding: 0.75rem; }
    .signature-pad { height: 120px; }
    .contenido-header { flex-direction: column; align-items: stretch; }
}

@media (min-width: 1200px) {
    .form-container { max-width: 1000px; }
    .firmas-grid { grid-template-columns: 1fr 1fr 1fr; }
    .content { padding: 2rem 3rem; }
    .actions-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Landscape phone */
@media (max-height: 500px) {
    .sidebar { max-height: 50vh; }
    .signature-pad { height: 100px; }
    .navbar { position: relative; }
}

/* Print */
@media print {
    .navbar, .sidebar, .form-actions, .btn, .search-form, .pagination, .actions-grid { display: none !important; }
    .main-layout { display: block; }
    .content { padding: 0; }
    .form-section { break-inside: avoid; border: none; box-shadow: none; }
}
