:root {
  --bg: #f5f5f6;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --muted-light: #9aa0a6;
  --line: #e6e7ea;
  --accent: #8a2f7c;
  --accent-dark: #6f2563;
  --accent-soft: #f6ecf4;
  --green-bg: #e6f4ea; --green-tx: #1e7e34;
  --amber-bg: #fdeccf; --amber-tx: #b06a00;
  --pink-bg: #fbe4ef; --pink-tx: #b83280;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Barlow', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #fafafa 0%, #f2eef1 100%); padding: 20px;
}
.login-card {
  background: var(--surface); width: 100%; max-width: 380px; border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 38px 34px;
}
.login-card .brand { font-size: 26px; font-weight: 900; letter-spacing: -.5px; margin-bottom: 6px; }
.login-card .brand .x { color: var(--accent); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  outline: none; transition: border-color .15s, box-shadow .15s; background: #fff;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,47,124,.12); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: none; padding: 11px 18px;
  border-radius: 8px; font-weight: 700; font-size: 14px; transition: background .15s;
}
.btn:hover { background: var(--accent-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f7f7f8; }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.login-error { color: #c0392b; font-size: 13px; margin-bottom: 12px; min-height: 18px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted-light); text-align: center; line-height: 1.5; }

/* ---------- App layout ---------- */
.app { display: none; min-height: 100vh; }
.app.active { display: block; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  padding: 0 22px; z-index: 40;
}
.topbar .hamb { background: none; border: none; font-size: 22px; color: var(--text); margin-right: 16px; line-height: 1; }
.topbar .brand { font-size: 20px; font-weight: 900; letter-spacing: -.5px; }
.topbar .brand .x { color: var(--accent); }
.topbar .brand .hub { font-weight: 800; }
.topbar .spacer { flex: 1; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 17px; padding: 8px; border-radius: 8px; }
.icon-btn:hover { background: #f2f2f3; color: var(--text); }
.bell-wrap { position: relative; }
.bell-dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; background: #e74c3c; border-radius: 50%; border: 2px solid #fff; display: none; }
.bell-dot.on { display: block; }
.user-menu { position: relative; margin-left: 8px; }
.user-btn { background: none; border: none; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text); padding: 6px 8px; border-radius: 8px; }
.user-btn:hover { background: #f2f2f3; }
.user-btn .caret { color: var(--muted-light); font-size: 11px; }
.dropdown {
  position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 180px; padding: 6px; display: none;
}
.dropdown.open { display: block; }
.dropdown a { display: block; padding: 10px 12px; border-radius: 7px; font-size: 14px; }
.dropdown a:hover { background: var(--accent-soft); color: var(--accent); }

.sidebar {
  position: fixed; top: 56px; left: 0; bottom: 0; width: 210px; background: var(--surface);
  border-right: 1px solid var(--line); padding: 18px 0; overflow-y: auto; z-index: 30;
  display: flex; flex-direction: column; transition: transform .2s;
}
.sidebar nav { flex: 1; }
.nav-item { display: flex; align-items: center; justify-content: space-between; padding: 11px 24px; color: var(--text); font-size: 15px; cursor: pointer; border-left: 3px solid transparent; }
.nav-item:hover { background: #fafafa; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.nav-item .caret { font-size: 10px; color: var(--muted-light); }
.subnav { overflow: hidden; }
.subnav .nav-item { padding-left: 40px; font-size: 14px; }
.sidebar-foot { padding: 14px 24px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted-light); }
.sidebar-foot .lbl { text-transform: uppercase; letter-spacing: .5px; }
.sidebar-foot .val { color: var(--text); font-weight: 700; margin-top: 2px; }

.content { margin-left: 210px; margin-top: 56px; padding: 34px 40px 60px; max-width: 1280px; }
.breadcrumb { text-transform: uppercase; letter-spacing: 1px; font-size: 11px; color: var(--muted-light); font-weight: 600; margin-bottom: 6px; }
h1.page-title { font-size: 30px; font-weight: 900; letter-spacing: -.5px; margin: 0 0 26px; }
h1.page-title .accent { color: var(--accent); }
.page-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

/* ---------- Cards / panels ---------- */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border-left: 4px solid var(--accent); padding: 22px 26px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; font-weight: 700; margin: 0 0 18px; }
.section-label { text-transform: uppercase; letter-spacing: .6px; font-size: 11px; color: var(--muted-light); font-weight: 700; margin: 4px 0 12px; }
.empty { color: var(--muted); padding: 6px 0; }

/* dashboard grids */
.kv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 40px; }
.kv-grid.two { grid-template-columns: repeat(2, 1fr); }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; padding: 7px 0; border-bottom: 1px dashed #eee; gap: 12px; }
.kv-row .k { color: var(--text); font-size: 14px; }
.kv-row .v { font-weight: 700; }
.kv-row .v .u { color: var(--muted-light); font-weight: 500; font-size: 12px; margin-left: 3px; }

/* saldos */
.saldo-big { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0 14px; }
.saldo-big .k { color: var(--muted); }
.saldo-big .v { font-size: 26px; font-weight: 800; }
.saldo-sub .kv-row { border-bottom: none; padding: 5px 0; color: var(--muted); font-size: 13px; }
.saldo-sub .kv-row .v { color: var(--text); }

/* toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.count-line { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.count-line b { color: var(--text); }
.search { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; outline: none; margin-bottom: 18px; background: #fff; }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,47,124,.10); }

/* tramite cards */
.tramite { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border-left: 5px solid var(--accent); padding: 16px 18px; margin-bottom: 14px; position: relative; }
.tramite.st-encurso, .tramite.st-entramite { border-left-color: #eab308; }
.tramite.st-finalizado { border-left-color: #22c55e; }
.tramite .t-head { display: flex; align-items: center; gap: 10px; }
.tramite .t-close { background: none; border: none; color: var(--muted-light); font-size: 17px; line-height: 1; padding: 2px; }
.tramite .t-close:hover { color: #e74c3c; }
.tramite .t-title { font-weight: 700; font-size: 15px; flex: 1; }
.tramite .t-badges { display: flex; gap: 6px; align-items: center; }
.tramite .t-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 13px; margin: 8px 0 2px; }
.tramite .t-meta b { color: var(--text); font-weight: 600; }
.tramite .t-meta .demora { color: var(--accent); font-weight: 600; }
.tramite .t-meta .demora.alert { color: #d97706; }
.t-fields { display: grid; grid-template-columns: 90px 120px 1fr 1.6fr; gap: 12px; margin-top: 12px; }
.t-fields.rpba { grid-template-columns: 90px 120px 1.2fr 1.6fr; }
.t-fields .fld label { display: block; text-transform: uppercase; letter-spacing: .5px; font-size: 10px; color: var(--muted-light); font-weight: 700; margin-bottom: 4px; }
.t-fields input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; outline: none; }
.t-fields input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,47,124,.08); }

.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 6px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green-tx); }
.badge.amber { background: var(--amber-bg); color: var(--amber-tx); }
.badge.pink  { background: var(--pink-bg);  color: var(--pink-tx); }

.saldo-inline { color: var(--muted); font-size: 14px; }
.saldo-inline b { color: var(--text); }

/* dropdown "nuevo tramite" */
.newmenu-wrap { position: relative; }
.newmenu { position: absolute; top: 46px; left: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 12px; width: 300px; display: none; z-index: 20; max-height: 60vh; overflow-y: auto; }
.newmenu.open { display: block; }
.newmenu .grp { margin-bottom: 12px; }
.newmenu .grp .gt { font-size: 12px; color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.newmenu .grp .opts { display: flex; gap: 8px; }
.newmenu .opt { flex: 1; text-align: center; padding: 7px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; font-weight: 600; }
.newmenu .opt:hover { border-color: var(--accent); color: var(--accent); }
.newmenu .opt.urg { background: #fdf6e3; }
.newmenu .opt.urg:hover { border-color: #eab308; color: #b06a00; }

/* agenda / notas */
.agenda-item, .nota-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; border-left: 4px solid var(--accent); }
.agenda-item { display: flex; justify-content: space-between; gap: 16px; }
.agenda-item .when { font-weight: 700; }
.agenda-item .who { color: var(--muted); font-size: 13px; margin-top: 4px; }
.nota-card { max-width: 560px; }
.nota-card input.titulo { width: 100%; border: none; border-bottom: 1px solid transparent; font-size: 16px; font-weight: 700; padding: 6px 2px; outline: none; }
.nota-card input.titulo:focus { border-bottom-color: var(--accent); }
.nota-card textarea { width: 100%; border: none; resize: vertical; min-height: 70px; outline: none; padding: 8px 2px; font-size: 14px; color: var(--text); }
.nota-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; font-size: 12px; color: var(--muted-light); }
.nota-foot .del { background: none; border: none; color: var(--muted); font-size: 13px; }
.nota-foot .del:hover { color: #e74c3c; }

/* antecedentes */
.consulta-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.consulta-form .field { margin: 0; }
.consulta-form .field input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; width: 130px; }
.ant-result { margin-top: 18px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(30,30,40,.45); display: none; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal-back.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 430px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.modal-head .close { background: none; border: none; font-size: 20px; color: var(--muted); }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }
.modal-body .field label { font-weight: 600; }
.modal-body .field input, .modal-body .field textarea, .modal-body .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.modal-body .field input:focus, .modal-body .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,47,124,.1); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* credenciales */
.cred-card { display: grid; grid-template-columns: 90px 1fr 1fr auto auto; gap: 14px; align-items: end; }
.cred-card .svc { font-weight: 800; font-size: 16px; align-self: center; }
.cred-status { font-size: 12px; color: var(--green-tx); font-weight: 600; text-align: right; margin-bottom: 6px; }
.pw-wrap { position: relative; }
.pw-wrap .eye { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--muted-light); }
.cred-panel { border-left-color: var(--accent); }

.toast { position: fixed; bottom: 22px; right: 22px; background: #1c1e21; color: #fff; padding: 12px 18px; border-radius: 9px; font-size: 14px; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: all .2s; z-index: 80; }
.toast.show { opacity: 1; transform: translateY(0); }
.saved-flag { color: var(--green-tx); font-size: 13px; font-weight: 600; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .content { margin-left: 0; padding: 22px 18px 60px; }
  .kv-grid, .kv-grid.two { grid-template-columns: 1fr; }
  .t-fields, .t-fields.rpba { grid-template-columns: 1fr 1fr; }
  .cred-card { grid-template-columns: 1fr 1fr; }
  h1.page-title { font-size: 24px; }
}

/* ---- Dibujo ---- */
.dibujo-panel { padding: 18px; }
.dibujo-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.tool-btn {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
}
.tool-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.tool-sep { width: 1px; align-self: stretch; background: var(--line); }
.color-swatches { display: flex; align-items: center; gap: 8px; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent-soft); }
.dibujo-canvas-wrap {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; line-height: 0;
}
#dibujoCanvas { width: 100%; height: auto; display: block; aspect-ratio: 1000 / 620; touch-action: none; cursor: crosshair; }
@media (max-width: 640px) {
  .dibujo-toolbar { gap: 8px; }
  .tool-sep { display: none; }
}
