/* ============================================================
   EucaSystem — Estilos principales (rediseño 2026)
   Impregnadora y Maderera La Criolla
   Soporta tema claro/oscuro + navegación móvil tipo app
   ============================================================ */

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

:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Marca (constante en ambos temas) */
  --brand:     #2D6B24;
  --brand-dk:  #1C4518;
  --brand-xdk: #122E10;
  --brand-lt:  #EBF5E9;
  --brand-mid: #4E8F43;
  --accent:    #D91F26;
  --accent-dk: #A8161C;
  --accent-lt: #FDEAEA;

  /* Superficies — tema claro */
  --bg:        #F4F7F3;
  --bg2:       #E8EFE7;
  --surface:   #FFFFFF;
  --surface-2: #FAFCFA;
  --border:    #DCE6DB;
  --border2:   #C2D2C1;

  /* Texto */
  --text:  #141B13;
  --text2: #56654F;
  --text3: #8A9E88;

  /* Semánticos */
  --green:#2D8A1E; --green-light:#DFF0DC; --green-dark:#1C5914;
  --blue:#185FA5;  --blue-light:#E6F1FB;
  --orange:#854F0B;--orange-light:#FAEEDA;
  --red:#A32D2D;   --red-light:#FCEBEB;

  /* Radios y sombras modernas */
  --radius-sm:8px; --radius-md:12px; --radius-lg:16px; --radius-xl:22px;
  --shadow:    0 1px 2px rgba(20,40,15,.05), 0 1px 3px rgba(20,40,15,.09);
  --shadow-md: 0 4px 12px rgba(20,40,15,.10), 0 2px 6px rgba(20,40,15,.06);
  --shadow-lg: 0 14px 36px rgba(20,40,15,.16);

  /* Aliases de compatibilidad (usados inline en módulos) */
  --primary:   var(--brand);
  --danger:    var(--accent);
  --card-bg:   var(--surface);
  --text-muted:var(--text2);
  --bg1:       var(--bg);
  --border1:   var(--border);
  --text1:     var(--text);
  --radius:    var(--radius-md);
}

html[data-theme="dark"] {
  --bg:        #0F1511;
  --bg2:       #19211A;
  --surface:   #161E16;
  --surface-2: #1C261C;
  --border:    #2A352A;
  --border2:   #3A4A3A;

  --text:  #E8EFE6;
  --text2: #A9BCA6;
  --text3: #7C9079;

  --brand-lt:  #1E2C1A;
  --green-light:#16301A; --green-dark:#9FE3A0;
  --blue-light: #142536;
  --orange-light:#33260F;
  --red-light:  #3A1717;

  --shadow:    0 1px 3px rgba(0,0,0,.40);
  --shadow-md: 0 6px 18px rgba(0,0,0,.50);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.62);

  color-scheme: dark;
}

html, body { height: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background .25s ease, color .25s ease;
}

/* === LAYOUT === */
.app  { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* === SIDEBAR === */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(185deg, var(--brand-xdk) 0%, #0E2A0C 100%);
  display: flex; flex-direction: column;
  box-shadow: 2px 0 14px rgba(0,0,0,.22);
  z-index: 60;
}
.logo {
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 11px;
}
.logo-img { width: 40px; height: 40px; flex-shrink: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.logo-text { line-height: 1.2; }
.logo-title { font-size: 13px; font-weight: 800; color: #fff; text-transform: uppercase; letter-spacing: .04em; }
.logo-sub   { font-size: 10px; color: rgba(255,255,255,.50); margin-top: 1px; letter-spacing: .03em; }

.nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav::-webkit-scrollbar { width: 0; }
.nav-section {
  font-size: 9.5px; color: rgba(255,255,255,.32);
  padding: 14px 18px 5px; letter-spacing: .10em; text-transform: uppercase; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 18px;
  font-size: 13.5px; color: rgba(255,255,255,.62); text-decoration: none;
  border-left: 3px solid transparent; transition: background .14s, color .14s;
  position: relative;
}
.nav-item svg { opacity: .72; transition: opacity .14s; flex-shrink: 0; }
.nav-item:hover     { background: rgba(255,255,255,.07); color: rgba(255,255,255,.95); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(217,31,38,.16), rgba(255,255,255,.06));
  color: #fff; border-left-color: var(--accent); font-weight: 600;
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 13px 16px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.user-name { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.85); }
.user-rol  { font-size: 10px; color: rgba(255,255,255,.45); margin-top: 1px; text-transform: capitalize; }
.btn-logout {
  color: rgba(255,255,255,.45); text-decoration: none;
  padding: 7px; border-radius: var(--radius-sm); transition: background .12s, color .12s;
  display: inline-flex;
}
.btn-logout:hover { background: rgba(255,255,255,.12); color: #fff; }

/* === SCRIM (fondo del drawer en móvil) === */
.scrim {
  display: none; position: fixed; inset: 0; z-index: 55;
  background: rgba(0,0,0,.45); opacity: 0; transition: opacity .22s ease;
  backdrop-filter: blur(1px);
}

/* === TOPBAR === */
.topbar {
  padding: 12px 22px; padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(140%) blur(10px);
}
.topbar-btn {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; flex-shrink: 0;
}
.topbar-btn:active { transform: scale(.94); }
.page-title { font-size: 17px; font-weight: 700; color: var(--text); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.fecha-hoy {
  font-size: 12px; color: var(--text2);
  background: var(--bg2); padding: 5px 12px; border-radius: 20px; white-space: nowrap;
}
.theme-toggle {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface); color: var(--text2);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; transition: background .14s, color .14s;
}
.theme-toggle:hover  { background: var(--bg2); color: var(--text); }
.theme-toggle:active { transform: scale(.94); }
.theme-toggle .ico-dark  { display: none; }
html[data-theme="dark"] .theme-toggle .ico-light { display: none; }
html[data-theme="dark"] .theme-toggle .ico-dark  { display: inline; }

/* === CONTENT === */
.content { flex: 1; overflow-y: auto; padding: 24px; -webkit-overflow-scrolling: touch; }

/* === BOTTOM NAV (solo móvil) === */
.bottom-nav { display: none; }

/* === GRILLAS === */
.g2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.g3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.g4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }

/* === MÉTRICAS === */
.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 20px;
  border-left: 4px solid var(--brand); box-shadow: var(--shadow);
  transition: box-shadow .16s, transform .16s;
}
.metric:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.metric-label { font-size: 11px; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.metric-val   { font-size: 25px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.metric-sub   { font-size: 11.5px; color: var(--text2); margin-top: 4px; }

/* === CARDS === */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 22px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 14px; font-weight: 700; margin-bottom: 16px;
  color: var(--text); padding-bottom: 11px; border-bottom: 1px solid var(--border);
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); }

/* === TABLAS === */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left; padding: 10px 11px;
  color: var(--text2); font-weight: 700; font-size: 11px;
  background: var(--surface-2); border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0;
}
td { padding: 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--brand-lt); }
.table-responsive { overflow-x: auto; border-radius: var(--radius-md); -webkit-overflow-scrolling: touch; }

/* === BOTONES === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--radius-md);
  border: 1px solid var(--border2); background: var(--surface);
  color: var(--text); font-size: 13px; font-family: var(--font);
  cursor: pointer; text-decoration: none; font-weight: 600;
  transition: background .12s, border-color .12s, transform .08s, box-shadow .12s;
}
.btn:hover  { background: var(--bg2); border-color: var(--brand-mid); }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(180deg, var(--brand-mid), var(--brand));
  color: #fff; border-color: var(--brand-dk);
  box-shadow: 0 1px 3px rgba(45,107,36,.30);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--brand), var(--brand-dk)); border-color: var(--brand-xdk); }
.btn-danger  { background: var(--accent-lt); color: var(--accent-dk); border-color: #F4B0B3; }
.btn-danger:hover { background: #F4B0B3; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 9px; font-size: 11px; }

/* === FORMULARIOS === */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label { font-size: 12px; color: var(--text2); font-weight: 600; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], input[type=time], input[type=tel], input[type=search],
select, textarea {
  width: 100%; padding: 10px 12px; min-height: 42px;
  border: 1px solid var(--border2); border-radius: var(--radius-md);
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface); transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input[readonly] { background: var(--bg2); color: var(--text2); }
textarea { resize: vertical; min-height: 76px; }
::placeholder { color: var(--text3); }

/* === BADGES === */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green  { background: var(--green-light); color: var(--green-dark); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-red    { background: var(--red-light); color: var(--red); }
.badge-blue   { background: var(--blue-light); color: var(--blue); }
.badge-gray   { background: var(--bg2); color: var(--text2); }
.badge-purple { background: #EEEDFE; color: #3C3489; }

/* === ALERTAS === */
.alert { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--green-light); color: var(--green-dark); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.alert-warning { background: var(--orange-light); color: var(--orange); border-color: color-mix(in srgb, var(--orange) 35%, transparent); }
.alert-danger  { background: var(--red-light); color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.alert-info    { background: var(--blue-light); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }

/* === TABS (segmented control) === */
.tabs {
  display: flex; gap: 3px; margin-bottom: 18px;
  background: var(--bg2); padding: 4px;
  border-radius: var(--radius-md); width: fit-content; max-width: 100%;
  flex-wrap: wrap; border: 1px solid var(--border);
}
.tab-btn {
  padding: 8px 16px; border-radius: 9px; font-size: 13px; cursor: pointer;
  color: var(--text2); border: none; background: transparent;
  font-family: var(--font); font-weight: 600; transition: background .14s, color .14s, box-shadow .14s;
  text-decoration: none; display: inline-block;
}
.tab-btn:hover { color: var(--brand); }
.tab-btn.active { background: var(--surface); color: var(--brand-dk); box-shadow: var(--shadow); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* === PROGRESS === */
.prog { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.prog-bar { height: 100%; background: linear-gradient(90deg, var(--brand-mid), var(--brand)); border-radius: 4px; }

/* === MODAL === */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  align-items: flex-start; justify-content: center; padding: 40px 16px;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; animation: fadein .2s ease; }
.modal-box {
  background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border2);
  padding: 24px; width: 500px; max-width: 100%; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-title  { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }

/* === SEMÁFORO === */
.semaforo { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.sem-verde   { background: var(--green); }
.sem-naranja { background: #BA7517; }
.sem-rojo    { background: var(--red); }

/* === UTILIDADES === */
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-orange { color: var(--orange); }
.text-blue   { color: var(--blue); }
.text-muted  { color: var(--text2); }
.fw-500      { font-weight: 500; }
.text-right  { text-align: right; }
.mb-0  { margin-bottom: 0; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* === LOGIN === */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(135deg, var(--brand-xdk) 0%, var(--brand-dk) 55%, #2D6B24 100%);
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px; width: 400px; max-width: 100%;
  box-shadow: 0 12px 50px rgba(0,0,0,.30);
}
.login-logo { text-align: center; margin-bottom: 28px; display: flex; flex-direction: column; align-items: center; }

/* ============================================================
   RESPONSIVE — navegación tipo app en celular
   ============================================================ */
@media (max-width: 1024px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  /* Sidebar → drawer deslizable */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 270px;
    transform: translateX(-100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
    padding-top: env(safe-area-inset-top);
  }
  .app.drawer-open .sidebar { transform: translateX(0); }
  .app.drawer-open .scrim   { display: block; opacity: 1; }

  .topbar-btn { display: inline-flex; }

  /* Barra inferior tipo app */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    backdrop-filter: saturate(140%) blur(12px);
    box-shadow: 0 -2px 14px rgba(0,0,0,.08);
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 9px 4px 7px; text-decoration: none; color: var(--text3);
    font-size: 10.5px; font-weight: 600; transition: color .14s; background: none; border: none;
    font-family: var(--font); cursor: pointer;
  }
  .bn-item svg { opacity: .9; }
  .bn-item.active { color: var(--brand); }
  html[data-theme="dark"] .bn-item.active { color: var(--brand-mid); }
  .bn-item:active { transform: scale(.92); }

  .content { padding: 16px; padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .fecha-hoy { display: none; }
  .page-title { font-size: 16px; }

  .g2, .g3, .g4 { grid-template-columns: 1fr; gap: 12px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
}

@media (max-width: 420px) {
  .content { padding: 13px; padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .bn-item { font-size: 10px; }
}

/* === PRINT (se mantiene) === */
@media print {
  .sidebar, .scrim, .bottom-nav, .topbar-btn, .theme-toggle, .no-print,
  .btn, .tabs, nav { display: none !important; }
  .app { display: block; height: auto; overflow: visible; }
  .main, .content { overflow: visible; height: auto; padding: 0 !important; }
  body { font-size: 11px; background: #fff; color: #000; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; margin-bottom: 12px; }
  .tab-panel { display: block !important; }
  .alert { display: none; }
}
