:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #b3541e;
  --primary-dark: #8f4217;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --success: #1e7a4c;
  --success-bg: #e8f7ef;
  --border: #e2e4e9;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 20, 20, 0.08), 0 1px 2px rgba(20, 20, 20, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; }

a { color: var(--primary); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header .brand {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.app-header .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (min-width: 480px) {
  .app-header .brand { font-size: 1.05rem; }
  .app-header .user-info { font-size: 0.9rem; gap: 10px; }
}

@media (max-width: 399px) {
  .app-header #username-label { display: none; }
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 100px;
}

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

button, .btn {
  font: inherit;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 600;
  cursor: pointer;
  min-height: 46px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}

.btn-block { width: 100%; display: block; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  border-radius: 999px;
  padding: 16px 22px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 18px rgba(179, 84, 30, 0.45);
  font-size: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.alert {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.92rem;
  margin-bottom: 14px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }

.hidden { display: none !important; }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card h1 { text-align: center; font-size: 1.4rem; }
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.92rem;
}

/* Cámara */
.camera-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.camera-overlay video, .camera-overlay canvas, .camera-overlay img.preview {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: #000;
}
.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.6);
}
.shutter-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255,255,255,0.5);
}
.camera-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  z-index: 5;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

/* Lista de tickets */
.ticket-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.ticket-item:last-child { border-bottom: none; }
.ticket-item .num { font-weight: 700; }
.ticket-item .meta { font-size: 0.82rem; color: var(--text-muted); }
.ticket-item .amount { font-weight: 700; white-space: nowrap; }

.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td {
  text-align: left;
  padding: 6px 4px;
  font-size: 0.88rem;
}
.items-table input { padding: 8px; font-size: 0.88rem; }
.items-table .qty-col { width: 54px; }
.items-table .price-col { width: 72px; }
.items-table .remove-col { width: 34px; }

.item-remove {
  background: transparent;
  color: var(--danger);
  padding: 4px 8px;
  min-height: auto;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.tab-btn {
  flex: 1;
  background: transparent;
  border-radius: 9px;
  padding: 10px;
  font-weight: 600;
  color: var(--text-muted);
}
.tab-btn.active { background: var(--primary); color: #fff; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { flex: 1; min-width: 130px; margin-bottom: 0; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 9px 6px;
  border-bottom: 1px solid var(--border);
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.pill-active { background: var(--success-bg); color: var(--success); }
.pill-inactive { background: var(--danger-bg); color: var(--danger); }

@media (min-width: 640px) {
  main { padding: 24px; }
}
