:root {
  --bg: #f1f4f9;
  --panel: #ffffff;
  --border: #dfe5ee;
  --text: #1c2733;
  --muted: #6b7889;
  --primary: #1666c4;
  --primary-dark: #0f4f99;
  --danger: #d64545;
  --success: #1e9e5a;
  --warning: #d98a1f;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 40, 70, .08);
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px;
  min-width: 250px;
  background: linear-gradient(180deg, #12305c, #0b2142);
  color: #dbe7f6;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 16px; border-bottom: 1px solid rgba(255,255,255,.12); }

.brand-logo {
  width: 42px; height: 42px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 700;
}

.brand h1 { font-size: 16px; color: #fff; }
.brand p { font-size: 11px; color: #9db4d1; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; color: #c5d5ea;
  padding: 11px 12px; border-radius: 8px;
  font-size: 14px; cursor: pointer; text-align: left;
  width: 100%; font-family: inherit;
  transition: background .15s, color .15s;
}

.nav-item svg { width: 19px; height: 19px; fill: currentColor; }

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(22,102,196,.4); }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }

.btn-ghost {
  background: transparent; border: 1px solid rgba(255,255,255,.25);
  color: #dbe7f6; border-radius: 8px; padding: 9px 12px;
  cursor: pointer; font-size: 13px; font-family: inherit;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-ghost svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------- Main ---------- */
.main { flex: 1; overflow-y: auto; padding: 28px 32px; }

.tab { display: none; }
.tab.active { display: block; }

.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}

.section-head h2 { font-size: 21px; font-weight: 600; }
.section-head p { color: var(--muted); margin-top: 4px; }

.head-actions { display: flex; gap: 10px; align-items: center; }

.search {
  width: 260px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit;
  background: var(--panel);
}
.search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,102,196,.15); }

.btn {
  border: none; border-radius: 8px; padding: 9px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: filter .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { padding: 5px 10px; font-size: 12px; font-weight: 500; }

/* ---------- Cards ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 24px;
}

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20,40,70,.12); }
.card .card-num { font-size: 30px; font-weight: 700; color: var(--primary); }
.card .card-label { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ---------- Panel ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.panel h3 { font-size: 15px; margin-bottom: 14px; }

.nota-mini {
  border-bottom: 1px solid var(--border); padding: 10px 2px;
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
}
.nota-mini:last-child { border-bottom: none; }
.nota-mini .nm-title { font-weight: 600; }
.nota-mini .nm-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

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

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: #f7f9fc; padding: 12px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}

td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #f6f9fd; }
tbody tr:last-child td { border-bottom: none; }
.col-actions { width: 110px; text-align: right; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: #e3f4ea; color: #187a46; }
.badge-red { background: #fbe7e7; color: #b33232; }
.badge-orange { background: #fdf0dc; color: #a96a14; }
.badge-blue { background: #e2edfb; color: #17508f; }
.badge-gray { background: #eef1f5; color: #5c6877; }

.tag {
  display: inline-block; background: #eef1f5; color: #4a5768;
  border-radius: 4px; padding: 2px 7px; font-size: 11px; margin: 2px 2px 0 0;
}

.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

.icon-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  width: 30px; height: 30px; cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; transition: all .15s;
}
.icon-btn svg { width: 15px; height: 15px; fill: currentColor; }
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 32px; }

.pw-dots { letter-spacing: 2px; color: var(--muted); cursor: pointer; user-select: none; }
.pw-dots:hover { color: var(--primary); }

/* ---------- Modal ---------- */
.modal-backdrop, .confirm-backdrop {
  position: fixed; inset: 0; background: rgba(12, 28, 52, .5);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}

.modal {
  background: var(--panel); border-radius: 12px; width: 620px; max-width: 100%;
  max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(10, 25, 50, .3);
}

.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }

.modal-close {
  background: transparent; border: none; font-size: 24px; cursor: pointer;
  color: var(--muted); line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 22px; overflow-y: auto; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,102,196,.15);
}
.field textarea { resize: vertical; min-height: 90px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 15px 22px; border-top: 1px solid var(--border);
}

.link-title {
  color: var(--primary); text-decoration: none; font-weight: 600;
  cursor: pointer;
}
.link-title:hover { text-decoration: underline; }

.modal-lg { width: 760px; }

.view-meta {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  color: var(--muted); font-size: 12px; margin-bottom: 14px;
}

.view-content {
  background: #f7f9fc; border: 1px solid var(--border); border-radius: 8px;
  padding: 18px; font-size: 14px; line-height: 1.65; white-space: normal;
  max-height: 55vh; overflow-y: auto;
}

.nota-mini.clickable { cursor: pointer; border-radius: 6px; padding: 10px 8px; transition: background .15s; }
.nota-mini.clickable:hover { background: #f0f5fc; }

.ticket-status {
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border);
}
.ticket-status > label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 6px; }
.status-row { display: flex; gap: 10px; align-items: center; }
.status-row select {
  flex: 1; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff;
}
.status-row select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,102,196,.15); }

.history { margin-top: 20px; }
.history h4 { font-size: 14px; margin-bottom: 10px; }

.history-list { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; max-height: 280px; overflow-y: auto; }
.history-item { padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fff; }
.history-item:last-child { border-bottom: none; }
.history-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.history-accion { font-weight: 600; font-size: 13px; }
.history-fecha { color: var(--muted); font-size: 11px; white-space: nowrap; }
.history-desc { color: var(--text); font-size: 13px; margin-top: 3px; white-space: pre-wrap; }

.history-add { margin-top: 10px; display: flex; gap: 8px; align-items: flex-end; }
.history-add textarea {
  flex: 1; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; min-height: 52px; resize: vertical;
}
.history-add textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,102,196,.15); }

/* ---------- Confirm ---------- */
.confirm {
  background: var(--panel); border-radius: 12px; padding: 24px;
  width: 380px; max-width: 100%; box-shadow: 0 20px 50px rgba(10,25,50,.3);
}
.confirm h3 { font-size: 16px; margin-bottom: 8px; }
.confirm p { color: var(--muted); margin-bottom: 20px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  background: #1f2d3d; color: #fff; padding: 12px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(8px); transition: all .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c6d0dd; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #aebacc; }

@media (max-width: 860px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 18px; }
  .search { width: 100%; }
  .table-wrap { overflow-x: auto; }
}

/* ---------- Login ---------- */
body.logged-out .sidebar,
body.logged-out .main { display: none; }

.login-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(160deg, #12305c, #0b2142);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.login-box {
  width: 360px; max-width: 100%;
  background: #fff; border-radius: 14px;
  padding: 28px 30px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
}

.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-logo { width: 54px; height: 54px; font-size: 28px; margin: 0 auto 10px; }
.login-brand h1 { font-size: 19px; color: var(--text); }
.login-brand p { font-size: 12px; color: var(--muted); margin-top: 4px; }

.login-box label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
.login-box input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit;
}
.login-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,102,196,.15); }
.login-box .btn { width: 100%; margin-top: 18px; }

.login-error {
  margin-top: 12px; background: #fdeeee; color: #b42318;
  border: 1px solid #f5c6c6; border-radius: 8px; padding: 9px 12px;
  font-size: 13px;
}

.login-hint { text-align: center; font-size: 11px; color: var(--muted); margin-top: 16px; }
.login-hint code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; }
