:root {
  --primary: #0d9488;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }

/* ---------- Login ---------- */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(135deg, var(--sidebar), var(--primary));
}
.auth-card {
  background: var(--card); border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
  padding: 32px; width: 100%; max-width: 380px;
}
.auth-card .brand { text-align: center; margin-bottom: 20px; }
.auth-card .brand img { max-height: 64px; max-width: 180px; object-fit: contain; }
.auth-card .brand .name { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-top: 8px; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.sidebar .logo { padding: 20px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .logo img { max-height: 36px; max-width: 120px; object-fit: contain; }
.sidebar .logo .name { font-weight: 700; font-size: 1.15rem; color: #fff; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px; color: var(--sidebar-text);
  font-weight: 500; border-left: 3px solid transparent;
}
.sidebar nav a .ic { width: 20px; text-align: center; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); }
.sidebar nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--primary); }
.sidebar .foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; }
.sidebar .foot .u { color: #fff; font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; align-items: center; justify-content: space-between;
  background: var(--sidebar); color: #fff; padding: 12px 16px; position: sticky; top: 0; z-index: 20;
}
.topbar .name { font-weight: 700; }
.content { padding: 22px; max-width: 1100px; width: 100%; margin: 0 auto; }

.bottomnav { display: none; }

/* ---------- Components ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: .85rem; }
.stat.accent { border-left: 4px solid var(--primary); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-weight: 600; cursor: pointer; font-size: .92rem; font-family: inherit;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: .95rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.muted { background: #e2e8f0; color: #475569; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal .modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal .modal-body { padding: 20px; }
.modal .modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.x-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); line-height: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 100; font-weight: 500; max-width: 90vw;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.spinner { text-align: center; padding: 50px; color: var(--muted); }
.right { text-align: right; } .center { text-align: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- Responsive / móvil ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .content { padding: 14px 14px 88px; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
    border-top: 1px solid var(--border); z-index: 30; padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a {
    flex: 1; text-align: center; padding: 9px 2px; color: var(--muted); font-size: .68rem; font-weight: 600;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  .bottomnav a .ic { font-size: 1.25rem; }
  .bottomnav a.active { color: var(--primary); }
  .stat .value { font-size: 1.4rem; }
  .page-head h1 { font-size: 1.2rem; }
}
