/* Mini app de asignación: móvil primero, dentro de Telegram. Toma los colores del tema de Telegram y, si no hay, claro u oscuro según el sistema. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1b1f23);
  --hint: var(--tg-theme-hint-color, #5b6672);
  --link: var(--tg-theme-link-color, #1565c0);
  --btn: var(--tg-theme-button-color, #1565c0);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --line: rgba(120, 130, 140, .28);
  --ok-bg: #dcf3e3; --ok-fg: #14532d;
  --warn-bg: #fdf0c8; --warn-fg: #6b4800;
  --bad-bg: #fbdcdc; --bad-fg: #7a1616;
  --info-bg: #dce9fb; --info-fg: #123d73;
  --mute-bg: #e6e9ed; --mute-fg: #3b4651;
  --radius: 12px;
  --gap: 8px;
  color-scheme: light dark;
  accent-color: var(--btn);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --ok-bg: #173a24; --ok-fg: #bfe8cc;
  --warn-bg: #4a3a0c; --warn-fg: #f4dc9a;
  --bad-bg: #4a1c1c; --bad-fg: #f4c3c3;
  --info-bg: #17304f; --info-fg: #bcd5f5;
  --mute-bg: #2a3036; --mute-fg: #c3cbd3;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17212b); --text: var(--tg-theme-text-color, #f5f7f9); --hint: var(--tg-theme-hint-color, #9aa8b5);
    --link: var(--tg-theme-link-color, #6ab3f3); --surface: var(--tg-theme-secondary-bg-color, #232e3c);
    --ok-bg: #173a24; --ok-fg: #bfe8cc; --warn-bg: #4a3a0c; --warn-fg: #f4dc9a; --bad-bg: #4a1c1c; --bad-fg: #f4c3c3;
    --info-bg: #17304f; --info-fg: #bcd5f5; --mute-bg: #2a3036; --mute-fg: #c3cbd3;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 12px 6px; border-bottom: 1px solid var(--line); }
.top-row, .search-row { display: flex; align-items: center; gap: var(--gap); }
.top-row { justify-content: space-between; margin-bottom: 8px; }
.day-nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.day-label { position: relative; display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 8px; background: var(--surface); min-height: 36px; }
.day-text { font-weight: 600; white-space: nowrap; }
.day-label input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.icon-btn { min-width: 40px; min-height: 40px; border: 0; border-radius: 10px; background: var(--surface); font-size: 20px; line-height: 1; }
.chip-btn { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; background: transparent; white-space: nowrap; }
.link-btn { border: 0; background: none; color: var(--link); padding: 8px 4px; min-height: 36px; }
.search-row input[type="search"] { flex: 1; min-width: 0; min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.badge-count { display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--btn); color: var(--btn-text); font-size: 12px; }

.views { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.views::-webkit-scrollbar { display: none; }
.view-btn { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; background: transparent; white-space: nowrap; }
.view-btn[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.view-btn .n { margin-left: 6px; font-weight: 700; }
.view-btn.zero:not([aria-pressed="true"]) { opacity: .55; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 0; }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--hint); }
.filters select, .filters input { min-height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; }
.filters .link-btn { grid-column: 1 / -1; justify-self: start; }
.summary { margin: 4px 0 2px; color: var(--hint); font-size: 13px; }

.list { padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.card { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.card.selected { border-color: var(--btn); box-shadow: 0 0 0 1px var(--btn) inset; background: var(--surface); }
.card input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 2px 0 0; border: 2px solid var(--hint); border-radius: 6px; background: transparent center / 16px no-repeat; cursor: pointer; }
.card input[type="checkbox"]:checked { border-color: var(--btn); background-color: var(--btn); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3.2 3.2L13 4.8' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.card-main { min-width: 0; }
.card-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.time { font-weight: 700; font-variant-numeric: tabular-nums; }
.patient { font-weight: 600; overflow-wrap: anywhere; }
.route { margin-top: 2px; color: var(--hint); font-size: 13px; overflow-wrap: anywhere; }
.card-bottom { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.b-unassigned { background: var(--mute-bg); color: var(--mute-fg); }
.b-rejected { background: var(--bad-bg); color: var(--bad-fg); }
.b-offered { background: var(--warn-bg); color: var(--warn-fg); }
.b-ok { background: var(--ok-bg); color: var(--ok-fg); }
.b-info { background: var(--info-bg); color: var(--info-fg); }
.b-bad { background: var(--bad-bg); color: var(--bad-fg); }
.driver-chip { font-size: 13px; }
.money { margin-left: auto; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }
.card-actions { display: flex; gap: 6px; }
.btn { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: var(--btn); font-weight: 600; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.state-screen { padding: 40px 20px; text-align: center; color: var(--hint); }
.state-screen h2 { color: var(--text); margin: 0 0 8px; font-size: 18px; }
.state-screen .btn { margin-top: 14px; }
.spinner { display: inline-block; width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.bar-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.selection-bar { position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 4; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -4px 16px rgba(0, 0, 0, .12); }
.sel-info { display: flex; gap: 6px; align-items: baseline; }
.sel-info #sel-value { color: var(--hint); margin-left: 6px; }
.sel-warning { margin: 6px 0 0; padding: 6px 8px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; }
.sel-actions { display: flex; gap: 8px; margin-top: 8px; }
.sel-actions .primary { flex: 1; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 8; background: rgba(0, 0, 0, .45); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; max-height: 86vh; display: flex; flex-direction: column; background: var(--bg); border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 4px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 4px 14px 10px; }
.sheet-actions { display: flex; gap: 8px; padding: 8px 14px 12px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }
.sheet-note { margin: 4px 0 10px; color: var(--hint); font-size: 14px; }
.opt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.opt { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); min-height: 52px; }
.opt[disabled] { opacity: .55; cursor: not-allowed; }
.opt .sub { display: block; color: var(--hint); font-size: 13px; }
.opt .name { font-weight: 600; }
.group { margin: 10px 0 4px; font-weight: 600; }
.group small { color: var(--hint); font-weight: 400; }
.mini-list { margin: 4px 0 0; padding-left: 18px; color: var(--hint); font-size: 14px; }
.mini-list li { margin: 2px 0; overflow-wrap: anywhere; }
.alert-box { margin: 8px 0; padding: 8px 10px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-fg); font-size: 14px; }
.alert-box.bad { background: var(--bad-bg); color: var(--bad-fg); }
.alert-box.ok { background: var(--ok-bg); color: var(--ok-fg); }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 12; padding: 10px 14px; border-radius: 10px; background: #1b1f23; color: #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); text-align: center; }
.toast.bad { background: #7a1616; }
@media (min-width: 720px) {
  .top, .list { max-width: 760px; margin-left: auto; margin-right: auto; }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .bar-actions, .selection-bar { max-width: 760px; width: 100%; left: 50%; right: auto; transform: translateX(-50%); }
  .sheet { max-width: 560px; left: 50%; right: auto; transform: translateX(-50%); width: 100%; }
}
