/* =================================================================
   SWOP - Estilos principales (paleta verde)
   Responsive: móvil pequeño, móvil grande, tablet, laptop, desktop
   ================================================================= */

/* ===== Reset y tipografía base ===== */
*, *::before, *::after { box-sizing: border-box; }

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

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--c-bg, #f0fdf4);
    color: var(--c-text, #052e16);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--c-primary, #16a34a); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

h1, h2, h3 { margin: 0 0 .6em 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

small { color: #64748b; }

/* ===== Topbar ===== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 60px;
    background: var(--c-secondary, #14532d);
    color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 18px;
    z-index: 100;
    box-shadow: 0 1px 4px rgba(0,0,0,.15);
    gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.topbar-logo { height: 36px; flex-shrink: 0; }
.topbar-logo-placeholder {
    height: 36px; min-width: 36px; padding: 0 10px;
    background: var(--c-primary, #16a34a);
    color: #fff; font-weight: 700; font-size: 14px;
    border-radius: 6px; display: flex; align-items: center;
    flex-shrink: 0;
}
.topbar-title {
    font-weight: 600; font-size: 1rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}
.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.topbar-user { font-size: 14px; }
.role-badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 11px; font-weight: 600; margin-right: 6px;
    text-transform: uppercase; letter-spacing: .5px;
}
.role-superusuario { background: #7c3aed; color: #fff; }
.role-administrador { background: #2563eb; color: #fff; }
.role-estandar { background: #475569; color: #fff; }

.hamburger {
    display: none;
    background: transparent; color: #fff; border: 0;
    font-size: 24px; cursor: pointer; padding: 4px 10px;
    line-height: 1; flex-shrink: 0;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed; top: 60px; left: 0; bottom: 0;
    width: 240px;
    background: #fff;
    border-right: 1px solid #dcfce7;
    overflow-y: auto;
    padding: 12px 0;
    transition: transform .25s ease;
    z-index: 95;
    -webkit-overflow-scrolling: touch;
}
.sidebar .nav-item {
    display: block; padding: 10px 18px; color: #334155;
    font-size: 14px; text-decoration: none; border-left: 3px solid transparent;
}
.sidebar .nav-item:hover { background: #f0fdf4; text-decoration: none; }
.sidebar .nav-item.active { background: #dcfce7; border-left-color: var(--c-primary); color: var(--c-primary); font-weight: 600; }
.sidebar .nav-sep {
    padding: 14px 18px 4px; font-size: 11px; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 1px; font-weight: 600;
}

/* Backdrop del sidebar móvil */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 60px 0 0 0;
    background: rgba(15,23,42,.5);
    z-index: 90;
}
.sidebar-backdrop.open { display: block; }

/* ===== Main ===== */
.main {
    margin-left: 240px;
    margin-top: 60px;
    padding: 24px;
    min-height: calc(100vh - 60px);
}
.page-title { margin: 0 0 18px 0; font-size: 1.5rem; }

.footer {
    margin-left: 240px;
    padding: 16px 24px;
    color: #94a3b8;
    text-align: center;
    font-size: 13px;
}

/* ===== Botones ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 6px; border: 1px solid transparent;
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: all .15s; text-decoration: none;
    background: #e2e8f0; color: #0f172a;
    white-space: nowrap;
    text-align: center;
    justify-content: center;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-accent  { background: var(--c-accent); color: #fff; }
.btn-danger  { background: #dc2626; color: #fff; }
.btn-warn    { background: #f59e0b; color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--c-primary); color: var(--c-primary); }
.btn-outline-light { background: transparent; border: 1px solid #fff; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ===== Formularios ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.form-row.full { grid-template-columns: 1fr; }
.form-row > div { min-width: 0; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #334155; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"],
input[type="color"], select, textarea {
    width: 100%; padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 6px;
    font-size: 15px; font-family: inherit; background: #fff; color: #0f172a;
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
}
input[type="color"] { padding: 2px; height: 40px; cursor: pointer; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(22,163,74,.18);
}
textarea { min-height: 80px; resize: vertical; }
.help { font-size: 12px; color: #64748b; margin-top: 4px; }

.form-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ===== Tabla ===== */
.table-wrap { background: #fff; border-radius: 8px; overflow: auto; box-shadow: 0 1px 3px rgba(0,0,0,.05); -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 600px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; }
table.data th { background: #f0fdf4; font-weight: 600; color: #166534; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }
table.data tbody tr:hover { background: #f7fee7; }
table.data .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-pendiente { background: #fef3c7; color: #92400e; }
.badge-concluido { background: #dcfce7; color: #14532d; }

/* ===== Cards ===== */
.card {
    background: #fff; border-radius: 8px; padding: 20px; margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    border: 1px solid #ecfdf5;
    min-width: 0;
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 12px; color: #14532d; }

/* Wrapper para canvases de Chart.js: da una altura estable para que
   el chart no crezca indefinidamente con maintainAspectRatio:false. */
.chart-wrap { position: relative; width: 100%; height: 320px; }
.chart-wrap.tall { height: 420px; }   /* para barras con muchas categorías */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi {
    background: #fff; padding: 18px; border-radius: 8px; border-left: 4px solid var(--c-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    min-width: 0;
}
.kpi .kpi-label { font-size: 12px; color: #64748b; text-transform: uppercase; letter-spacing: .5px; }
.kpi .kpi-value { font-size: 2rem; font-weight: 700; color: var(--c-secondary); margin-top: 4px; line-height: 1.1; }
.kpi .kpi-foot { font-size: 12px; color: #64748b; margin-top: 4px; }

/* ===== Alertas ===== */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; word-wrap: break-word; }
.alert-success { background: #dcfce7; color: #14532d; border-left: 4px solid #16a34a; }
.alert-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #dc2626; }
.alert-warn    { background: #fef3c7; color: #92400e; border-left: 4px solid #f59e0b; }
.alert-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid #2563eb; }

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.55);
    display: none; align-items: center; justify-content: center; z-index: 200;
    padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff; border-radius: 10px; max-width: 520px; width: 100%;
    padding: 22px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
    max-height: 90vh; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 14px; color: #052e16; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* ===== Login ===== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-secondary) 100%);
    padding: 20px;
}
.login-card {
    background: #fff; border-radius: 12px; padding: 32px;
    width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card h1 { text-align: center; color: var(--c-secondary); font-size: 1.3rem; }
.login-logo { display: block; max-height: 80px; margin: 0 auto 18px auto; }

/* ===== Filtros ===== */
.filters {
    background: #fff; border-radius: 8px; padding: 16px; margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    border: 1px solid #ecfdf5;
}
.filters .form-row { margin-bottom: 10px; }
.filters .form-row:last-child { margin-bottom: 0; }

/* ===== Utils ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* =================================================================
   RESPONSIVE
   ================================================================= */

/* ----- Móvil pequeño: hasta 480px (iPhone SE, etc.) ----- */
@media (max-width: 480px) {
    body { font-size: 14px; }
    .topbar { padding: 0 10px; height: 56px; }
    .topbar-title { display: none; }
    .topbar-user { display: none; }
    .hamburger { display: inline-block; }
    .main { margin-left: 0; margin-top: 56px; padding: 14px; }
    .footer { margin-left: 0; padding: 12px 14px; }
    .page-title { font-size: 1.2rem; }
    h1 { font-size: 1.35rem; }
    .kpi .kpi-value { font-size: 1.6rem; }
    .card { padding: 14px; }
    .form-row { grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
    .btn { padding: 10px 14px; font-size: 14px; }
    .btn-sm { padding: 6px 10px; font-size: 12px; }
    .login-card { padding: 22px 18px; }
    .form-actions .btn { width: 100%; }
    .sidebar { transform: translateX(-100%); width: 84%; max-width: 300px; }
    .sidebar.open { transform: translateX(0); }
    .modal { padding: 18px; }
    table.data { font-size: 12px; min-width: 540px; }
    table.data th, table.data td { padding: 8px; }
    .topbar-right .btn { padding: 4px 8px; font-size: 12px; }
    .topbar .role-badge { display: none; }
    .flex-between { flex-direction: column; align-items: stretch; }
    .flex-between > * { width: 100%; }
}

/* ----- Móvil grande / phablet: 481px a 768px ----- */
@media (min-width: 481px) and (max-width: 768px) {
    .hamburger { display: inline-block; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main, .footer { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar-user { font-size: 12px; }
    .topbar-title { display: none; }
}

/* ----- Tablet: 769px a 1024px ----- */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar { width: 220px; }
    .main { margin-left: 220px; padding: 20px; }
    .footer { margin-left: 220px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr 1fr; }
    .hamburger { display: inline-block; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main, .footer { margin-left: 0; }
}

/* ----- Laptop: 1025px a 1280px ----- */
@media (min-width: 1025px) and (max-width: 1280px) {
    .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ----- Desktop: > 1280px ----- */
@media (min-width: 1281px) {
    .main { padding: 28px 32px; }
    .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ----- Sidebar abierto: aplicar margen cuando se abre en móvil/tablet ----- */
@media (max-width: 1024px) {
    body.sidebar-open { overflow: hidden; }
    body.sidebar-open .main { filter: blur(1px); pointer-events: none; }
}
