:root {
  --blue: #1e6fd9;
  --blue-dark: #1554b8;
  --blue-soft: #e8f1fd;
  --gray: #7c8591;
  --text: #17202b;
  --muted: #5d6773;
  --line: #e3e8ef;
  --bg: #f4f7fb;
  --card: #ffffff;
  --green: #17914f;
  --green-soft: #e3f5ea;
  --red: #d23b3b;
  --red-soft: #fdeaea;
  --amber: #b7791f;
  --amber-soft: #fdf3e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: Roboto, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 18px 18px 10px; }
.sidebar .brand img { width: 190px; display: block; }
.nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; overflow-y: auto; flex: 1; }
.nav .section { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gray); margin: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--blue-soft); color: var(--blue-dark); }
.nav .badge { margin-left: auto; }
.nav svg { width: 20px; height: 20px; flex-shrink: 0; }
.userbox { border-top: 1px solid var(--line); padding: 12px 16px; font-size: .85rem; }
.userbox strong { display: block; }

.main { flex: 1; min-width: 0; padding: 24px 28px 40px; max-width: 1200px; width: 100%; margin: 0 auto; } /* centrado en pantallas anchas */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.topbar { display: none; }
.bottombar { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
    padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  }
  .topbar img { height: 34px; }
  .layout { flex-direction: column; }
  .main { padding: 16px 16px 96px; }
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottombar a, .bottombar button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px; font-size: .7rem;
    color: var(--muted); text-decoration: none; background: none; border: 0; font-family: inherit; cursor: pointer;
  }
  .bottombar a.active { color: var(--blue); }
  .bottombar a { position: relative; }
  .bottombar .count {
    position: absolute; top: 3px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 999px; background: var(--red); color: #fff; font-size: .66rem; font-weight: 700; line-height: 17px; text-align: center;
  }
  .bottombar svg { width: 22px; height: 22px; }
  .drawer .nav a { padding: 14px 12px; }
}

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid.cols-2 { grid-template-columns: 1fr; } .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  padding: 8px 16px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: 500 .95rem var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label.field { display: block; font-size: .85rem; font-weight: 500; color: var(--muted); }
label.field > span { display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: 400 1rem var(--font); color: var(--text); background: #fff;
  border: 1px solid #cfd6df; border-radius: 9px; padding: 9px 11px; min-height: 42px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid rgba(30, 111, 217, .25); border-color: var(--blue); }
.form { display: grid; gap: 12px; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .form .row2 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.check input { width: auto; min-height: 0; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.badge.blue { background: var(--blue-soft); color: var(--blue-dark); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 6px; flex-shrink: 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--gray); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- documentos ---------- */
.attach { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.attach-item { display: flex; align-items: center; gap: 2px; max-width: 240px; }
.attach a, .doc-title a { display: inline-flex; align-items: center; gap: 5px; min-width: 0; font-size: .9rem; }
.attach a span, .doc-title a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach svg, .doc-title svg { width: 15px; height: 15px; flex-shrink: 0; }
.doc-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 500; }
.btn.icon-only { min-height: 26px; padding: 2px 4px; }
.btn.icon-only svg { width: 15px; height: 15px; }
input[type=file] { padding: 7px; background: var(--bg); }
.radio-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 2px; }
.radio-row .check input, .pick-list .check input, .pick-head .check input { width: auto; min-height: 0; }
.pick-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.pick-list { display: grid; gap: 4px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; }
.modal.wide { max-width: 880px; }
table.review select { min-height: 36px; padding: 5px 8px; font-size: .9rem; min-width: 200px; }
table.review .file-name { word-break: break-all; font-weight: 500; }
table.review td { vertical-align: top; }
table.review .badge { white-space: normal; margin: 1px 0; }
@media (max-width: 640px) {
  table.review td { flex-direction: column; align-items: stretch; text-align: left; }
  table.review select { min-width: 0; width: 100%; }
}
@media (max-width: 640px) {
  table.responsive td .attach { align-items: flex-end; }
}

/* Lista responsive: en móvil las tablas se convierten en tarjetas */
@media (max-width: 640px) {
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 2px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--gray); font-size: .8rem; text-align: left; }
  table.responsive td.actions { justify-content: flex-end; }
  table.responsive td.actions::before { content: none; }
}

/* ---------- fichaje ---------- */
.clock-card { text-align: center; padding: 28px 18px; }
.clock-state { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(23, 145, 79, .5); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(23, 145, 79, 0); } 100% { box-shadow: 0 0 0 0 rgba(23, 145, 79, 0); } }
.timer { font-size: clamp(2.8rem, 12vw, 4.2rem); font-weight: 700; letter-spacing: -1px; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.clock-actions { display: grid; gap: 10px; max-width: 420px; margin: 18px auto 0; }
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 64px;
  font: 700 1.2rem var(--font); border-radius: 14px; border: 0; cursor: pointer; color: #fff;
}
.big-btn svg { width: 26px; height: 26px; }
.big-btn.start { background: var(--blue); }
.big-btn.start:hover { background: var(--blue-dark); }
.big-btn.stop { background: var(--red); }
.big-btn:disabled { opacity: .6; cursor: wait; }
.clock-actions select { min-height: 50px; font-size: 1.02rem; }

.timeline { position: relative; height: 26px; background: var(--bg); border-radius: 6px; overflow: hidden; margin: 8px 0 4px; }
.timeline .seg { position: absolute; top: 0; bottom: 0; border-radius: 3px; min-width: 2px; }
.timeline-scale { display: flex; justify-content: space-between; font-size: .7rem; color: var(--gray); }

.seg-list { list-style: none; margin: 0; padding: 0; }
.seg-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.seg-list li:last-child { border-bottom: 0; }
.seg-list .grow { flex: 1; min-width: 0; }
.seg-list .grow .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- informes ---------- */
.stat { padding: 14px 16px; }
.stat .label { font-size: .78rem; color: var(--gray); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr 64px; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--bg); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--blue); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 10px 12px; font: 500 .92rem var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #eef5ff 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 400px; }
.login-card img { width: 250px; max-width: 100%; display: block; margin: 0 auto 22px; }
.login-title { margin: 0; font-size: 1.15rem; text-align: center; }
.login-link { display: block; text-align: center; font-size: .9rem; color: var(--blue); text-decoration: none; padding: 6px 0; }
.login-link:hover { text-decoration: underline; }
.login-card .btn { text-align: center; text-decoration: none; }

/* ---------- modal / drawer / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
@media (max-width: 640px) {
  .overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
.drawer { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); }
.drawer .panel { position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); background: var(--card); display: flex; flex-direction: column; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(30px); opacity: 0; z-index: 60;
  background: #17202b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .92rem; pointer-events: none;
  transition: all .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }
@media (max-width: 860px) { #toast { bottom: 84px; } }

.alert { padding: 10px 12px; border-radius: 9px; font-size: .9rem; }
.alert.error { background: var(--red-soft); color: var(--red); }
.alert.info { background: var(--blue-soft); color: var(--blue-dark); }
.alert.ok { background: var(--green-soft); color: var(--green); }
.alert.warn { background: var(--amber-soft); color: #8a5a12; }
.alert .badge { vertical-align: 1px; }
ul.tight { margin: 4px 0 0; padding-left: 20px; }

/* ---------- proyectos de I+D ---------- */
.rd-card { display: block; color: inherit; text-decoration: none; transition: box-shadow .15s; }
.rd-card:hover { box-shadow: 0 4px 14px rgba(16, 24, 40, .12); }
.rd-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.rd-head strong { font-size: 1.05rem; }
.rd-mine + .rd-mine { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.rd-mine details { margin-top: 8px; }
.rd-mine summary { cursor: pointer; color: var(--blue); }
.meter { margin: 10px 0; }
.meter-label { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.meter-track { position: relative; height: 10px; background: #eef2f7; border-radius: 6px; }
.meter-fill { height: 100%; border-radius: 6px; background: var(--blue); }
.meter-fill.time { background: #9aa6b5; }
.meter-fill.ok { background: var(--green); }
.meter-fill.warn { background: #e0a030; }
.meter-fill.late { background: var(--red); }
.meter-fill.idle { background: var(--blue); }
.meter-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; }
.dev.pos { color: var(--green); }
.dev.warn { color: var(--amber); }
.dev.neg { color: var(--red); }
.rd-chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.meters-2 { gap: 0 24px; }
@media (max-width: 640px) { table.responsive tfoot td:empty { display: none; } }
.rd-chart text { font-size: 11px; fill: var(--gray); }
.rd-chart text.year { font-weight: 600; fill: var(--muted); }
.rd-chart .grid { stroke: var(--line); stroke-width: 1; }
.rd-chart .planned { fill: none; stroke: #9aa6b5; stroke-width: 2; stroke-dasharray: 6 4; }
.rd-chart .actual { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linejoin: round; }
.rd-chart .actual-dot { fill: var(--blue); }
.rd-chart .today { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 3 3; }
.rd-chart .today-label { fill: var(--amber); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: 6px; border-top: 3px solid var(--blue); }
.legend i.planned { border-top: 2px dashed #9aa6b5; }
.legend i.today { border-top: 2px dashed var(--amber); }
tr.current td { background: var(--blue-soft); }
tr.future td { color: var(--muted); }
table.matrix th, table.matrix td { white-space: nowrap; padding: 6px 8px; font-size: .85rem; }
table.matrix td:first-child, table.matrix th:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
table.matrix tr.total td { font-weight: 600; border-top: 2px solid var(--line); }
table.matrix tr.target td { color: var(--muted); }
.mcell-v { padding: 1px 5px; border-radius: 5px; }
.mcell-v.c-ok { background: var(--green-soft); color: var(--green); }
.mcell-v.c-warn { background: var(--amber-soft); color: var(--amber); }
.mcell-v.c-late { background: var(--red-soft); color: var(--red); }
tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }
label.field.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
label.field.inline input { width: auto; min-height: 38px; padding: 6px 10px; }
.rd-fields { border-left: 3px solid var(--blue-soft); padding-left: 12px; display: grid; gap: 12px; }
.rd-fields.hidden { display: none; }
table.team select { min-width: 190px; min-height: 36px; padding: 5px 8px; }
table.team input { width: 96px; min-height: 36px; padding: 5px 8px; text-align: right; }
table.team input.driver { border-color: var(--blue); font-weight: 600; }
table.team td { vertical-align: middle; padding: 6px 8px; }
.month-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.mcell { position: relative; display: block; border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px 8px; font-size: .8rem; color: var(--muted); }
.mcell span { text-transform: capitalize; }
.mcell input { width: 100%; min-height: 34px; padding: 4px 6px; margin-top: 3px; text-align: right; }
.mcell.fixed { border-color: var(--blue); background: var(--blue-soft); }
.mcell.fixed input { font-weight: 600; }
.mcell .unfix { display: none; position: absolute; top: 3px; right: 4px; border: 0; background: none; color: var(--blue); cursor: pointer; font-size: .95rem; padding: 0 2px; }
.mcell.fixed .unfix { display: block; }
@media (max-width: 640px) {
  table.team thead { display: none; }
  table.team tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.team td { padding: 0; border: 0; }
  table.team td:first-child { grid-column: 1 / -1; }
  table.team select, table.team input { width: 100%; min-width: 0; }
}

@media print {
  .sidebar, .topbar, .bottombar, .no-print { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
