:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-soft: #EEF2FF;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-2: #334155;
  --muted: #64748B;
  --faint: #94A3B8;
  --border: #E2E8F0;
  --danger: #DC2626;
  --success: #16A34A;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04);
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.ms {
  font-family: 'Material Symbols Rounded';
  font-weight: normal; font-style: normal; font-size: 20px; line-height: 1;
  display: inline-block; white-space: nowrap; direction: ltr;
  -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga';
  width: 1em; overflow: hidden; flex-shrink: 0;
}

/* ── Botones ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 40px; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #FFF; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #FFF; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #FFF; }
.btn.danger:hover { background: #B91C1C; border-color: #B91C1C; color: #FFF; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn .ms { font-size: 18px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); cursor: pointer; transition: background .15s;
}
.icon-btn:hover { background: #F1F5F9; }
.icon-btn.danger  { color: var(--danger); }
.icon-btn.danger:hover  { background: #FEF2F2; }
.icon-btn.success { color: var(--success); }
.icon-btn.success:hover { background: #F0FDF4; }
.icon-btn.accent  { color: var(--primary); }
.icon-btn.accent:hover  { background: var(--primary-soft); }

/* ── Formularios ─────────────────────────────────────────────────────────── */

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: .875rem; color: var(--text-2); margin-bottom: .35rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: .55rem .75rem; min-height: 40px;
  border: 1px solid #CBD5E1; border-radius: 8px; background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 110px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
.field select:disabled { background: #F1F5F9; color: var(--muted); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 2.75rem; }
.pw-wrap input::-ms-reveal { display: none; }  /* evita el ojo propio de Edge junto al nuestro */
.pw-toggle { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); }
.pw-toggle:hover { color: var(--primary); }
.field-wrap { margin-bottom: 1rem; }
.field-wrap .field { margin-bottom: 0; }
.hint { display: block; font-size: .78rem; color: var(--faint); margin-top: .3rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.caption { font-size: .85rem; color: var(--muted); margin: 0 0 1rem; }

.file-drop {
  display: flex; align-items: center; gap: .75rem; padding: .75rem;
  border: 1px dashed #CBD5E1; border-radius: 8px; background: var(--bg); cursor: pointer;
}
.file-drop:hover, .file-drop.drag { border-color: var(--primary); background: var(--primary-soft); }
.file-drop input { display: none; }
.file-drop .ms { color: var(--faint); font-size: 26px; }
.file-drop .txt { font-size: .85rem; color: var(--muted); line-height: 1.3; min-width: 0; }
.file-drop .txt b { color: var(--text); font-weight: 500; display: block; }
.file-drop .txt b.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-drop .clear { margin-left: auto; }

.alert { padding: .7rem .9rem; border-radius: 8px; font-size: .9rem; margin-bottom: 1rem; }
.alert.error   { background: #FEF2F2; color: #B91C1C; }
.alert.info    { background: #EFF6FF; color: #1D4ED8; }
.alert.success { background: #F0FDF4; color: #15803D; display: flex; gap: .5rem; align-items: center; }

/* ── Login ───────────────────────────────────────────────────────────────── */

.login { max-width: 420px; margin: 0 auto; padding: 3rem 16px; }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand .logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto .9rem;
                     background: var(--primary); color: #FFF; font-size: 1.6rem;
                     display: flex; align-items: center; justify-content: center; }
.login-brand h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
.login-brand p  { color: var(--muted); margin: .35rem 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 1.5rem; box-shadow: var(--shadow); }

/* ── Estructura ──────────────────────────────────────────────────────────── */

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.5rem 1.25rem; z-index: 20; transition: transform .2s;
}
.sidebar h3 { font-size: 1.15rem; margin: 0 0 .5rem; }
.sidebar-close { position: absolute; top: .75rem; right: .75rem; }
.sidebar-open { display: none; margin-bottom: .5rem; }
.sidebar-backdrop { display: none; }
.main { margin-left: var(--sidebar-w); padding: 2rem 2.5rem 3rem; transition: margin .2s; }
#page { max-width: 1200px; margin: 0 auto; }

body.sidebar-hidden .sidebar { transform: translateX(-100%); }
body.sidebar-hidden .main { margin-left: 0; }
body.sidebar-hidden .sidebar-open { display: inline-flex; }

.nav { display: grid; gap: .25rem; margin-top: 1.25rem; }
.nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 8px;
         color: var(--text-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: #F1F5F9; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }

.app-header h1 { font-size: 1.75rem; font-weight: 700; margin: 0; }
.app-header p  { color: var(--muted); margin: .25rem 0 1.5rem; }
.page-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.page-top .btn { margin-bottom: 1.5rem; flex-shrink: 0; }

/* ── Indicadores ─────────────────────────────────────────────────────────── */

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
       padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.kpi .label { font-size: .78rem; font-weight: 600; color: var(--muted);
              text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; margin-top: .25rem; }
.kpi .bar   { height: 4px; border-radius: 4px; margin-top: .75rem; background: var(--border); overflow: hidden; }
.kpi .bar > span { display: block; height: 100%; border-radius: 4px; }

/* ── Filtros ─────────────────────────────────────────────────────────────── */

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px;
             background: var(--surface); overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: .45rem .9rem; cursor: pointer;
                    font-size: .88rem; color: var(--text-2); white-space: nowrap; }
.segmented button + button { border-left: 1px solid var(--border); }
@media (hover: hover) { .segmented button:hover { color: var(--primary); } }
.segmented button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.filters select { padding: .45rem .75rem; border: 1px solid var(--border); border-radius: 8px;
                  background: var(--surface); font-size: .88rem; min-width: 190px; }

/* ── Filas de la tabla ───────────────────────────────────────────────────── */

.col-heads, .row { display: grid; gap: 1rem; align-items: center; }
.col-heads { font-size: .72rem; font-weight: 600; color: var(--faint); text-transform: uppercase;
             letter-spacing: .05em; padding: 0 1rem .5rem; }
.tasks.admin .col-heads, .tasks.admin .row { grid-template-columns: 5fr 2.2fr 1.4fr 1.9fr; }
.tasks .col-heads, .tasks .row { grid-template-columns: 5fr 2.2fr 1.4fr 1.2fr; }
.users .col-heads, .users .row { grid-template-columns: 3.4fr 3fr 1.5fr 1.3fr 1.6fr; }
.row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
       padding: 1rem; margin-bottom: .75rem; transition: box-shadow .15s; }
.row:hover { box-shadow: 0 4px 12px rgba(15, 23, 42, .06); }
.row > * { min-width: 0; }
.actions { display: flex; gap: .25rem; flex-wrap: wrap; }
.cell-label { display: none; }

.task-title { font-weight: 600; }
.task-title.done { color: var(--faint); text-decoration: line-through; }
.task-desc  { font-size: .85rem; color: var(--muted); margin-top: .15rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.task-id    { font-size: .75rem; color: var(--faint); font-weight: 500; }
.muted      { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.meta       { color: var(--faint); }

.person { display: flex; align-items: center; gap: .55rem; font-size: .9rem; color: var(--text-2); }
.person small { display: block; color: var(--faint); font-size: .75rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
          display: flex; align-items: center; justify-content: center;
          font-size: .75rem; font-weight: 700; flex-shrink: 0; }
.avatar.off { background: #F1F5F9; color: var(--faint); }
.avatar.lg  { width: 40px; height: 40px; font-size: .9rem; }

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .65rem;
         border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.pending  { background: #FEF3C7; color: #B45309; }
.badge.done, .badge.active { background: #DCFCE7; color: #15803D; }
.badge.inactive { background: #F1F5F9; color: var(--muted); }
.badge.admin    { background: var(--primary-soft); color: var(--primary-dark); }
.badge.encargado{ background: #E0F2FE; color: #0369A1; }

.tag, .prio { display: inline-block; padding: .05rem .5rem; border-radius: 6px; font-size: .7rem;
              font-weight: 600; margin-left: .35rem; vertical-align: middle; }
.tag.asignada { background: var(--primary-soft); color: var(--primary-dark); }
.tag.propia   { background: #CCFBF1; color: #0F766E; }
.prio { font-weight: 700; }
.prio.urgente { background: #FEE2E2; color: #B91C1C; }
.prio.alta    { background: #FFEDD5; color: #C2410C; }
.prio.media   { background: #FEF3C7; color: #B45309; }
.prio.baja    { background: #F1F5F9; color: #475569; }

.fu-count, .support { font-size: .78rem; color: var(--muted); margin-top: .3rem;
                      display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.fu-count .ms, .support .ms, .file-link .ms { font-size: 16px; }
.file-link { color: var(--primary); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.file-link:hover { text-decoration: underline; }

.closure { margin-top: .5rem; padding: .5rem .75rem; border-left: 3px solid #22C55E;
           background: #F0FDF4; border-radius: 0 8px 8px 0; font-size: .82rem; color: var(--text-2);
           overflow-wrap: anywhere; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--faint);
         border: 1px dashed #CBD5E1; border-radius: var(--radius); background: var(--surface); }
.loading { text-align: center; padding: 3rem 1rem; color: var(--faint); }

/* ── Modal ───────────────────────────────────────────────────────────────── */

dialog { width: min(500px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
         border: 0; border-radius: 14px; padding: 1.5rem; color: var(--text);
         box-shadow: 0 20px 50px rgba(15, 23, 42, .25); }
dialog.large { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h2 { font-size: 1.25rem; margin: 0; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1rem; }
.modal-actions.single { grid-template-columns: 1fr; }
.summary p { margin: .35rem 0; overflow-wrap: anywhere; }

.fu-list { max-height: 45vh; overflow-y: auto; margin-bottom: .5rem; }
.fu-item { border-left: 3px solid #C7D2FE; padding: .35rem 0 .35rem .75rem; margin-bottom: .75rem; }
.fu-item .who  { font-size: .8rem; color: var(--muted); }
.fu-item .note { font-size: .9rem; margin-top: .15rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.fu-item .file-link { font-size: .82rem; }

/* ── Avisos ──────────────────────────────────────────────────────────────── */

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: .5rem; z-index: 50; }
.toast { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-radius: 10px;
         background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 25px rgba(15, 23, 42, .12);
         font-size: .9rem; animation: toast-in .2s ease-out; }
.toast .ms { color: var(--success); }
.toast.error .ms { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Pantallas pequeñas ──────────────────────────────────────────────────── */

@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(15, 23, 42, .2); }
  .main { margin-left: 0; padding: 1rem 16px 3rem; }
  .sidebar-open { display: inline-flex; }
  body.sidebar-shown .sidebar { transform: none; }
  body.sidebar-shown .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 15;
                                          background: rgba(15, 23, 42, .35); }
  body.sidebar-hidden .sidebar { transform: translateX(-100%); }

  .col-heads { display: none; }
  .tasks .row, .tasks.admin .row, .users .row { grid-template-columns: 1fr; gap: .6rem; }
  .cell-label { display: block; font-size: .7rem; font-weight: 600; color: var(--faint);
                text-transform: uppercase; letter-spacing: .05em; margin-bottom: .15rem; }
  .actions { border-top: 1px solid var(--border); padding-top: .5rem; }
  .page-top { flex-direction: column; align-items: stretch; }
  .page-top .btn { margin-bottom: 1rem; }
  .filters > * { width: 100%; }
  .segmented { display: flex; }
  .segmented button { flex: 1; padding: .45rem .5rem; }
}

@media (max-width: 480px) {
  .kpis { gap: .6rem; }
  .kpi { padding: .8rem .9rem; }
  .kpi .value { font-size: 1.5rem; }
  .row2 { grid-template-columns: 1fr; }
  .app-header h1 { font-size: 1.4rem; }
  dialog { padding: 1.1rem; }
}
