:root {
  --t:  #0D9488; --td: #0F766E; --tl: #CCFBF1; --t2: #E6FFFA;
  --amber: #D97706; --al: #FFFBEB; --ab: #FDE68A;
  --green: #16A34A; --gl: #F0FDF4;
  --red:   #DC2626; --rl: #FEF2F2;
  --blue:  #2563EB; --bl: #EFF6FF;
  --purple:#7C3AED; --pl: #EDE9FE;
  --bg:    #F0FDF9; --s: #FFFFFF; --bdr: #D1FAE5;
  --tx:    #0F172A; --mx: #475569; --sx: #94A3B8;
  --r:     10px; --rs: 7px;
  --shadow: 0 1px 4px rgba(13,148,136,.1);
  --f: 'DM Sans', system-ui, sans-serif;
  --fm: 'DM Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body {
  font-family: var(--f);
  background: var(--bg);
  color: var(--tx);
  font-size: 15px;
}

/* ── TOPBAR ─────────────────────────────────────────────────────────── */
#topbar {
  background: var(--t);
  color: #fff;
  padding: 12px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-top: max(12px, env(safe-area-inset-top));
}

.tb-left h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.tb-left p {
  font-size: 11px;
  opacity: .75;
  margin-top: 1px;
}

.tb-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.online-pill {
  background: rgba(255, 255, 255, .18);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.pulse {
  width: 7px;
  height: 7px;
  background: #4ADE80;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ── SCROLL AREA ────────────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

/* ── BOTTOM NAV ─────────────────────────────────────────────────────── */
#bottomnav {
  display: flex;
  background: var(--s);
  border-top: 1px solid var(--bdr);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
  z-index: 100;
}

.nb {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 6px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--sx);
  font-size: 10px;
  font-family: var(--f);
}

.nb.on {
  color: var(--t);
}

.nb svg {
  width: 22px;
  height: 22px;
}

/* ── FAB ─────────────────────────────────────────────────────────────── */
#fab {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom) + 12px);
  right: 16px;
  width: 54px;
  height: 54px;
  background: var(--t);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(13, 148, 136, .45);
  z-index: 80;
  transition: transform .15s;
}

#fab:active {
  transform: scale(.93);
}

#fab svg {
  stroke: #fff;
  width: 24px;
  height: 24px;
}

/* ── PAGES ───────────────────────────────────────────────────────────── */
.page {
  display: none;
  padding: 12px 12px 90px;
  animation: fadeIn .18s ease;
}

.page.on {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── CARDS ───────────────────────────────────────────────────────────── */
.card {
  background: var(--s);
  border-radius: var(--r);
  border: 1px solid var(--bdr);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--t);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--t);
  border-radius: 2px;
}

/* ── STAT GRID ───────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--s);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}

.stat.accent {
  background: var(--t);
  border-color: var(--t);
  grid-column: 1 / -1;
}

.stat-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--mx);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}

.stat.accent .stat-lbl {
  color: rgba(255, 255, 255, .75);
}

.stat-val {
  font-size: 26px;
  font-weight: 700;
  color: var(--t);
  line-height: 1;
}

.stat.accent .stat-val {
  color: #fff;
  font-size: 30px;
}

.stat-sub {
  font-size: 11px;
  color: var(--sx);
  margin-top: 2px;
}

.stat.accent .stat-sub {
  color: rgba(255, 255, 255, .65);
}

/* ── SEARCH ──────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--sx);
}

.search-inp {
  width: 100%;
  padding: 10px 12px 10px 35px;
  border: 1.5px solid var(--bdr);
  border-radius: var(--rs);
  font-family: var(--f);
  font-size: 15px;
  background: var(--s);
  outline: none;
}

.search-inp:focus {
  border-color: var(--t);
}

/* ── FILTER CHIPS ────────────────────────────────────────────────────── */
.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  margin-bottom: 10px;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid var(--bdr);
  background: var(--s);
  cursor: pointer;
  white-space: nowrap;
  color: var(--mx);
  font-family: var(--f);
}

.chip.on {
  background: var(--t);
  color: #fff;
  border-color: var(--t);
}

/* ── REGISTRO CARD ───────────────────────────────────────────────────── */
.reg {
  background: var(--s);
  border-radius: var(--r);
  border: 1px solid var(--bdr);
  padding: 13px 14px;
  margin-bottom: 9px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s;
}

.reg:active {
  border-color: var(--t);
}

.reg.borrador {
  border-left: 3px solid var(--amber);
  background: var(--al);
}

.reg-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 7px;
}

.reg-name {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  margin-right: 8px;
}

.reg-hora {
  font-size: 12px;
  color: var(--mx);
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
  font-family: var(--fm);
}

.badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

.bg-felino { background: var(--pl); color: var(--purple); }
.bg-canino { background: var(--bl); color: var(--blue); }
.bg-H { background: #FDF2F8; color: #BE185D; }
.bg-M { background: #EFF6FF; color: #1D4ED8; }
.bg-pago { background: var(--gl); color: var(--green); }
.bg-cortesia { background: var(--al); color: var(--amber); }
.bg-pendiente { background: var(--rl); color: var(--red); }
.bg-borrador { background: var(--al); color: var(--amber); border: 1px dashed var(--amber); }
.bg-atendido { background: var(--gl); color: var(--green); }
.bg-no_vino { background: var(--rl); color: var(--red); }

.reg-meta {
  font-size: 12px;
  color: var(--mx);
  display: flex;
  align-items: center;
  gap: 10px;
}

.reg-actions {
  display: flex;
  gap: 7px;
  margin-top: 10px;
  border-top: 1px solid var(--bdr);
  padding-top: 10px;
  overflow-x: auto;
  flex-wrap: nowrap;
}

.ra {
  flex: 1;
  padding: 7px 6px;
  border-radius: var(--rs);
  border: 1px solid var(--bdr);
  background: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--f);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.ra.t { color: var(--t); border-color: var(--tl); }
.ra.g { color: var(--green); border-color: #BBF7D0; }
.ra.b { color: var(--blue); border-color: #BFDBFE; }
.ra.r { color: var(--red); border-color: #FECACA; }
.ra.p { color: var(--purple); border-color: var(--pl); }

.ra svg {
  width: 13px;
  height: 13px;
}

/* ── RT INDICATOR ────────────────────────────────────────────────────── */
.rt-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  background: var(--gl);
  border: 1px solid #BBF7D0;
  border-radius: var(--rs);
  padding: 6px 12px;
  margin-bottom: 10px;
}

/* ── FORM ────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 13px;
}

.label {
  font-size: 11px;
  font-weight: 700;
  color: var(--mx);
  display: block;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.inp {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #E2E8F0;
  border-radius: var(--rs);
  font-family: var(--f);
  font-size: 16px;
  background: #F8FAFC;
  outline: none;
  transition: border-color .15s, background .15s;
}

.inp:focus {
  border-color: var(--t);
  background: var(--s);
}

select.inp {
  cursor: pointer;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.esp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.esp-opt {
  border: 2px solid #E2E8F0;
  border-radius: var(--rs);
  padding: 11px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--f);
  transition: all .15s;
}

.esp-opt .ic {
  font-size: 22px;
  display: block;
  margin-bottom: 3px;
}

.esp-opt.sel-felino { border-color: var(--purple); background: var(--pl); color: var(--purple); }
.esp-opt.sel-canino { border-color: var(--blue); background: var(--bl); color: var(--blue); }
.esp-opt.sel-M { border-color: var(--blue); background: #EFF6FF; color: #1D4ED8; }
.esp-opt.sel-H { border-color: #BE185D; background: #FDF2F8; color: #BE185D; }

.draft-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--al);
  border: 1px solid var(--ab);
  border-radius: var(--rs);
  padding: 10px 13px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--amber);
  font-weight: 600;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--t);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--f);
  transition: background .15s;
}

.btn-primary:hover {
  background: var(--td);
}

.btn-primary:disabled {
  background: var(--sx);
  cursor: not-allowed;
}

.btn-sec {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--bdr);
  background: none;
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--f);
  color: var(--mx);
  margin-top: 8px;
}

/* ── STATS BARS ──────────────────────────────────────────────────────── */
.bar-wrap {
  margin-bottom: 10px;
}

.bar-lbl {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}

.bar-track {
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width .6s ease;
}

/* ── TOAST ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #0F172A;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}

#toast.show {
  opacity: 1;
}

/* ── LOADING ─────────────────────────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading.hide {
  display: none;
}

.loader-box {
  background: #fff;
  border-radius: var(--r);
  padding: 24px 32px;
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--tl);
  border-top-color: var(--t);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── MODAL ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .6);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  animation: slideUp .3s ease;
}

.modal.hide {
  display: none;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-content {
  width: 100%;
  background: var(--s);
  border-radius: var(--r) var(--r) 0 0;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, .15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--bdr);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--mx);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--bdr);
  flex-shrink: 0;
  background: var(--bg);
}

.modal-footer button {
  flex: 1;
  padding: 12px;
  border-radius: var(--rs);
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--f);
  font-size: 14px;
}

/* ── RECETA CONTENT ──────────────────────────────────────────────────── */
.receta-box {
  background: var(--s);
  border: 2px solid var(--bdr);
  border-radius: var(--r);
  padding: 16px;
  font-family: 'Arial', sans-serif;
  line-height: 1.6;
}

.receta-header {
  text-align: center;
  border-bottom: 2px solid var(--t);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.receta-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--t);
  font-weight: 700;
}

.receta-header p {
  margin: 4px 0;
  font-size: 12px;
  color: var(--mx);
}

.receta-section {
  margin-bottom: 14px;
}

.receta-section-title {
  font-weight: 700;
  color: var(--t);
  font-size: 13px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.receta-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid #F1F5F9;
}

.receta-row strong {
  color: var(--tx);
}

.receta-row span {
  color: var(--mx);
}

/* ── LOGIN ───────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--t);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 400;
}

#login-screen.hide {
  display: none;
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
}

.login-logo {
  text-align: center;
  margin-bottom: 20px;
}

.login-logo h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--t);
  letter-spacing: -.5px;
}

.login-logo p {
  font-size: 13px;
  color: var(--mx);
  margin-top: 3px;
}

.login-err {
  background: var(--rl);
  color: var(--red);
  border-radius: var(--rs);
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

/* ── ADMIN ───────────────────────────────────────────────────────────── */
.adm-section {
  background: var(--s);
  border-radius: var(--r);
  border: 1px solid var(--bdr);
  margin-bottom: 12px;
  overflow: hidden;
}

.adm-hdr {
  padding: 13px 16px;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--bdr);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.adm-body {
  padding: 14px 16px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #F1F5F9;
}

.user-row:last-child {
  border: none;
}

.user-av {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tl);
  color: var(--t);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
}

.user-info strong {
  font-size: 13px;
  display: block;
}

.user-info span {
  font-size: 11px;
  color: var(--mx);
}

.rol-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.rol-admin { background: var(--pl); color: var(--purple); }
.rol-operador { background: var(--tl); color: var(--td); }
.rol-lectura { background: #F1F5F9; color: var(--mx); }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: #F1F5F9;
}

/* ── MODAL FORM STYLES ──────────────────────────────────────────────── */
.modal-body .form-group {
  margin-bottom: 16px;
}

.modal-body .form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--t);
}

.modal-body .form-group input,
.modal-body .form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--bdr);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #F8FAFC;
  outline: none;
  transition: border-color .15s, background .15s;
}

.modal-body .form-group input:focus,
.modal-body .form-group select:focus {
  outline: none;
  border-color: var(--t);
  background: var(--s);
  box-shadow: 0 0 0 2px var(--t2);
}
