:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #98989d;
  --border: #e6e6eb;
  --border-strong: #d2d2d7;
  --accent: #0071e3;
  --accent-soft: #eaf3fe;
  --green: #1f9d55;
  --green-soft: #e6f5ec;
  --amber: #9a6b00;
  --amber-soft: #fbf1d9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --sidebar-w: 250px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei",
    "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  gap: 26px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(150deg, #0a84ff, #0058c8);
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: 0.5px;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 650; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; border: 0; background: transparent;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; color: var(--text-2);
  cursor: pointer; text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item .ico { width: 18px; height: 18px; fill: currentColor; opacity: 0.85; flex: 0 0 auto; }
.nav-item:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.nav-item.is-active .ico { opacity: 1; }
.nav-item.is-soon { color: var(--text-3); cursor: default; }
.soon {
  margin-left: auto; font-size: 10px; letter-spacing: 0.3px;
  background: var(--border); color: var(--text-3);
  padding: 2px 7px; border-radius: 999px; text-transform: uppercase;
}

.user-card {
  margin-top: auto; display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--border);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--border-strong); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-size: 13px; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--text-3); }
.user-action {
  margin-left: auto; flex: 0 0 auto; border: 0; background: transparent;
  color: var(--accent); font: inherit; font-size: 12px; font-weight: 560;
  cursor: pointer; padding: 4px 6px; border-radius: 7px;
}
.user-action:hover { background: var(--accent-soft); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

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

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; padding: 26px 34px 18px;
}
.page-title { margin: 0; font-size: 26px; font-weight: 680; letter-spacing: -0.02em; }
.page-sub { margin: 4px 0 0; font-size: 13.5px; color: var(--text-2); }

.lang-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px; }
.lang-toggle button {
  border: 0; background: transparent; font: inherit; font-size: 13px;
  color: var(--text-2); padding: 5px 13px; border-radius: 999px; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-toggle button.is-active { background: var(--text); color: #fff; }

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

/* ===== Toolbar (search + filtros + chips) ===== */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.search {
  position: relative; flex: 1 1 260px; max-width: 360px;
}
.search input {
  width: 100%; font: inherit; font-size: 14px;
  padding: 10px 12px 10px 36px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; fill: var(--text-3); }

.filters { display: inline-flex; gap: 6px; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface);
  font: inherit; font-size: 13px; color: var(--text-2);
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--text-3); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.summary { margin-left: auto; display: inline-flex; gap: 8px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; padding: 4px 14px; border-left: 1px solid var(--border); }
.stat b { font-size: 18px; font-weight: 680; }
.stat span { font-size: 11px; color: var(--text-3); }

/* ===== Tabla ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 580; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-3);
  padding: 13px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  position: sticky; top: 0;
}
tbody td { padding: 13px 18px; font-size: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--surface-2); }

.person { display: flex; align-items: center; gap: 11px; }
.person .ava {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 650; color: #fff;
}
.person-name { font-weight: 540; }
.person-dept { font-size: 12px; color: var(--text-3); }

.tag { display: inline-flex; align-items: center; font-size: 12px; font-weight: 540; padding: 3px 10px; border-radius: 999px; }
.tag-level { background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-2); }
.tag-active { background: var(--green-soft); color: var(--green); }
.tag-inactive { background: var(--border); color: var(--text-3); }
.badges { display: inline-flex; gap: 6px; }
.badge { font-size: 11px; font-weight: 560; padding: 3px 9px; border-radius: 7px; }
.badge-evltr { background: var(--accent-soft); color: var(--accent); }
.badge-evltd { background: var(--amber-soft); color: var(--amber); }
.muted { color: var(--text-3); }

/* ===== Estados ===== */
.state { padding: 60px 20px; text-align: center; color: var(--text-2); }
.state h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); font-weight: 600; }
.state p { margin: 0 0 16px; font-size: 13.5px; }
.state button { font: inherit; font-size: 13px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 9px; cursor: pointer; }
.state button:hover { border-color: var(--text-3); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin 0.7s linear infinite; }

.fade-in { animation: fade 0.25s ease both; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== Responsive ===== */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: var(--sidebar-w); transform: translateX(-100%); transition: transform 0.2s ease; }
  .summary { display: none; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
  .person-dept { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ===== Botones generales ===== */
.btn {
  font: inherit; font-size: 13.5px; font-weight: 540; cursor: pointer;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 7px;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--text-3); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #0064c8; border-color: #0064c8; }
.btn-danger { background: #e5484d; border-color: #e5484d; color: #fff; }
.btn-danger:hover { background: #d23b40; border-color: #d23b40; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.add-btn { margin-left: 4px; }

/* ===== Acciones por fila ===== */
.row-actions { display: inline-flex; gap: 4px; opacity: 0; transition: opacity 0.12s ease; }
tbody tr:hover .row-actions { opacity: 1; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; cursor: pointer; display: grid; place-items: center;
  color: var(--text-2); transition: all 0.12s ease;
}
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }
.icon-btn:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.icon-btn.danger:hover { color: #e5484d; border-color: #f3c0c2; background: #fdeced; }
th.col-actions, td.col-actions { width: 86px; text-align: right; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50;
  animation: fade 0.18s ease both; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22); animation: pop 0.2s ease both;
}
.modal-sm { max-width: 420px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 14px; }
.modal header h2 { margin: 0; font-size: 18px; font-weight: 650; }
.modal .x { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--text-3); cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.modal .x:hover { background: var(--surface-2); color: var(--text); }
.modal .form { padding: 4px 22px 8px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px 20px; border-top: 1px solid var(--border); margin-top: 8px; }
.modal .msg { margin: 0 22px; padding: 10px 12px; border-radius: 9px; font-size: 13px; background: #fdeced; color: #c0282d; display: none; }
.modal .msg.show { display: block; }
.modal .confirm-text { padding: 0 22px 4px; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.modal .confirm-text b { color: var(--text); }

/* ===== Formulario ===== */
.field { margin-bottom: 14px; }
.field.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 540; color: var(--text-2); margin-bottom: 6px; }
.field input[type="text"], .field input[type="email"], .field select {
  width: 100%; font: inherit; font-size: 14px; padding: 9px 11px;
  border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.switches { display: flex; gap: 18px; margin: 4px 0 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ===== Toast ===== */
.toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: #fff; font-size: 13.5px; padding: 11px 18px; border-radius: 11px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22); animation: toastIn 0.2s ease both; }
.toast.err { background: #c0282d; }
@keyframes pop { from { opacity: 0; transform: scale(0.97) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 560px) { .field.row2 { grid-template-columns: 1fr; } }

/* ===== Acciones de fila: kebab + menú flotante ===== */
.col-actions { width: 52px; text-align: right; }
.kebab { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; color: var(--text-3); display: inline-grid; place-items: center; }
.kebab svg { width: 18px; height: 18px; fill: currentColor; }
.kebab:hover { background: var(--surface-2); color: var(--text); }
.row-menu { position: fixed; z-index: 90; width: 170px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 6px; animation: fade .12s ease both; }
.row-menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; font: inherit; font-size: 13.5px; color: var(--text); padding: 8px 11px; border-radius: 7px; cursor: pointer; }
.row-menu-item:hover { background: var(--surface-2); }
.row-menu-item.danger { color: #e5484d; }
.row-menu-item.danger:hover { background: #fdeced; }

/* ===== Drawer lateral (panel deslizante desde la derecha) ===== */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 70; display: flex; justify-content: flex-end; opacity: 0; transition: opacity .2s ease; }
.drawer-overlay.open { opacity: 1; }
.drawer { width: 460px; max-width: 92vw; height: 100%; background: var(--surface); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.12); transform: translateX(100%); transition: transform .2s ease; }
.drawer-overlay.open .drawer { transform: translateX(0); }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.drawer header h2 { margin: 0; font-size: 18px; font-weight: 650; }
.drawer .x { border: 0; background: transparent; font-size: 22px; line-height: 1; color: var(--text-3); cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.drawer .x:hover { background: var(--surface-2); color: var(--text); }
.drawer .form { padding: 18px 24px; overflow-y: auto; flex: 1; }
.drawer footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
.drawer .msg { margin: 14px 24px 0; padding: 10px 12px; border-radius: 9px; font-size: 13px; background: #fdeced; color: #c0282d; display: none; }
.drawer .msg.show { display: block; }
.drawer .field input[type="date"] { width: 100%; font: inherit; font-size: 14px; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.drawer .field input[type="date"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }
