:root{
  --ink:#16233d;
  --ink-2:#0c1526;
  --parchment:#f6f3ec;
  --paper:#ffffff;
  --brass:#a9814a;
  --brass-light:#cdb27a;
  --brass-dim:#e7dcc4;
  --red:#a83a2f;
  --red-bg:#fbe9e6;
  --amber:#b3781f;
  --amber-bg:#fbf1de;
  --green:#3f6b4f;
  --green-bg:#e9f2ec;
  --gray:#68707e;
  --border:#e3dccb;
  --border-2:#2a3a5c;
  --shadow: 0 8px 24px rgba(15,23,42,.10);
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Courier New', ui-monospace, monospace;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  background:var(--parchment);
  color:var(--ink);
  font-family:var(--sans);
  font-size:14px;
  line-height:1.5;
  min-height:100vh;
}
.app{display:flex; min-height:100vh;}

/* ---------- Sidebar ---------- */
.sidebar{
  width:248px; flex-shrink:0;
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 100%);
  color:#ecebe6;
  display:flex; flex-direction:column;
  position:sticky; top:0; height:100vh;
}
.brand{
  padding:26px 22px 18px 22px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.brand .seal{
  width:40px;height:40px;border-radius:50%;
  border:1.5px solid var(--brass-light);
  display:flex;align-items:center;justify-content:center;
  font-family:var(--serif); font-weight:700; font-size:16px; color:var(--brass-light);
  margin-bottom:12px;
}
.brand h1{
  font-family:var(--serif); font-size:17px; font-weight:700; margin:0 0 3px 0; letter-spacing:.2px; color:#fff;
}
.brand p{margin:0; font-size:11px; color:var(--brass-light); letter-spacing:.6px; text-transform:uppercase;}

.nav{padding:14px 12px; flex:1; overflow-y:auto; min-height:0;}
.nav button{
  width:100%; text-align:left; background:none; border:none; color:#c9cede;
  padding:10px 12px; border-radius:8px; font-size:13.5px; font-family:var(--sans);
  display:flex; align-items:center; gap:10px; cursor:pointer; margin-bottom:2px;
  transition:background .15s ease, color .15s ease;
}
.nav button .ico{width:16px; text-align:center; opacity:.85;}
.nav button:hover{background:rgba(255,255,255,.06); color:#fff;}
.nav button.active{background:rgba(169,129,74,.22); color:#fff; box-shadow:inset 3px 0 0 var(--brass-light);}
.nav .section-label{
  font-size:10px; text-transform:uppercase; letter-spacing:1px; color:#7c869c;
  padding:14px 12px 6px 12px;
}
.sidebar-foot{
  padding:16px 20px; border-top:1px solid rgba(255,255,255,.08); font-size:11px; color:#8a93a8;
}
.user-pill{
  display:flex; align-items:center; gap:8px; margin-bottom:10px; padding:8px 10px;
  background:rgba(255,255,255,.05); border-radius:8px;
}
.user-pill .dot{width:8px;height:8px;border-radius:50%; background:var(--brass-light); flex-shrink:0;}
.user-pill span{color:#e9e6dc; font-size:12.5px; font-weight:600;}
.switch-user{background:none;border:1px solid rgba(255,255,255,.15); color:#c9cede; font-size:11px; padding:5px 8px; border-radius:6px; cursor:pointer; width:100%;}
.switch-user:hover{border-color:var(--brass-light); color:#fff;}

/* ---------- Main ---------- */
.main{flex:1; min-width:0; padding:30px 38px 60px 38px;}
.topbar{display:flex; align-items:center; justify-content:space-between; margin-bottom:26px; gap:20px;}
.topbar h2{font-family:var(--serif); font-size:24px; margin:0; font-weight:700; color:var(--ink);}
.topbar .sub{color:var(--gray); font-size:12.5px; margin-top:3px;}
.search-box{
  display:flex; align-items:center; gap:8px; background:var(--paper); border:1px solid var(--border);
  border-radius:9px; padding:9px 14px; min-width:280px; box-shadow:var(--shadow);
}
.search-box input{border:none; outline:none; font-size:13px; flex:1; background:none; font-family:var(--sans); color:var(--ink);}

/* ---------- Cards / stats ---------- */
.stat-grid{display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:28px;}
.stat-card{
  background:var(--paper); border:1px solid var(--border); border-radius:12px; padding:18px 20px;
  box-shadow:var(--shadow); position:relative; overflow:hidden;
}
.stat-card .num{font-family:var(--serif); font-size:30px; font-weight:700; color:var(--ink); line-height:1;}
.stat-card .label{font-size:11.5px; color:var(--gray); margin-top:8px; text-transform:uppercase; letter-spacing:.5px;}
.stat-card.crit .num{color:var(--red);}
.stat-card.warn .num{color:var(--amber);}
.stat-card.ok .num{color:var(--green);}
.stat-card .bar{position:absolute; left:0; top:0; bottom:0; width:4px; background:var(--brass);}
.stat-card.crit .bar{background:var(--red);}
.stat-card.warn .bar{background:var(--amber);}
.stat-card.ok .bar{background:var(--green);}

.panel{background:var(--paper); border:1px solid var(--border); border-radius:12px; box-shadow:var(--shadow); margin-bottom:24px; overflow:hidden;}
.panel-head{padding:16px 20px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between;}
.panel-head h3{font-family:var(--serif); font-size:16px; margin:0; color:var(--ink);}
.panel-head .count{font-size:11px; color:var(--gray); background:var(--parchment); padding:3px 9px; border-radius:20px;}
.panel-body{padding:6px 0; overflow-x:auto; max-width:100%;}

/* ---------- Alert rows ---------- */
.alert-row{
  display:flex; align-items:center; gap:14px; padding:12px 20px; border-bottom:1px solid #f0ece1; cursor:pointer;
  transition:background .12s;
}
.alert-row:last-child{border-bottom:none;}
.alert-row:hover{background:var(--parchment);}
.ring{position:relative; width:44px; height:44px; flex-shrink:0;}
.ring svg{transform:rotate(-90deg);}
.ring .bg{stroke:#eee7d6;}
.ring .val{stroke-linecap:round; transition:stroke-dashoffset .4s;}
.ring .days{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-family:var(--mono); font-weight:700; font-size:11px;
}
.alert-info{flex:1; min-width:0;}
.alert-info .name{font-weight:600; font-size:13.5px; color:var(--ink);}
.alert-info .meta{font-size:11.5px; color:var(--gray); margin-top:2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.badge{font-size:10px; font-weight:700; padding:4px 9px; border-radius:20px; text-transform:uppercase; letter-spacing:.4px; white-space:nowrap;}
.badge.crit{background:var(--red-bg); color:var(--red);}
.badge.warn{background:var(--amber-bg); color:var(--amber);}
.badge.ok{background:var(--green-bg); color:var(--green);}
.badge.closed{background:#ece9e1; color:var(--gray);}
.badge.convenio{background:#f1e9da; color:var(--brass);}
.badge.interrumpida{background:#e7ecf3; color:#3c5a86;}

/* ---------- Table / cases ---------- */
.filters{display:flex; gap:8px; flex-wrap:wrap; margin-bottom:16px;}
.chip{
  border:1px solid var(--border); background:var(--paper); padding:6px 13px; border-radius:20px; font-size:12px;
  cursor:pointer; color:var(--ink); font-weight:600;
}
.chip.active{background:var(--ink); color:#fff; border-color:var(--ink);}
table{width:100%; min-width:640px; border-collapse:collapse;}
thead th{
  text-align:left; font-size:10.5px; text-transform:uppercase; letter-spacing:.5px; color:var(--gray);
  padding:10px 16px; border-bottom:1.5px solid var(--border); background:#faf8f2; position:sticky; top:0;
}
tbody td{padding:12px 16px; border-bottom:1px solid #f0ece1; font-size:13px; vertical-align:middle;}
tbody tr{cursor:pointer;}
tbody tr:hover{background:var(--parchment);}
.exp-code{font-family:var(--mono); font-size:12px; color:var(--gray);}
.abogado-tag{font-size:10.5px; color:var(--brass); font-weight:700;}

/* ---------- Modal ---------- */
.overlay{
  position:fixed; inset:0; background:rgba(15,20,35,.55); display:none; align-items:flex-start; justify-content:center;
  padding:40px 20px; z-index:100; overflow-y:auto; backdrop-filter: blur(2px);
}
.overlay.show{display:flex;}
.modal{
  background:var(--paper); border-radius:14px; max-width:840px; width:100%; box-shadow:0 30px 60px rgba(0,0,0,.35);
  overflow:hidden; margin-bottom:40px;
}
.modal-head{
  background:linear-gradient(120deg, var(--ink), var(--ink-2)); color:#fff; padding:24px 28px; position:relative;
}
.modal-head .close{position:absolute; top:18px; right:20px; background:none; border:none; color:#c9cede; font-size:20px; cursor:pointer;}
.modal-head h2{font-family:var(--serif); margin:0 0 4px 0; font-size:20px;}
.modal-head .sub{color:var(--brass-light); font-size:12.5px;}
.modal-tabs{display:flex; gap:2px; background:#faf8f2; border-bottom:1px solid var(--border); padding:0 20px; overflow-x:auto; scrollbar-width:thin;}
.modal-tabs button{
  background:none; border:none; padding:12px 14px; font-size:12.5px; font-weight:600; color:var(--gray); cursor:pointer;
  border-bottom:2px solid transparent; white-space:nowrap; flex-shrink:0;
}
.modal-tabs button.active{color:var(--ink); border-bottom-color:var(--brass);}
.modal-body{padding:22px 28px; max-height:60vh; overflow-y:auto;}
.grid2{display:grid; grid-template-columns:1fr 1fr; gap:14px 24px;}
.field{margin-bottom:2px;}
.field label{display:block; font-size:10.5px; text-transform:uppercase; letter-spacing:.4px; color:var(--gray); margin-bottom:4px;}
.field .v{font-size:13.5px; color:var(--ink); font-weight:500;}
.field textarea, .field input[type=text], .field input[type=date]{
  width:100%; border:1px solid var(--border); border-radius:8px; padding:9px 11px; font-size:13px; font-family:var(--sans);
  background:var(--parchment);
}
.field textarea{min-height:70px; resize:vertical;}
.manual-item{border:1px solid var(--border); border-radius:10px; margin-bottom:10px; overflow:hidden; background:var(--paper);}
.manual-item summary{
  padding:16px 20px; cursor:pointer; font-family:var(--serif); font-weight:700; font-size:15px; color:var(--ink);
  list-style:none; display:flex; align-items:center; gap:10px; user-select:none;
}
.manual-item summary::-webkit-details-marker{display:none;}
.manual-item summary::before{content:'▸'; color:var(--brass); font-size:13px; transition:transform .15s;}
.manual-item[open] summary::before{transform:rotate(90deg);}
.manual-item summary .n{
  width:26px; height:26px; border-radius:50%; background:var(--ink); color:#fff; font-family:var(--sans);
  font-size:12px; display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.manual-body{padding:2px 20px 20px 56px; font-size:13.5px; color:#3c4a63; line-height:1.7;}
.manual-body ol, .manual-body ul{margin:8px 0; padding-left:20px;}
.manual-body li{margin-bottom:6px;}
.manual-body .tag{
  display:inline-block; background:var(--parchment); border:1px solid var(--border); border-radius:5px;
  padding:1px 7px; font-family:var(--sans); font-weight:600; color:var(--ink); font-size:12.5px;
}
.manual-body .tip{background:var(--green-bg); border-left:3px solid var(--green); padding:10px 14px; border-radius:0 8px 8px 0; margin:10px 0; font-size:12.5px;}
.manual-body .warn2{background:var(--amber-bg); border-left:3px solid var(--brass); padding:10px 14px; border-radius:0 8px 8px 0; margin:10px 0; font-size:12.5px;}
.legal-box{
  background:var(--parchment); border-left:3px solid var(--brass); padding:14px 16px; border-radius:0 8px 8px 0; font-size:12.5px; color:#3c4a63;
  margin-top:6px;
}
.csection{font-family:var(--mono); font-size:10px; letter-spacing:.1em; color:var(--gray); border-bottom:1px solid var(--border); padding:16px 0 5px; margin-top:6px; text-transform:uppercase;}
.crow{display:flex; justify-content:space-between; align-items:baseline; padding:10px 0; border-bottom:1px dotted #c9c2ab;}
.crow .cname{font-size:13.5px; color:var(--ink);}
.crow .cfund{font-family:var(--mono); font-size:10px; color:var(--gray); margin-top:2px;}
.crow .camt{font-size:14px; font-weight:600; color:var(--ink); white-space:nowrap; padding-left:14px;}
.crow-total{background:var(--parchment); margin:4px 0 0; padding:12px 14px; border-radius:6px; border-bottom:none;}
.crow-total .cname{font-weight:700;}
.crow-total .camt{color:var(--brass); font-size:16px;}
.btn{
  background:var(--ink); color:#fff; border:none; padding:9px 18px; border-radius:8px; font-size:12.5px; font-weight:600;
  cursor:pointer;
}
.btn:hover{background:var(--ink-2);}
.btn.secondary{background:none; border:1px solid var(--border); color:var(--ink);}
.divider{height:1px; background:var(--border); margin:18px 0;}

/* ---------- Login / usuario ---------- */
.gate{min-height:100vh; display:flex; align-items:center; justify-content:center; background:var(--ink); padding:20px;}
.gate-card{background:linear-gradient(160deg, var(--ink) 0%, var(--ink-2) 100%); border-radius:16px; padding:40px 38px; width:100%; max-width:400px; box-shadow:0 30px 60px rgba(0,0,0,.4); text-align:center; border:1px solid rgba(255,255,255,.06);}
.gate-card .seal{
  width:56px;height:56px;border-radius:50%; border:2px solid var(--brass); margin:0 auto 16px auto;
  display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-weight:700; font-size:22px; color:var(--brass);
}
.gate-card h1{font-family:var(--serif); font-size:20px; margin:0 0 6px 0; color:#fff;}
.gate-card p{color:#a8b0c2; font-size:12.5px; margin:0 0 22px 0;}
.user-option{
  display:flex; align-items:center; justify-content:space-between; padding:12px 16px; border:1px solid rgba(255,255,255,.1);
  border-radius:10px; margin-bottom:9px; cursor:pointer; text-align:left; background:rgba(255,255,255,.05);
}
.user-option:hover{border-color:var(--brass-light);}
.user-option .name{font-weight:700; font-size:13px; color:#fff;}
.user-option .role{font-size:10.5px; color:#a8b0c2;}
.mode-toggle{display:flex; gap:8px; margin-top:20px; justify-content:center;}
.mode-toggle button{background:none; border:none; color:#a8b0c2; font-size:11.5px; text-decoration:underline; cursor:pointer;}

/* ---------- Cliente portal ---------- */
.client-search{max-width:460px; margin:0 auto; text-align:center; padding:50px 20px;}
.client-search h2{font-family:var(--serif); font-size:22px; margin-bottom:6px;}
.client-search p{color:var(--gray); font-size:13px; margin-bottom:26px;}
.client-search input{
  width:100%; padding:12px 14px; border:1px solid var(--border); border-radius:9px; font-size:13.5px; margin-bottom:10px; background:var(--paper);
}
.client-result{max-width:560px; margin:0 auto;}
.status-timeline{display:flex; flex-direction:column; gap:0; margin-top:18px;}
.tl-item{display:flex; gap:14px; padding-bottom:20px; position:relative;}
.tl-item:not(:last-child)::before{content:''; position:absolute; left:9px; top:22px; bottom:0; width:2px; background:var(--border);}
.tl-dot{width:20px;height:20px;border-radius:50%; background:var(--brass); flex-shrink:0; display:flex; align-items:center; justify-content:center; color:#fff; font-size:10px; z-index:1;}
.tl-item.done .tl-dot{background:var(--green);}
.tl-item.pending .tl-dot{background:var(--border-2); opacity:.3;}
.tl-text .t{font-weight:700; font-size:13px; color:var(--ink);}
.tl-text .d{font-size:11.5px; color:var(--gray);}
.notice{background:var(--amber-bg); border:1px solid var(--brass-dim); color:#6b4d18; font-size:11.5px; padding:10px 14px; border-radius:8px; margin-top:14px;}

.empty{padding:40px 20px; text-align:center; color:var(--gray); font-size:13px;}
.mobile-menu-btn{display:none;}

/* ---------- Formularios de autenticación (agregado en la migración a MySQL) ---------- */
.field input[type=email], .field input[type=password], .field input[type=number],
.text-input{
  width:100%; border:1px solid var(--border); border-radius:8px; padding:9px 11px; font-size:13px; font-family:var(--sans);
  background:var(--parchment); box-sizing:border-box;
}
.gate-form{text-align:left; margin-top:6px;}
.gate-form label{display:block; font-size:11px; color:#a8b0c2; margin-bottom:5px; text-transform:uppercase; letter-spacing:.4px;}
.gate-form input{
  width:100%; padding:11px 13px; border:1px solid rgba(255,255,255,.15); border-radius:9px; font-size:13.5px;
  margin-bottom:14px; background:rgba(255,255,255,.06); color:#fff; box-sizing:border-box;
}
.gate-form input::placeholder{color:#7c869c;}
.gate-form .btn{width:100%; padding:11px; font-size:13px;}
.gate-error{background:rgba(168,58,47,.18); border:1px solid rgba(168,58,47,.4); color:#f3b7ae; font-size:12px; padding:9px 12px; border-radius:8px; margin-bottom:14px; text-align:left;}
.gate-info{background:rgba(169,129,74,.15); border:1px solid rgba(169,129,74,.35); color:var(--brass-light); font-size:11.5px; padding:9px 12px; border-radius:8px; margin-bottom:14px; text-align:left;}
.temp-pass-box{background:var(--parchment); border:1px dashed var(--brass); border-radius:8px; padding:14px; margin:10px 0; font-family:var(--mono); font-size:15px; text-align:center; color:var(--ink); letter-spacing:.5px;}
.badge.codigo{background:#f1e9da; color:var(--brass); font-family:var(--mono);}
.link-btn{background:none; border:none; color:var(--brass); text-decoration:underline; cursor:pointer; font-size:12px; padding:0;}
.nav-badge{
  display:inline-block; background:var(--red); color:#fff; font-size:10px; font-weight:700; line-height:1;
  padding:3px 6px; border-radius:20px; margin-left:4px; vertical-align:middle;
}
.aviso-card{border:1px solid var(--brass-dim); background:var(--amber-bg); border-radius:10px; padding:14px 16px; margin-bottom:10px;}
.aviso-card .aviso-head{display:flex; justify-content:space-between; align-items:flex-start; gap:10px; margin-bottom:6px;}
.aviso-card .aviso-caso{font-weight:700; font-size:13px; color:var(--ink);}
.aviso-card .aviso-fuente{font-size:11px; color:var(--gray); margin-top:2px;}
.aviso-card .aviso-resumen{font-size:12.5px; color:#3c4a63; white-space:pre-wrap;}
.aviso-card .aviso-meta{font-size:11px; color:var(--gray); margin-top:6px;}
.aviso-card .aviso-actions{display:flex; gap:8px; margin-top:10px;}
.sidebar-backdrop{display:none;}
@media (max-width:900px){
  .stat-grid{grid-template-columns:repeat(2,1fr) !important;}
  .grid2{grid-template-columns:1fr;}
  .main{padding:20px 16px 50px 16px;}
  .mobile-menu-btn{
    display:flex; align-items:center; justify-content:center; width:38px; height:38px; border-radius:8px;
    background:var(--ink); color:#fff; border:none; font-size:18px; cursor:pointer; flex-shrink:0;
  }
  .topbar{flex-wrap:wrap; gap:10px;}
  .topbar h2{font-size:19px;}
  .search-box{min-width:0; width:100%; order:3;}
  .sidebar{
    display:flex !important; position:fixed; top:0; left:0; height:100vh; z-index:200;
    transform:translateX(-100%); transition:transform .22s ease; box-shadow:0 0 30px rgba(0,0,0,.4);
  }
  .sidebar.open{transform:translateX(0);}
  .sidebar-backdrop{
    display:none; position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:150;
  }
  .sidebar-backdrop.open{display:block;}
  .stat-card .num{font-size:24px;}
  .modal{max-width:100%; margin:0; border-radius:0; min-height:100vh;}
  .overlay{padding:0;}
  .modal-body{max-height:none;}
  table{min-width:560px;}
}
@media (max-width:520px){
  .stat-grid{grid-template-columns:1fr !important;}
  .gate-card{padding:30px 22px;}
}
@media (max-width:600px){
  .alert-row{flex-wrap:wrap; row-gap:8px;}
  .alert-row .alert-info{flex-basis:100%; order:2;}
  .alert-row > button, .alert-row .agenda-complete{order:3; margin-left:auto;}
}
