/* =========================================================
   ContaDoc - Gestor Documental Contable
   Paleta: Verde esmeralda + grafito
   ========================================================= */
:root {
  --brand:        #059669;
  --brand-dark:   #047857;
  --brand-darker: #065f46;
  --brand-deep:   #064e3b;
  --brand-soft:   #d1fae5;
  --brand-tint:   #ecfdf5;
  --accent:       #34d399;

  --graphite:     #1f2937;
  --graphite-700: #374151;
  --graphite-500: #6b7280;
  --graphite-300: #d1d5db;

  --bg:           #eef2f1;
  --card:         #ffffff;
  --line:         #e5e7eb;

  --ok:           #059669;
  --warn:         #d97706;
  --danger:       #dc2626;
  --info:         #2563eb;

  --radius:       18px;
  --radius-sm:    12px;
  --shadow:       0 10px 30px rgba(6, 78, 59, .08);
  --shadow-sm:    0 4px 14px rgba(15, 23, 42, .06);

  --sidebar-w:    256px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--graphite);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---------- Layout principal ---------- */
.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--brand-darker) 0%, var(--brand-deep) 100%);
  color: #e7f6ef;
  padding: 26px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-radius: 0 32px 32px 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 22px;
}
.brand .logo {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(52, 211, 153, .35);
}
.brand .logo svg { width: 24px; height: 24px; color: #fff; }
.brand .brand-text strong { display: block; font-size: 18px; letter-spacing: .3px; color: #fff; }
.brand .brand-text span { font-size: 11px; color: #a7d8c4; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: #7fc3a7; padding: 14px 14px 6px;
}
.nav a {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 14px;
  border-radius: 12px;
  color: #c9e9da;
  font-size: 14.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active {
  background: #fff;
  color: var(--brand-darker);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.sidebar-footer { margin-top: auto; padding-top: 14px; }
.sidebar-footer a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px;
  color: #bfe6d4; font-size: 14px;
}
.sidebar-footer a:hover { background: rgba(255,255,255,.08); color:#fff; }
.sidebar-footer a svg { width: 19px; height: 19px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 22px 30px;
}
.topbar .greeting h1 { margin: 0; font-size: 22px; font-weight: 700; color: var(--graphite); }
.topbar .greeting p { margin: 2px 0 0; font-size: 13px; color: var(--graphite-500); }

.search {
  margin-left: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 9px 16px;
  width: 320px; max-width: 38vw;
  box-shadow: var(--shadow-sm);
}
.search svg { width: 18px; height: 18px; color: var(--graphite-500); }
.search input { border: none; outline: none; width: 100%; font-size: 14px; background: transparent; color: var(--graphite); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-sm); position: relative; color: var(--graphite-700);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn .dot {
  position: absolute; top: 9px; right: 10px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid #fff;
}
.empresa-selector select {
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 30px;
  background: var(--card); color: var(--graphite); font-size: 13px; font-weight: 600;
  outline: none; box-shadow: var(--shadow-sm); cursor: pointer; max-width: 200px;
}
.empresa-selector select:focus { border-color: var(--brand); }

.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow-sm);
}

.content { padding: 6px 30px 40px; }

/* Boton hamburguesa y overlay (solo visibles en movil) */
.menu-toggle { display: none; }
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6, 31, 24, .5); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: opacity .25s;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px;
  border: 1px solid var(--line);
}
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
}
.kpi .kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon.green  { background: var(--brand-tint); color: var(--brand-dark); }
.kpi-icon.amber  { background: #fef3c7; color: var(--warn); }
.kpi-icon.blue   { background: #dbeafe; color: var(--info); }
.kpi-icon.slate  { background: #eef2f7; color: var(--graphite-700); }
.kpi .kpi-value { font-size: 27px; font-weight: 700; color: var(--graphite); line-height: 1; }
.kpi .kpi-label { font-size: 13px; color: var(--graphite-500); }
.kpi .kpi-trend { font-size: 12px; font-weight: 600; }
.kpi .kpi-trend.up { color: var(--ok); }

/* ---------- Cards / panels ---------- */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 18px; }
.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; color: var(--graphite); }
.panel-head .muted { font-size: 12px; color: var(--graphite-500); }

/* ---------- Charts ---------- */
.charts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.charts-grid .span-2 { grid-column: span 2; }
.charts-grid > .panel { min-width: 0; }       /* evita que el canvas desborde la celda */
.panel { min-width: 0; }
.chart-box { position: relative; width: 100%; min-width: 0; height: 280px; }
.chart-box.tall { height: 320px; }
.chart-box canvas { max-width: 100% !important; }
.panel-head .legend-dots { display: flex; gap: 14px; }
.legend-dots span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--graphite-500); }
.legend-dots i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

@media (max-width: 1200px) {
  .charts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid .span-2 { grid-column: span 2; }
}
@media (max-width: 760px) {
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid .span-2 { grid-column: span 1; }
  .chart-box, .chart-box.tall { height: 240px; }
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; padding: 12px 14px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--graphite-500); border-bottom: 1px solid var(--line);
}
table.data td { padding: 13px 14px; border-bottom: 1px solid var(--line); color: var(--graphite-700); }
table.data tbody tr:hover { background: var(--brand-tint); }
table.data tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: 30px;
  font-size: 12px; font-weight: 600;
}
.badge.pendiente   { background: #fef3c7; color: #92400e; }
.badge.registrado  { background: #dbeafe; color: #1e40af; }
.badge.pagado      { background: var(--brand-soft); color: var(--brand-darker); }
.badge.anulado     { background: #fee2e2; color: #991b1b; }
.badge.borrador    { background: #e5e7eb; color: #374151; }
.badge.contabilizado { background: var(--brand-soft); color: var(--brand-darker); }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
  border: none; cursor: pointer; transition: background .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn svg { width: 17px; height: 17px; }
.btn.ghost { background: #fff; color: var(--brand-dark); border: 1px solid var(--brand-soft); }
.btn.ghost:hover { background: var(--brand-tint); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filters input, .filters select {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--graphite); outline: none;
}
.filters input:focus, .filters select:focus { border-color: var(--brand); }
.filters input[type=search] { min-width: 240px; }

/* ---------- Module cards grid ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.feature-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand-soft); }
.feature-card .fc-icon {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--brand-tint); color: var(--brand-dark);
  display: grid; place-items: center; margin-bottom: 14px;
}
.feature-card .fc-icon svg { width: 23px; height: 23px; }
.feature-card h3 { margin: 0 0 6px; font-size: 15px; color: var(--graphite); }
.feature-card p { margin: 0; font-size: 13px; color: var(--graphite-500); line-height: 1.5; }

/* ---------- Forms (CRUD) ---------- */
.form-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow-sm); max-width: 880px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field { display: flex; flex-direction: column; gap: 7px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--graphite-700); }
.form-field input, .form-field select, .form-field textarea {
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--graphite); outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s; font-family: inherit;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(5,150,105,.13);
}
.form-field .help { font-size: 12px; color: var(--graphite-500); }
.form-field .err { font-size: 12.5px; color: var(--danger); }
.form-field.has-error input, .form-field.has-error select { border-color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.required-star { color: var(--danger); }

.btn.secondary { background: #fff; color: var(--graphite-700); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f8fafc; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 7px 12px; font-size: 13px; }

/* Acciones en tabla */
.row-actions { display: flex; gap: 6px; }
.icon-action {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; display: grid; place-items: center; color: var(--graphite-700); cursor: pointer;
}
.icon-action:hover { background: var(--brand-tint); color: var(--brand-dark); border-color: var(--brand-soft); }
.icon-action svg { width: 16px; height: 16px; }
.icon-action.danger:hover { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }

/* Page header con boton */
.page-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }

/* Detalle (definicion) */
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 28px; }
.detail-grid .full { grid-column: 1 / -1; }
.detail-item .dt { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--graphite-500); margin-bottom: 4px; }
.detail-item .dd { font-size: 15px; color: var(--graphite); font-weight: 500; }

/* Confirmacion eliminar */
.confirm-box { max-width: 520px; text-align: center; }
.confirm-box .warn-ico { width: 60px; height: 60px; border-radius: 50%; background: #fee2e2; color: var(--danger); display: grid; place-items: center; margin: 0 auto 16px; }
.confirm-box .warn-ico svg { width: 30px; height: 30px; }

/* Rol badge */
.rol-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--brand-tint); color: var(--brand-dark); }

/* Formset (asientos) */
.detalle-row { display: grid; grid-template-columns: 2fr 2fr 1.2fr 1.2fr 40px; gap: 10px; align-items: end; margin-bottom: 10px; }
.detalle-row .form-field { gap: 4px; }
.formset-totales { display: flex; gap: 24px; justify-content: flex-end; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 14px; }
.formset-totales b { color: var(--graphite); }
.cuadre-ok { color: var(--ok); font-weight: 700; }
.cuadre-bad { color: var(--danger); font-weight: 700; }

@media (max-width: 720px) {
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .detalle-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--graphite-500); }
.empty svg { width: 48px; height: 48px; color: var(--graphite-300); margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--graphite-700); font-size: 16px; }

/* ---------- Messages ---------- */
.messages { margin: 0 30px 10px; }
.alert {
  padding: 12px 16px; border-radius: 10px; font-size: 14px; margin-bottom: 8px;
  border: 1px solid transparent;
}
.alert.success { background: var(--brand-soft); color: var(--brand-darker); border-color: var(--accent); }
.alert.danger  { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.alert.info    { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.alert.warning { background: #fef3c7; color: #92400e; border-color: #fcd34d; }

.section-title { font-size: 13px; color: var(--graphite-500); margin: 0 0 14px; }
.pill-count { background: var(--brand-tint); color: var(--brand-dark); padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.text-right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-art {
  background: linear-gradient(150deg, var(--brand-darker), var(--brand-deep) 70%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center;
  position: relative; overflow: hidden;
}
.login-art::after {
  content: ""; position: absolute; right: -120px; bottom: -120px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(52,211,153,.35), transparent 70%);
}
.login-art .logo-lg {
  width: 60px; height: 60px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  display: grid; place-items: center; margin-bottom: 28px;
}
.login-art .logo-lg svg { width: 32px; height: 32px; color: #fff; }
.login-art h1 { font-size: 34px; margin: 0 0 14px; line-height: 1.2; }
.login-art p { font-size: 15px; color: #b8e6d3; max-width: 380px; line-height: 1.6; }
.login-features { margin-top: 34px; display: flex; flex-direction: column; gap: 14px; }
.login-features div { display: flex; align-items: center; gap: 12px; font-size: 14px; color: #d6f3e6; }
.login-features svg { width: 20px; height: 20px; color: var(--accent); }

.login-form-side { display: grid; place-items: center; padding: 40px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 24px; margin: 0 0 6px; color: var(--graphite); }
.login-card .sub { color: var(--graphite-500); font-size: 14px; margin: 0 0 26px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--graphite-700); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 13px 15px; border: 1px solid var(--line);
  border-radius: 11px; font-size: 14.5px; outline: none; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(5,150,105,.15); }
.btn-full { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }
.login-hint { margin-top: 18px; font-size: 12.5px; color: var(--graphite-500); text-align: center; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Tablet y movil: sidebar deslizable */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: -300px; top: 0; z-index: 50;
    border-radius: 0 24px 24px 0; transition: left .25s ease;
  }
  .sidebar.open { left: 0; }
  .menu-toggle { display: grid; }
  .content { padding: 6px 18px 36px; }
  .topbar { padding: 16px 18px; gap: 12px; flex-wrap: wrap; }
  .topbar .greeting { order: 2; flex: 1 1 100%; }
  .topbar .greeting h1 { font-size: 19px; }
  .search { order: 3; width: 100%; max-width: none; margin-left: 0; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar .icon-btn:nth-of-type(3) { display: none; } /* oculta correo en pantallas muy chicas */
  .filters input[type=search] { min-width: 0; width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
  table.data { font-size: 13px; }
  .content { padding: 6px 14px 32px; }
}

/* ---------- Utilidades para modulos: bancos, activos, presupuestos, tributario ---------- */
.data th.num, .data td.num { text-align: right; }
.data td.num.mono, .data th.num { white-space: nowrap; }

.progress {
  width: 120px;
  height: 8px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
.progress span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 6px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.detail-grid .muted { font-size: 12px; }
