:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e6e8f0;
  --text: #1a1d29;
  --muted: #6b7280;
  --primary: #5b5bf0;
  --primary-dark: #4747d1;
  --primary-soft: #ececfd;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea {
  font-family: inherit; font-size: 14px; width: 100%;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 72px; }
label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 5px; color: #374151; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px;
  background: var(--surface-2); color: var(--text); transition: all .15s; border: 1px solid transparent;
}
.btn:hover { background: #e3e6f0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
}
.brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg,#5b5bf0,#8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 17px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: #475467; font-weight: 600; font-size: 13.5px; margin-bottom: 2px; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 99px; font-weight: 700; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius-sm); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary-dark); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-chip .nm { font-weight: 600; font-size: 13px; }
.user-chip .rl { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.main { flex: 1; margin-left: 232px; min-width: 0; }
.topbar {
  height: 62px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 28px; gap: 16px; position: sticky; top: 0; z-index: 15;
}
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-size: 18px; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px;
  background: var(--red); border-radius: 50%; border: 2px solid var(--surface); }
.content { padding: 24px 28px 60px; max-width: 1240px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.grid { display: grid; gap: 16px; }
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; display: flex;
  align-items: center; gap: 8px; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -1px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .pill-ico { position: absolute; top: 16px; right: 16px; font-size: 20px; opacity: .85; }
.kpi.good .val { color: var(--green); }
.kpi.warn .val { color: var(--amber); }
.kpi.bad .val { color: var(--red); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-nueva { background: var(--surface-2); color: #475467; }
.b-aceptada { background: var(--blue-soft); color: var(--blue); }
.b-en_proceso { background: var(--amber-soft); color: var(--amber); }
.b-en_revision { background: #ede9fe; color: #7c3aed; }
.b-entregada { background: var(--green-soft); color: var(--green); }
.b-pausada { background: #f3f4f6; color: #9ca3af; }
.b-urgente { background: var(--red-soft); color: var(--red); }
.b-alta { background: #ffedd5; color: #ea580c; }
.b-normal { background: var(--amber-soft); color: var(--amber); }
.b-baja { background: var(--green-soft); color: var(--green); }
.b-overdue { background: var(--red-soft); color: var(--red); }
.b-ontime { background: var(--green-soft); color: var(--green); }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.t-code { font-weight: 700; color: var(--primary); font-size: 13px; }
.t-title { font-weight: 600; }
.t-meta { font-size: 12px; color: var(--muted); }

/* Filters bar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 340px; }

/* Kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: 270px; gap: 14px; overflow-x: auto;
  padding-bottom: 14px; }
.kcol { background: var(--surface-2); border-radius: var(--radius); padding: 10px; }
.kcol-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px;
  font-weight: 700; font-size: 13px; }
.kcol-count { background: var(--surface); color: var(--muted); border-radius: 99px; padding: 1px 8px;
  font-size: 12px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  margin-bottom: 9px; box-shadow: var(--shadow); cursor: pointer; }
.kcard:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); transition: all .12s; }
.kcard .kc-code { font-size: 11px; font-weight: 700; color: var(--primary); }
.kcard .kc-title { font-weight: 600; font-size: 13px; margin: 4px 0 8px; }
.kcard .kc-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }

/* Bars / charts */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .bl { width: 130px; font-size: 12.5px; color: #475467; font-weight: 600; flex-shrink: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 22px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; display: flex; align-items: center; padding: 0 8px;
  color: #fff; font-size: 11.5px; font-weight: 700; min-width: 24px; transition: width .4s; }
.bar-row .bv { width: 36px; text-align: right; font-weight: 700; font-size: 13px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

/* Modal / drawer */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 40; display: flex;
  justify-content: flex-end; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.drawer { width: 560px; max-width: 94vw; background: var(--bg); height: 100%; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: slide .2s; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } }
.drawer-head { padding: 20px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; gap: 12px; }
.drawer-body { padding: 20px 24px 60px; }
.modal { background: var(--surface); border-radius: var(--radius); width: 560px; max-width: 94vw;
  max-height: 92vh; overflow-y: auto; margin: auto; box-shadow: var(--shadow-lg); animation: pop .15s; }
@keyframes pop { from { transform: scale(.97); opacity: .6; } }
.overlay.center { justify-content: center; align-items: center; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px;
  justify-content: flex-end; position: sticky; bottom: 0; background: var(--surface); }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.close-x { font-size: 22px; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.close-x:hover { background: var(--surface-2); }

/* Detail blocks */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0; }
.dfield { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.dfield .dl { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  font-weight: 700; margin-bottom: 4px; }
.dfield .dv { font-size: 13.5px; font-weight: 500; }
.full { grid-column: 1 / -1; }

/* Comments / timeline */
.comment { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; }
.comment.internal { background: var(--amber-soft); border-color: #fde68a; }
.comment .ch { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment .ca { font-weight: 700; font-size: 13px; }
.comment .ct { font-size: 11.5px; color: var(--muted); }
.timeline-item { display: flex; gap: 10px; font-size: 12.5px; color: #475467; padding: 6px 0; }
.timeline-item .ti-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
  margin-top: 6px; flex-shrink: 0; }

/* Notifications panel */
.notif-panel { position: absolute; top: 56px; right: 20px; width: 380px; max-width: 92vw;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 30; max-height: 70vh; overflow: hidden; display: flex; flex-direction: column; }
.notif-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex;
  justify-content: space-between; align-items: center; }
.notif-list { overflow-y: auto; }
.notif { padding: 13px 18px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--primary-soft); }
.notif .nt { font-weight: 600; font-size: 13px; }
.notif .nb { font-size: 12.5px; color: var(--muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif .nd { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #eef0fc 0%, #f6f7fb 60%); }
.login-card { width: 400px; max-width: 100%; }
.login-card .card-pad { padding: 32px; }
.login-logo { width: 52px; height: 52px; border-radius: 13px; background: linear-gradient(135deg,#5b5bf0,#8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 24px; margin-bottom: 18px; }
.login-demo { margin-top: 18px; padding: 14px; background: var(--surface-2); border-radius: 10px;
  font-size: 12px; color: #475467; }
.login-demo b { color: var(--text); }
.login-demo .row { cursor: pointer; padding: 3px 0; }
.login-demo .row:hover { color: var(--primary); }

/* Misc */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex { display: flex; align-items: center; gap: 8px; }
.gap12 { gap: 12px; } .gap16 { gap: 16px; }
.muted { color: var(--muted); }
.tag { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 2px 8px;
  font-size: 11.5px; margin: 2px 3px 2px 0; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .ei { font-size: 42px; margin-bottom: 10px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1a1d29;
  color: #fff; padding: 12px 20px; border-radius: 10px; font-weight: 600; font-size: 13.5px; z-index: 100;
  box-shadow: var(--shadow-lg); animation: pop .2s; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--surface-2); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner-warn { background: var(--amber-soft); color: #92400e; padding: 10px 16px; border-radius: 10px;
  font-size: 12.5px; font-weight: 600; margin-bottom: 16px; display: flex; gap: 8px; }

.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .cols-2, .cols-3, .detail-grid, .field-row { grid-template-columns: 1fr; }
  .menu-toggle { display: grid !important; }
}
.menu-toggle { display: none; }

@media print {
  .sidebar, .topbar, #repControls, .printbtn { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: 100% !important; }
  .card, .kpi { box-shadow: none !important; break-inside: avoid; }
  body { background: #fff !important; }
}
