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

:root {
  --bg: #f2f5fa;
  --panel: #ffffff;
  --line: #e6eaf2;
  --text: #1b2333;
  --muted: #6a7590;
  --accent: #4f6ef7;
  --accent-soft: #eef1ff;
  --green: #16a34a;
  --green-soft: #e8f8ee;
  --red: #e5484d;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fdf3e3;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}
.hidden { display: none !important; }

button { font: inherit; cursor: pointer; border: none; border-radius: 12px; padding: 9px 16px; background: var(--accent); color: #fff; font-weight: 600; transition: transform .05s ease, opacity .15s; }
button:active { transform: scale(.97); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { background: #f0f2f8; }
button.danger { background: var(--red); }
button.success { background: var(--green); }
button.small { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 11px; border: 1.5px solid var(--line);
  background: #fff; color: var(--text); font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=checkbox], input[type=file] { width: auto; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #e8edff, transparent), var(--bg); }
.login-card { background: var(--panel); padding: 34px 30px; border-radius: 22px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card .brand { width: 56px; height: 56px; font-size: 26px; margin-bottom: 16px; }
.login-card h1 { font-size: 24px; }
.login-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { margin-top: 6px; }
.login-card button { width: 100%; margin-top: 6px; padding: 12px; font-size: 15px; }
.turnstile { margin: 12px 0; min-height: 65px; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; }

.brand { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #4f6ef7, #7c5cf0); color: #fff; font-weight: 800; border-radius: 16px; }
.brand.small { width: 32px; height: 32px; font-size: 15px; border-radius: 10px; }

/* App shell */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-row h1 { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
#user-badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

.tabs { display: flex; gap: 4px; padding: 10px 16px; overflow-x: auto; scrollbar-width: none; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 61px; z-index: 19; }
.tabs::-webkit-scrollbar { display: none; }
.tab { background: transparent; color: var(--muted); white-space: nowrap; font-weight: 600; }
.tab.active { background: var(--accent-soft); color: var(--accent); }

main { padding: 20px 16px 80px; max-width: 1100px; margin: 0 auto; }
.view h2 { font-size: 20px; margin-bottom: 4px; }
.view .subtitle { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type=search] { max-width: 260px; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Cards grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.pcard { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; border: 1px solid transparent; position: relative; }
.pcard:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(16,24,40,.1); }
.pcard .avatar { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.pcard .pname { font-weight: 700; font-size: 15px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; }
.pcard .pmeta { color: var(--muted); font-size: 13px; }
.pcard .actions { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.activo { background: var(--green); }
.dot.inactivo { background: var(--red); }
.cargo-chip { background: var(--accent-soft); color: var(--accent); }
.jefe { background: #f3e8ff; color: #9333ea; }

.cards-stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat .lbl { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; font-size: 14px; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
th { background: #fafbfe; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(23,28,45,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { background: var(--panel); border-radius: 20px; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; padding: 24px; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-box.wide { max-width: 620px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 8px; }
.modal-box h3 { margin-bottom: 16px; font-size: 18px; }
.confirm-msg { margin-bottom: 18px; font-size: 15px; }

.profile-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.profile-head .avatar { width: 64px; height: 64px; font-size: 24px; }
.profile-head .pname { font-size: 19px; font-weight: 800; }
.profile-head .badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.tabs-inline { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs-inline button { background: transparent; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent; }
.tabs-inline button.active { color: var(--accent); border-bottom-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea { margin-top: 4px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 10px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv div { display: flex; flex-direction: column; }
.kv .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kv .v { font-size: 14.5px; font-weight: 500; }
.kv .v.empty { color: #c3c9d6; font-weight: 400; }

.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: none; }
.doc-icon { font-size: 20px; margin-right: 8px; }
.doc-meta { color: var(--muted); font-size: 12.5px; }
.upload-btn { margin-bottom: 14px; }

.empty { color: var(--muted); padding: 30px; text-align: center; }
.empty .big { font-size: 40px; margin-bottom: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1b2333; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.ok { background: #14532d; }
.toast.err { background: #7f1d1d; }

.summary { font-size: 14px; color: var(--muted); margin: 10px 0; }
.summary b { color: var(--text); }

/* Manifiestos */
.modal-box.xwide { max-width: 900px; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: #f6f8fd; }
.mani-head { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.mani-head label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.mani-head input { margin-top: 4px; }
.visita { border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; background: #fbfcfe; }
.visita-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.visita-num { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.visita-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.visita-grid label { font-size: 12px; font-weight: 600; color: var(--muted); }
.visita-grid input, .visita-grid select { margin-top: 3px; padding: 8px 10px; font-size: 13.5px; }
.visita-grid .full { grid-column: 1 / -1; }
.mani-totals { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; padding: 12px 14px; background: var(--accent-soft); border-radius: 12px; font-size: 14px; color: var(--muted); }
.mani-totals b { color: var(--text); }

@media (max-width: 700px) {
  .mani-head { grid-template-columns: 1fr; }
  .visita-grid { grid-template-columns: 1fr 1fr; }
}

/* Seguimiento mensual */
.seg-group-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }
.seg-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.seg-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.seg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.seg-name { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg-meta { display: flex; gap: 12px; color: var(--muted); font-size: 12.5px; }
.seg-meta b { color: var(--text); }
.seg-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg-dias { font-size: 13px; color: var(--muted); max-height: 220px; overflow-y: auto; border-right: 1px solid var(--line); padding-right: 10px; }
.sd-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.sd-row b { color: var(--text); font-weight: 600; }
.sd-empty { color: #c3c9d6; font-style: italic; }
.seg-totales { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-content: start; }
.seg-totales .st { font-size: 12.5px; }
.seg-totales .lbl { color: var(--muted); font-weight: 600; }
.seg-totales .val { font-weight: 700; text-align: right; }
.seg-totales .tot { color: var(--accent); font-size: 14px; font-weight: 800; }
.bono-edit { grid-column: 1 / -1; margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--line); }
.bono-toggle { background: transparent; color: var(--muted); font-weight: 600; border: 1.5px dashed var(--line); border-radius: 10px; padding: 5px 12px; font-size: 12.5px; }
.bono-toggle:hover { background: #f0f2f8; }
.bono-panel { display: flex; align-items: flex-end; gap: 8px; margin-top: 8px; }
.bono-panel label { font-size: 12px; font-weight: 600; color: var(--muted); }
.bono-panel input { margin-top: 3px; padding: 7px 10px; font-size: 13.5px; max-width: 170px; }

@media (max-width: 700px) {
  .seg-body { grid-template-columns: 1fr; }
  .seg-dias { border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 10px; }
}

@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .topbar-right .ghost { padding: 6px 10px; font-size: 12.5px; }
  .tabs { top: 55px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  main { padding: 16px 12px 80px; }
}
