/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --accent:  #1a237e;
  --bg:      #f5f5f5;
  --surface: #ffffff;
  --border:  #e0e0e0;
  --text:    #202124;
  --muted:   #5f6368;
  --radius:  12px;
  --shadow:  0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);

  --ei-green:  #e8f5e9; --ei-green-icon:  #2e7d32;
  --ei-blue:   #e3f2fd; --ei-blue-icon:   #1565c0;
  --ei-orange: #fff3e0; --ei-orange-icon: #e65100;
  --ei-purple: #f3e5f5; --ei-purple-icon: #6a1b9a;
  --ei-red:    #fce4ec; --ei-red-icon:    #c62828;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-top: 60px;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 4px;
  z-index: 100;
}

.header-logo {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.header-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.header-logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -.01em;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  padding: 10px 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s;
}
.btn-icon:active { background: var(--bg); }

.worker-chip {
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--ei-blue);
  border-radius: 20px;
  padding: 6px 14px;
  min-width: unset;
  border: none;
  cursor: pointer;
}

/* ── Screen title (sub-screens only) ───────────────────────────────────── */
#screen-title {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Worker modal ──────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 24px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.modal-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin: 0 auto 16px;
  overflow: hidden;
}
.modal-logo img { width: 100%; height: 100%; object-fit: cover; }

.modal-card h2 {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--text);
  font-weight: 600;
}

.btn-worker {
  display: block;
  width: 100%;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}
.btn-worker:last-child { margin-bottom: 0; }
.btn-worker:active { background: var(--bg); }

/* ── Screens ───────────────────────────────────────────────────────────── */
.screen { padding: 12px 16px; }

/* ── Home: event list ───────────────────────────────────────────────────── */
.event-list {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-width: 480px;
  margin: 4px auto 0;
}

.event-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 16px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 14px;
  text-align: left;
  transition: background .12s;
  min-height: 72px;
}
.event-item:last-child { border-bottom: none; }
.event-item:active { background: var(--bg); }

.event-item-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.event-item-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.event-item-title {
  font-size: .97rem;
  font-weight: 600;
  color: var(--text);
}
.event-item-sub {
  font-size: .8rem;
  color: var(--muted);
}
.event-item-chevron {
  color: var(--border);
  font-size: 1.4rem;
  line-height: 1;
}

.ei-green  { background: var(--ei-green); }
.ei-blue   { background: var(--ei-blue); }
.ei-orange { background: var(--ei-orange); }
.ei-purple { background: var(--ei-purple); }
.ei-red    { background: var(--ei-red); }

.offline-badge {
  text-align: center;
  font-size: .8rem;
  color: #e65100;
  font-weight: 600;
  margin-top: 12px;
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
.event-form {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 32px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.flex1 { flex: 1; }
.flex2 { flex: 2; }

label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.opt {
  font-weight: 400;
  text-transform: none;
  font-size: .85em;
  letter-spacing: 0;
  color: #9e9e9e;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 13px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .97rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .18s, box-shadow .18s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,35,126,.08);
}

textarea { resize: none; }

.scan-row {
  display: flex;
  gap: 8px;
}
.scan-row input { flex: 1; }

.btn-scan {
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  white-space: nowrap;
  min-height: 48px;
  color: var(--muted);
}
.btn-scan:active { background: var(--border); }

/* ── Machine grid ──────────────────────────────────────────────────────── */
.machine-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 340px) {
  .machine-grid { grid-template-columns: repeat(3, 1fr); }
}

.btn-machine {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  gap: 3px;
  min-height: 64px;
  transition: border-color .15s, background .15s;
}
.btn-machine.active {
  border-color: var(--accent);
  background: #e8eaf6;
}
.btn-machine:active { opacity: .8; }

.maq-cod {
  font-size: .6rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .03em;
}
.maq-nom {
  font-size: .7rem;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  white-space: pre-line;
}

/* ── Choice buttons ─────────────────────────────────────────────────────── */
.choice-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.choice-grid.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.btn-choice {
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: .92rem;
  text-align: left;
  transition: border-color .15s, background .15s;
  color: var(--text);
}
.btn-choice.active {
  border-color: var(--accent);
  background: #e8eaf6;
  font-weight: 600;
}
.btn-choice:active { opacity: .8; }

/* ── Confirm button ─────────────────────────────────────────────────────── */
.btn-confirm {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .01em;
  box-shadow: var(--shadow);
  transition: opacity .15s;
}
.btn-confirm:disabled { opacity: .45; cursor: not-allowed; }
.btn-confirm:active   { opacity: .85; }

.btn-secondary {
  padding: 13px 28px;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

/* ── Scanner overlay ────────────────────────────────────────────────────── */
#scanner-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
}

.scanner-hint {
  color: #fff;
  font-size: .95rem;
  opacity: .8;
}

#scanner-container {
  width: 300px;
  max-width: 90vw;
  border-radius: 12px;
  overflow: hidden;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  z-index: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  transition: opacity .25s;
}

.toast-success { background: #2e7d32; color: #fff; }
.toast-error   { background: #c62828; color: #fff; }
.toast-warn    { background: #e65100; color: #fff; }
.toast-info    { background: #333;    color: #fff; }

/* ── Utils ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Cotizaciones ───────────────────────────────────────────────────────── */
.ei-navy { background: #e8eaf6; }

.cot-toolbar {
  max-width: 480px;
  margin: 0 auto 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cot-search-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  background: var(--surface);
}
.cot-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.cot-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.cot-filters::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: .82rem;
  white-space: nowrap;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.cot-list {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 60px;
}

.cot-loading {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: .9rem;
}

.cot-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .15s;
}
.cot-card:active { box-shadow: none; background: var(--bg); }

.cot-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.cot-id { font-size: .78rem; font-weight: 700; color: var(--muted); }
.cot-cliente { font-size: .92rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }

.cot-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cot-fecha { font-size: .78rem; color: var(--muted); }
.cot-total { font-size: .95rem; font-weight: 700; color: var(--accent); }

.status-chip {
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
}
.status-pending { background: #fff8e1; color: #f57f17; }
.status-ok      { background: #e8f5e9; color: #2e7d32; }
.status-no      { background: #fce4ec; color: #c62828; }

.cot-total-bar {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0);
  left: 0; right: 0;
  background: var(--accent);
  color: #fff;
  text-align: center;
  padding: 10px;
  font-size: .85rem;
  font-weight: 600;
}

/* Detail */
.cot-detail { max-width: 480px; margin: 0 auto; padding-bottom: 40px; }

.cot-detail-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0; }
.detail-value { font-size: .9rem; color: var(--text); text-align: right; }

.cot-items-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.cot-items-label { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; }

.cot-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cot-item:last-child { border-bottom: none; }

.cot-item-num { font-size: .75rem; font-weight: 700; color: var(--muted); width: 18px; flex-shrink: 0; padding-top: 2px; }
.cot-item-body { flex: 1; }
.cot-item-desc { font-size: .88rem; color: var(--text); line-height: 1.4; margin-bottom: 3px; }
.cot-item-meta { font-size: .76rem; color: var(--muted); }
.cot-item-total { font-size: .9rem; font-weight: 700; color: var(--accent); flex-shrink: 0; }

.cot-totals {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  color: var(--muted);
}
.total-row:last-child { border-bottom: none; }
.total-final { font-weight: 700; font-size: 1.05rem; color: var(--text); }
