/* ══════════════════════════════════════════════════════════════
   ENOWEB v2 — Design System | Multi-Viña
   Tema: Madera Profunda — roble oscuro, vino, oro envejecido
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500;600;700&family=Lato:wght@300;400;500;700&display=swap');

/* ── Paleta madera ─────────────────────────────────────────── */
:root {
  /* Fondos — roble oscuro */
  --bg:          #160c06;
  --bg2:         #1f1008;
  --bg3:         #2a160a;
  --surface:     #341c0e;
  --surface2:    #3e2210;
  --surface3:    #4a2912;

  /* Bordes */
  --border:      rgba(185,130,65,.18);
  --border2:     rgba(185,130,65,.30);

  /* Acentos madera */
  --oak:         #C87941;   /* roble claro */
  --oak-dim:     rgba(200,121,65,.14);
  --oak-glow:    rgba(200,121,65,.22);
  --mahogany:    #8B4513;   /* caoba */
  --teak:        #9C6B2E;   /* teca */

  /* Vino / cosecha */
  --wine:        #6B2737;
  --wine-bright: #8B3248;
  --wine-dim:    rgba(107,39,55,.22);

  /* Oro envejecido */
  --gold:        #C8953A;
  --gold-light:  #E4B45A;
  --gold-dim:    rgba(200,149,58,.14);
  --gold-glow:   rgba(200,149,58,.25);

  /* Texto */
  --text:        #F0E4D0;
  --text2:       #B8906A;
  --text3:       #7A5A3A;

  /* Estados */
  --green:       #5D9E6A;
  --green-dim:   rgba(93,158,106,.16);
  --red:         #C25050;
  --red-dim:     rgba(194,80,80,.16);
  --amber:       #D4953A;
  --amber-dim:   rgba(212,149,58,.16);
  --blue:        #4A7FA8;
  --blue-dim:    rgba(74,127,168,.16);

  /* Tipografía */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'Lato', system-ui, sans-serif;

  /* Geometría */
  --radius:      8px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --shadow:      0 4px 28px rgba(0,0,0,.55);
  --shadow-lg:   0 8px 52px rgba(0,0,0,.70);
  --transition:  .18s cubic-bezier(.4,0,.2,1);

  --sidebar-w:   248px;
  --header-h:    60px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }
img { max-width: 100%; }

/* ══ LAYOUT ══════════════════════════════════════════════════ */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  grid-column: 1 / -1;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: var(--sidebar-w);
  padding-right: 20px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--mahogany), var(--oak));
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 0 18px var(--oak-glow);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .04em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 9px;
  font-weight: 400;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 2px;
  display: block;
}

/* Switcher viña */
.vina-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 12px 5px 10px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
  color: var(--text2);
}
.vina-switcher:hover { border-color: var(--gold); color: var(--gold); }
.vina-switcher .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.vina-switcher select {
  background: none; border: none; color: inherit; font-size: inherit;
  outline: none; cursor: pointer; font-family: var(--font-body); padding: 0;
}

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.btn-header {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 14px;
  color: var(--text2); font-size: 13px; cursor: pointer;
  font-family: var(--font-body); transition: var(--transition);
}
.btn-header:hover { border-color: var(--gold); color: var(--gold); background: var(--bg3); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 5px 12px;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--wine), var(--mahogany));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--text);
}
.user-info { line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 500; color: var(--text); }
.user-role { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
  z-index: 50;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 2px; }

.nav-section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--text3);
  padding: 18px 18px 5px;
  font-weight: 700;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  cursor: pointer;
  color: var(--text2);
  font-size: 13.5px;
  border-left: 3px solid transparent;
  transition: var(--transition);
  text-decoration: none;
}
.nav-item i { width: 17px; text-align: center; font-size: 13px; }
.nav-item:hover { background: var(--surface); color: var(--text); border-left-color: var(--oak); }
.nav-item.active { background: var(--surface2); color: var(--gold-light); border-left-color: var(--gold); }
.nav-item .badge {
  margin-left: auto; background: var(--wine); color: var(--text);
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  font-size: 11px;
  color: var(--text3);
}
.cosecha-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--wine-dim); border: 1px solid rgba(107,39,55,.4);
  border-radius: 20px; padding: 3px 10px; font-size: 11px;
  color: #D07080; font-weight: 600;
}

/* ── Contenido principal ─────────────────────────────────────── */
.main-content {
  padding: 28px 32px;
  overflow-y: auto;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}
.page-subtitle { font-size: 13px; color: var(--text3); margin-top: 3px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Botones ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text2); font-size: 13.5px; cursor: pointer;
  font-family: var(--font-body); transition: var(--transition);
  font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }

.btn-primary {
  background: var(--wine); border-color: var(--wine-bright); color: var(--text);
}
.btn-primary:hover { background: var(--wine-bright); border-color: var(--wine-bright); color: #fff; }

.btn-gold {
  background: var(--gold); border-color: var(--gold-light); color: #1a0900;
}
.btn-gold:hover { background: var(--gold-light); }

.btn-oak {
  background: var(--oak-dim); border-color: var(--oak); color: var(--oak);
}
.btn-oak:hover { background: var(--oak); color: #1a0900; }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-danger { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ── KPIs ────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 16px; margin-bottom: 28px; }
.kpi {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--wine), var(--oak));
}
.kpi-icon { position: absolute; bottom: 14px; right: 16px; font-size: 28px; opacity: .12; }
.kpi-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.8px; color: var(--text3); margin-bottom: 7px; font-weight: 700; }
.kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 600; color: var(--text); line-height: 1; }
.kpi-sub { font-size: 11.5px; color: var(--text3); margin-top: 5px; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 22px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 10px;
}
.card-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.card-title::before {
  content: ''; display: block; width: 3px; height: 16px;
  background: var(--gold); border-radius: 2px;
}

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }

.cuba-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  cursor: pointer; transition: var(--transition);
}
.cuba-card:hover { transform: translateY(-2px); border-color: var(--gold); box-shadow: 0 8px 28px rgba(0,0,0,.5); }
.cuba-card.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-dim); }

/* ── Tablas ──────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead tr { background: var(--surface); border-bottom: 1px solid var(--border2); }
thead th { text-align: left; padding: 10px 14px; color: var(--text3); font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.8px; font-weight: 700; }
tbody tr { border-bottom: 1px solid rgba(185,130,65,.08); transition: background var(--transition); }
tbody tr:hover { background: var(--surface); }
tbody td { padding: 10px 14px; color: var(--text2); vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ── Tags / Badges ───────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 2px 10px;
  border-radius: 20px; font-size: 11px; font-weight: 600;
}
.tag-green { background: var(--green-dim); color: var(--green); }
.tag-amber { background: var(--amber-dim); color: var(--amber); }
.tag-red   { background: var(--red-dim);   color: var(--red);   }
.tag-blue  { background: var(--blue-dim);  color: var(--blue);  }
.tag-gray  { background: rgba(100,80,60,.2); color: var(--text3); }
.tag-wine  { background: var(--wine-dim); color: #D07080; }
.tag-oak   { background: var(--oak-dim);  color: var(--oak);   }

/* ── Formularios ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

label {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--text3); margin-bottom: 6px; font-weight: 700;
}

input, select, textarea {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 13px;
  color: var(--text); font-family: var(--font-body);
  font-size: 14px; transition: border-color var(--transition); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); background: var(--surface2); }
input::placeholder { color: var(--text3); }
select option { background: var(--surface); color: var(--text); }
textarea { resize: vertical; min-height: 78px; }

/* ── Modales ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.82); z-index: 500;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 {
  font-family: var(--font-display); font-size: 18px; font-weight: 600; color: var(--text);
}
.modal-close {
  background: none; border: none; color: var(--text3); font-size: 22px;
  cursor: pointer; padding: 2px 8px; border-radius: 6px; transition: var(--transition);
}
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-body { padding: 22px 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ── Progress ────────────────────────────────────────────────── */
.progress { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--wine), var(--oak)); transition: width .5s ease; }

/* ── Timeline ────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 14px; }
.tl-dot { position: absolute; left: -22px; top: 13px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--gold); background: var(--bg2); }
.tl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 15px; }
.tl-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; flex-wrap: wrap; gap: 6px; }
.tl-op { font-size: 13px; font-weight: 600; color: var(--text); }
.tl-fecha { font-size: 11px; color: var(--text3); }
.tl-body { font-size: 12.5px; color: var(--text3); }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; background: var(--surface); border-radius: var(--radius); padding: 4px; border: 1px solid var(--border); width: fit-content; }
.tab { padding: 7px 18px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text3); transition: var(--transition); }
.tab:hover { color: var(--text); }
.tab.active { background: var(--wine); color: var(--text); }

/* ── Toast ───────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--gold); color: #160c06;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 700; z-index: 1000;
  opacity: 0; transform: translateY(10px); transition: all .3s;
  pointer-events: none; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--red); color: #fff; }

/* ── Loader ──────────────────────────────────────────────────── */
.loader { text-align: center; padding: 40px; color: var(--text3); font-size: 14px; }
.loader::after { content: '...'; animation: dots 1.5s infinite; }
@keyframes dots { 0%,100%{content:'...'} 33%{content:'.'} 66%{content:'..'}  }

/* ── Permisos grid ───────────────────────────────────────────── */
.perms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.perm-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; cursor: pointer;
  transition: var(--transition); font-size: 13px; color: var(--text2);
}
.perm-item:hover { border-color: var(--gold-light); color: var(--text); }
.perm-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--gold); flex-shrink: 0; }
.perm-item.checked { background: var(--gold-dim); border-color: var(--gold); color: var(--text); }

/* ── Perfil badges ───────────────────────────────────────────── */
.perfil-0 { background: rgba(107,39,55,.3); color: #E07080; }
.perfil-1 { background: var(--gold-dim); color: var(--gold-light); }
.perfil-2 { background: var(--blue-dim); color: var(--blue); }
.perfil-3 { background: var(--oak-dim);  color: var(--oak); }
.perfil-4 { background: rgba(100,80,60,.2); color: var(--text3); }

/* ── Análisis Grilla ─────────────────────────────────────────── */
.analisis-grid-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); margin-top: 16px; }
.analisis-grid { border-collapse: collapse; font-size: 12.5px; min-width: 700px; }
.analisis-grid th { background: var(--surface); padding: 8px 13px; text-align: center; color: var(--text3); font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.5px; border: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 10; }
.analisis-grid th.param-head { text-align: left; position: sticky; left: 0; z-index: 20; min-width: 150px; background: var(--surface); }
.analisis-grid td { border: 1px solid rgba(185,130,65,.08); padding: 0; }
.analisis-grid td.param-name { background: var(--surface); padding: 8px 13px; color: var(--text2); font-size: 12.5px; position: sticky; left: 0; z-index: 5; white-space: nowrap; }
.analisis-grid input.cell-input { background: transparent; border: none; width: 90px; text-align: center; color: var(--text); font-size: 13px; padding: 7px 8px; border-radius: 0; }
.analisis-grid input.cell-input:focus { background: var(--surface2); border: 1px solid var(--gold); border-radius: 4px; z-index: 1; position: relative; }
.analisis-grid .cell-ok { background: var(--green-dim); }
.analisis-grid .cell-warn { background: var(--red-dim); }

/* ── Alert box ───────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 18px; }
.alert-info    { background: var(--blue-dim);  border: 1px solid var(--blue);  color: var(--blue); }
.alert-success { background: var(--green-dim); border: 1px solid var(--green); color: var(--green); }
.alert-warning { background: var(--amber-dim); border: 1px solid var(--amber); color: var(--amber); }
.alert-danger  { background: var(--red-dim);   border: 1px solid var(--red);   color: var(--red); }

/* ── CB Card ─────────────────────────────────────────────────── */
.cb-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; cursor: pointer; transition: var(--transition);
}
.cb-card:hover { border-color: var(--oak); }
.cb-code { font-family: monospace; font-size: 13px; font-weight: 700; color: var(--gold); letter-spacing: .5px; }

/* ── Login page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 60%, rgba(107,39,55,.18) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 20%, rgba(200,121,65,.12) 0%, transparent 50%),
              var(--bg);
  padding: 20px;
}
.login-box {
  width: 100%; max-width: 420px;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-xl); padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
}
.login-logo .ico {
  width: 70px; height: 70px; border-radius: 20px;
  background: linear-gradient(135deg, var(--mahogany), var(--oak));
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; margin: 0 auto 14px;
  box-shadow: 0 0 40px var(--oak-glow);
}
.login-logo h1 { font-family: var(--font-display); font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: 3px; }
.login-logo p { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 2.5px; margin-top: 4px; }

/* ── Responsive ──────────────────────────────────────────────── */
.burger { display: none; position: fixed; top: 14px; left: 14px; z-index: 300; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 38px; height: 38px; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; color: var(--text); }
#overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 90; }
#overlay.open { display: block; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .header-brand { width: auto; border-right: none; }
  .sidebar { position: fixed; left: -260px; top: 0; height: 100vh; transition: left .3s ease; z-index: 200; }
  .sidebar.open { left: 0; }
  .main-content { margin-left: 0; padding: 20px; }
  .burger { display: flex; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
