/* ===== Lanhelburu v0.9 · móvil, tablet y PWA ===== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
button, .btn, a, select, summary { touch-action: manipulation; }
.menu-btn, .tabbar, .scrim, #install-btn, .mini-btn { display: none; }
.mini-btn.show { display: inline-flex; align-items: center; justify-content: center; width: 36px; padding: 0; color: var(--muted); }
.mini-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.mini-btn:hover { color: var(--text); }
.menu-btn { width: 40px; height: 40px; border: 1px solid var(--border); background: #fff; border-radius: 10px; align-items: center; justify-content: center; color: var(--text); flex: none; padding: 0; cursor: pointer; }
.menu-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#install-btn { margin: 10px 8px 0; width: calc(100% - 16px); height: 34px; border-radius: 8px; border: 1px solid var(--navy-2); background: transparent; color: var(--navy-text); font: inherit; font-size: 12px; cursor: pointer; }
#install-btn:hover { background: var(--navy-2); color: #fff; }
#install-btn.show { display: block; }
.auth-install { display: none; margin: 12px 0 0; width: 100%; height: 42px; background: #fff; border: 1px solid var(--border); color: var(--text); border-radius: 10px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.auth-install.show { display: block; }

/* ---------- Tablet y móvil: menú lateral como cajón ---------- */
@media (max-width: 960px) {
  .app { display: block; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); height: auto; z-index: 40; flex-direction: column; align-items: stretch;
    overflow-y: auto; overflow-x: hidden; padding: calc(20px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom)); gap: 0;
    transform: translateX(-104%); transition: transform .22s ease; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 8px 0 40px rgba(0,0,0,.35); }
  .brand { padding: 4px 8px 22px; } nav { flex-direction: column; }
  nav a { padding: 12px 12px; font-size: 15px; } nav a.active { box-shadow: inset 3px 0 0 #EDEAE2; }
  .sidebar-foot { display: block; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(43,46,51,.5); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.on { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 16px 10px; gap: 10px; justify-content: flex-start; }
  .topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .lang-sw { margin-left: 0; }
  .timer { order: 5; flex: 1 1 100%; min-width: 0; width: 100%; flex-wrap: wrap; justify-content: stretch; }
  .timer #description { flex: 1 1 100%; max-width: none; }
  .timer select, #task-select { flex: 1 1 40%; max-width: none; min-width: 0; }
  #clock { margin-left: auto; }
  main { padding: 18px 16px 40px; max-width: none; }
  main:has(#view-informes:not([hidden])) { max-width: none; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .donut, #rs-donuts-card .donut, .donut.logo3d { max-width: 100%; }
  #rs-donuts-card .dn-legend, .dn-legend { min-width: 0; flex: 1 1 100%; padding-top: 0; }
  .filters select, .filters input { min-width: 0; }
  dialog { max-width: 94vw; }
}
@media (min-width: 721px) and (max-width: 960px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .timer #description { flex: 1 1 40%; }
  .timer select { flex: 0 1 200px; }
}

/* ---------- Móvil ---------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  input, select, textarea { height: 44px; font-size: 16px; }
  textarea { height: auto; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  .btn { height: 44px; padding: 0 16px; }
  .btn.ghost { height: 40px; min-width: 40px; }
  .btn.bill { width: 44px; }
  .seg button { height: 42px; } .seg2 button { height: 44px; }
  .proj-actions .btn, .client-head .btn, .task-row .btn { height: 38px; }
  .topbar { position: static; }
  .timer { gap: 6px; flex-wrap: wrap; }
  .timer select, #task-select { flex: 1 1 90px; min-width: 90px; }
  #clock { font-size: 16px; min-width: 76px; margin-left: 0; }
  .timer #toggle { flex: 0 0 auto; padding: 0 14px; }
  .card-head { flex-wrap: wrap; gap: 10px; }
  .card-head h2 { flex: 1 1 auto; }
  .j-tools { width: 100%; } .j-tools .btn, .j-tools a { flex: 1; text-align: center; }
  .seg { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .seg button { white-space: nowrap; flex: none; }
  .topbar h1 { font-size: 18px; }
  .kpi { padding: 14px; } .kpi strong { font-size: 21px; }
  .card { padding: 14px; }
  .chart { gap: 6px; height: 170px; }
  .day-bar, .day-right { width: 100%; }
  #day-label { min-width: 0; flex: 1; }
  .j-clock { font-size: 44px; }
  .j-actions { width: 100%; }
  .j-actions .btn { flex: 1; min-width: 0; height: 54px; font-size: 16px; }
  .j-now { gap: 14px; }
  .report-actions { margin-left: 0; width: 100%; }
  .report-actions .btn { flex: 1; }
  .filters { gap: 10px; } .filters label { flex: 1 1 100%; } .filters select, .filters input { width: 100%; }
  .period-nav { width: 100%; } .period-nav label { flex: 1; }
  .form-row input { min-width: 0; flex: 1 1 100%; }
  .pair { grid-template-columns: 1fr; }
  .log { grid-template-columns: 1fr auto; } .log-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .ts-status-actions { margin-left: 0; width: 100%; } .ts-status-actions .btn { flex: 1; }
  .j-dec { margin-left: 0; width: 100%; } .j-dec .btn { flex: 1; }
  .t-budget { margin: 4px 0 0; } .task-row { flex-wrap: wrap; }
  .team-block { flex-direction: column; }
  .td-add { flex-wrap: wrap; } .td-add input, .td-add select { flex: 1 1 100%; }
  .iv-table { font-size: 13px; }

  /* barra inferior */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--navy); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 2px; box-shadow: 0 -4px 20px rgba(0,0,0,.18); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border: 0; background: transparent; color: var(--navy-text); text-decoration: none; font: inherit; font-size: 11px; font-weight: 600; border-radius: 10px; cursor: pointer; position: relative; }
  .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .on { color: #fff; background: var(--navy-2); box-shadow: inset 0 -3px 0 #EDEAE2; }
  .tabbar .tb-badge { position: absolute; top: 4px; right: calc(50% - 20px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: #EDEAE2; color: #2B2E33; font-size: 10px; display: grid; place-items: center; }
  main { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

  /* diálogos a pantalla completa */
  dialog, dialog.wide-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); min-height: 100%; align-content: start; }
  .dlg-body { padding: 18px 16px; max-height: none; }
  #invoice-form { max-height: none; }
  .dialog-actions { position: sticky; bottom: 0; background: #fff; padding: 10px 0 2px; margin: 0; box-shadow: 0 -10px 12px -10px rgba(0,0,0,.12); }
  .dialog-actions .btn { flex: 1; }

  /* tablas -> tarjetas */
  main table:not(.att) { display: block; width: 100%; }
  main table:not(.att) thead { position: absolute; left: -9999px; top: -9999px; }
  main table:not(.att) tbody, main table:not(.att) tfoot, main table:not(.att) tr { display: block; }
  main table:not(.att) tbody tr, main table:not(.att) tfoot tr { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 4px 14px; margin: 0 0 10px; }
  main table:not(.att) tfoot tr { background: var(--accent-soft); border-color: transparent; }
  main table:not(.att) tbody tr:hover { background: #fff; }
  main table:not(.att) td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 8px 0; border-bottom: 1px dashed #E6E4DD; text-align: right !important; min-width: 0 !important; word-break: break-word; }
  main table:not(.att) td:last-child { border-bottom: 0; }
  main table:not(.att) td::before { content: attr(data-label); flex: 0 0 34%; max-width: 42%; text-align: left; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
  main table:not(.att) td[data-label=""]::before, main table:not(.att) td:not([data-label])::before { display: none; }
  main table:not(.att) td[data-label=""], main table:not(.att) td:not([data-label]) { justify-content: flex-end; }
  main table:not(.att) td.empty { display: block; text-align: center !important; }
  main table:not(.att) td.empty::before { display: none; }
  main table:not(.att) td:empty { display: none; }
  main table:not(.att) td .btn { height: 38px; }
  table.ts td:first-child { display: block; text-align: left !important; font-weight: 600; }
  table.ts td:first-child::before { display: block; max-width: none; margin-bottom: 2px; }
  table.ts td:first-child { font-weight: 600; } table.ts input { width: 90px; text-align: right; }
  .ts-wrap, .att-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .j-ev { white-space: normal; }
}
@media (max-width: 380px) { .kpis { grid-template-columns: 1fr 1fr; } .kpi strong { font-size: 19px; } .tabbar a, .tabbar button { font-size: 10px; } }

/* App instalada: sin rebote y con zonas seguras */
@media (display-mode: standalone) { html, body { overscroll-behavior-y: none; } }
