/* ─── SYMT Console — Global Styles ─────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3250;
  --accent:    #4f6ef7;
  --accent-h:  #6b85ff;
  --danger:    #e05260;
  --success:   #3ecf8e;
  --warning:   #f5a623;
  --text:      #e2e5f0;
  --muted:     #7a80a0;
  --radius:    8px;
  --font:      'Inter', system-ui, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }

/* ─── Layout ────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.sidebar-logo span { color: var(--accent); }

.sidebar-section {
  padding: 12px 10px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-radius: 6px;
  margin: 1px 6px;
  color: var(--muted);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.sidebar nav a:hover,
.sidebar nav a.active {
  background: var(--surface2);
  color: var(--text);
}
.sidebar nav a.active { color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-footer strong { color: var(--text); display: block; }

.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 600;
}

.content {
  padding: 28px;
  max-width: 1200px;
}

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.sistema-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.sistema-card:hover { border-color: var(--accent); transform: translateY(-1px); }

.sistema-card-header { display: flex; align-items: center; justify-content: space-between; }
.sistema-card-name { font-size: 15px; font-weight: 600; }
.sistema-card-url { font-size: 12px; color: var(--muted); }

.stat-row { display: flex; gap: 20px; }
.stat { display: flex; flex-direction: column; }
.stat-val { font-size: 22px; font-weight: 700; }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: #1a3a2d; color: var(--success); }
.badge-red    { background: #3a1a1e; color: var(--danger); }
.badge-yellow { background: #3a2d10; color: var(--warning); }
.badge-blue   { background: #1a2a4a; color: var(--accent-h); }
.badge-muted  { background: var(--surface2); color: var(--muted); }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot-green  { background: var(--success); }
.dot-red    { background: var(--danger); }
.dot-yellow { background: var(--warning); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td {
  padding: 12px 14px;
  font-size: 13px;
  vertical-align: middle;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-success  { background: var(--success); color: #0a2018; }
.btn-success:hover { opacity: 0.85; }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--muted); }
.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
}
.form-control::placeholder { color: var(--muted); }

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-lg { max-width: 660px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  min-width: 260px;
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.2s ease;
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--danger); }
.toast.toast-info    { border-left: 3px solid var(--accent); }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ─── Misc ───────────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16  { margin-top: 16px; }
.mt-20  { margin-top: 20px; }
.flex   { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--muted); }
.text-sm    { font-size: 12px; }
.fw-600     { font-weight: 600; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
}
.pagination .btn-sm { min-width: 32px; justify-content: center; }

/* ─── Sidebar drawer helpers (desktop = ocultos) ───────────────────────── */
.sidebar-overlay { display: none; }
.hamburger { display: none; }

/* ─── Voucher card ───────────────────────────────────────────────────────── */
.voucher-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.voucher-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--muted);
}
.voucher-meta strong { color: var(--text); }
.voucher-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: contain;
  cursor: pointer;
}

/* ─── Mobile (<768px) — Todo lo de abajo es exclusivo de móvil ─────────── */
@media (max-width: 767.98px) {

  /* ── Layout base ── */
  .app { display: block; }
  .main { margin-left: 0; }
  .content {
    padding: 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    max-width: none;
  }

  /* ── Sidebar como cajón ── */
  .sidebar {
    width: 260px;
    max-width: 82vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-overlay {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 40;
  }
  body.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  /* Áreas táctiles en la nav del sidebar */
  .sidebar nav a { min-height: 44px; padding: 12px 14px; font-size: 14px; }
  .sidebar-footer { padding: 14px; }
  .sidebar-footer .btn { min-height: 44px; }

  /* ── Topbar ── */
  .topbar {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .topbar h1 {
    font-size: 15px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #topbar-date { display: none; }

  .hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
  }
  .hamburger svg { width: 22px; height: 22px; }

  /* Contenedores de filtros en topbar (vouchers, audit): saltan a nueva fila */
  .topbar .flex:has(.form-control) {
    flex: 1 0 100%;
    order: 3;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar .flex:has(.form-control) .form-control {
    width: 100% !important;
    flex: 1 1 100%;
    min-height: 40px;
  }
  .topbar .flex:has(.form-control) .btn { flex: 1 1 auto; min-height: 40px; }

  /* ── Botones: 44x44 mínimo ── */
  .btn { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .btn-sm { min-height: 40px; padding: 8px 14px; font-size: 13px; }

  /* ── Grids y stats: una columna ── */
  .card-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .stat-row { gap: 20px; flex-wrap: wrap; }

  /* Ajustar el grid inline de sistema.html (stats-row) */
  #stats-row { grid-template-columns: repeat(2, 1fr) !important; }

  /* ── Section header: filtros bajo el título ── */
  .section-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .section-header .flex { flex: 1 1 100%; }
  .section-header .form-control { width: 100% !important; }

  /* ── Tablas → tarjetas apiladas ── */
  .table-wrap {
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
  }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 12px 14px;
  }
  tbody tr:hover { background: var(--surface); }
  tbody tr:last-child { border-bottom: 1px solid var(--border); }

  tbody td {
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
    align-items: stretch;
    word-break: break-word;
  }
  tbody tr td:last-child { border-bottom: none; padding-bottom: 0; }
  tbody tr td:first-child { padding-top: 0; }

  tbody td::before {
    content: attr(data-label);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--muted);
    font-weight: 600;
  }

  /* Etiquetas por página (los tbody son únicos por vista) */
  .table-wrap:has(#audit-tbody) tbody td:nth-of-type(1)::before { content: "Fecha"; }
  .table-wrap:has(#audit-tbody) tbody td:nth-of-type(2)::before { content: "Sistema"; }
  .table-wrap:has(#audit-tbody) tbody td:nth-of-type(3)::before { content: "Organización"; }
  .table-wrap:has(#audit-tbody) tbody td:nth-of-type(4)::before { content: "Acción"; }
  .table-wrap:has(#audit-tbody) tbody td:nth-of-type(5)::before { content: "Detalle"; }

  .table-wrap:has(#sistemas-tbody) tbody td:nth-of-type(1)::before { content: "Nombre"; }
  .table-wrap:has(#sistemas-tbody) tbody td:nth-of-type(2)::before { content: "URL Base"; }
  .table-wrap:has(#sistemas-tbody) tbody td:nth-of-type(3)::before { content: "Campos"; }
  .table-wrap:has(#sistemas-tbody) tbody td:nth-of-type(4)::before { content: "Estado"; }
  .table-wrap:has(#sistemas-tbody) tbody td:nth-of-type(5)::before { content: "Acciones"; }

  .table-wrap:has(#orgs-tbody) tbody td:nth-of-type(1)::before { content: "Organización"; }
  .table-wrap:has(#orgs-tbody) tbody td:nth-of-type(2)::before { content: "Estado"; }
  .table-wrap:has(#orgs-tbody) tbody td:nth-of-type(3)::before { content: "Vencimiento"; }
  .table-wrap:has(#orgs-tbody) tbody td:nth-of-type(4)::before { content: "Config"; }
  .table-wrap:has(#orgs-tbody) tbody td:nth-of-type(5)::before { content: "Acciones"; }

  /* Celdas con colspan (spinner / vacío / error): sin etiqueta, texto centrado */
  tbody td[colspan] {
    display: block;
    text-align: center;
    padding: 24px 12px !important;
    border-bottom: none;
  }
  tbody td[colspan]::before { content: none; }

  /* Botones dentro de una celda de acciones: 2 columnas cómodas */
  tbody td .btn-group {
    flex-wrap: wrap;
    gap: 8px;
  }
  tbody td .btn-group .btn,
  tbody td .btn-group .btn-sm {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
    min-height: 44px;
    font-size: 13px;
  }

  /* ── Voucher card — pantalla prioritaria en el iPhone ── */
  .voucher-card { padding: 16px 14px; gap: 12px; }
  .voucher-card .flex.items-center.justify-between {
    flex-wrap: wrap;
    gap: 6px;
  }
  .voucher-card .fw-600 { font-size: 15px; }
  .voucher-meta { font-size: 13px; row-gap: 4px; }
  .voucher-img { max-height: 220px; }
  .voucher-card .btn-group {
    flex-wrap: wrap;
    gap: 8px;
  }
  .voucher-card .btn-group .btn {
    flex: 1 1 calc(50% - 4px);
    justify-content: center;
    min-height: 48px;
    font-size: 15px;
    font-weight: 600;
    padding: 12px 16px;
  }

  /* ── Modals ── */
  .modal-overlay {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    align-items: flex-start;
  }
  .modal { max-height: 92vh; padding: 18px; margin-top: 8vh; }
  .modal-lg { max-width: 100%; }
  .modal .form-control { min-height: 44px; font-size: 14px; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  /* Los grids internos de sistemas.html (campos-list) a una columna */
  #campos-list > div > div[style*="grid-template-columns"],
  #campos-list-edit > div > div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* ── Toast ── */
  #toast-container {
    left: 12px;
    right: 12px;
    bottom: max(16px, env(safe-area-inset-bottom));
  }
  .toast { min-width: 0; max-width: 100%; }

  /* ── Paginación ── */
  .pagination { flex-wrap: wrap; justify-content: center; }
  .pagination .btn-sm { min-height: 40px; min-width: 40px; }
}
