:root {
  --bg: #050810;
  --bg2: #0c1222;
  --panel: #111827;
  --glass: rgba(12, 18, 35, 0.88);
  --border: rgba(34, 211, 238, 0.22);
  --cyan: #22d3ee;
  --cyan-dim: #0891b2;
  --purple: #a855f7;
  --muted: #94a3b8;
  --text: #f1f5f9;
  --danger: #f43f5e;
  --success: #34d399;
  --glow: 0 0 24px rgba(34, 211, 238, 0.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --header-h: 56px;
  --nav-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overscroll-behavior: none;
}

body {
  padding-top: var(--safe-top);
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(34, 211, 238, 0.12), transparent 50%),
    radial-gradient(ellipse 80% 50% at 100% 50%, rgba(168, 85, 247, 0.08), transparent 45%),
    var(--bg);
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* —— Login —— */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  position: relative;
}
.login-wrap::before {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.2), transparent 70%);
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(145deg, rgba(17, 24, 39, 0.95), rgba(15, 23, 42, 0.98));
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: var(--glow), 0 24px 48px rgba(0, 0, 0, 0.45);
  position: relative;
  z-index: 1;
}
.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  margin: 0 auto 12px;
  border: 2px solid var(--cyan);
  box-shadow: var(--glow);
}
.login-card h1 {
  margin: 8px 0 4px;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--cyan);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.login-card .subtitle { color: var(--muted); font-size: 0.85rem; margin: 0 0 24px; line-height: 1.5; }
.login-card input {
  width: 100%;
  padding: 16px;
  font-size: 1.35rem;
  text-align: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  letter-spacing: 0.25em;
  -webkit-text-security: disc;
  text-security: disc;
}
.login-card input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, opacity 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--cyan-dim));
  color: #041018;
  width: 100%;
  margin-top: 16px;
  box-shadow: 0 4px 20px rgba(34, 211, 238, 0.35);
}
.btn-ghost { background: rgba(30, 41, 59, 0.8); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: linear-gradient(135deg, #f43f5e, #e11d48); color: #fff; }
.btn-purple { background: linear-gradient(135deg, var(--purple), #7c3aed); color: #fff; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 0.8rem; border-radius: 12px; }

/* —— Header —— */
.header {
  background: var(--glass);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}
.header-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-meta { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.header-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}
.badge {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
}
.badge-admin { color: var(--purple); border-color: rgba(168, 85, 247, 0.4); }
.badge-emp { color: var(--cyan); }
.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.header-actions select {
  min-height: 40px;
  max-width: 130px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}
.casier-label { font-size: 0.65rem; color: var(--muted); display: block; width: 100%; text-align: right; }

/* —— Main & tabs —— */
.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.tab-panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 12px);
}
.tab-panel--tables { padding-left: 0; padding-right: 0; padding-top: 0; }

.section-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--muted);
  padding: 12px 16px 8px;
  margin: 0;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--glass);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 50;
  backdrop-filter: blur(16px);
  min-height: var(--nav-h);
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  position: relative;
}
.bottom-nav button.active {
  color: var(--cyan);
}
.bottom-nav button.active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--cyan);
  border-radius: 2px;
  box-shadow: var(--glow);
}

/* —— Tables grid (responsive) —— */
.tables-stage {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}
.tables-stage.tables-count-1 {
  padding: 0;
  gap: 0;
  min-height: calc(100dvh - var(--header-h) - var(--nav-h) - var(--safe-top) - var(--safe-bottom) - 20px);
  grid-template-columns: 1fr;
}
.tables-stage.tables-count-2 {
  grid-template-columns: 1fr 1fr;
  padding: 8px;
  gap: 8px;
}
.tables-stage.tables-count-3,
.tables-stage.tables-count-4,
.tables-stage.tables-count-many {
  grid-template-columns: repeat(2, 1fr);
  padding: 8px;
  gap: 8px;
}
.tables-stage.tables-count-many {
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
}
@media (min-width: 520px) {
  .tables-stage.tables-count-3,
  .tables-stage.tables-count-4 {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
  .tables-stage.tables-count-1 { padding: 12px; }
  .tables-count-1 .table-card { border-radius: 24px !important; }
}

.table-card {
  --accent: var(--cyan);
  position: relative;
  background: linear-gradient(160deg, rgba(17, 24, 39, 0.98), rgba(10, 14, 26, 0.99));
  border-radius: 22px;
  border: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  padding: 16px 14px 18px;
  text-align: center;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 0 40px color-mix(in srgb, var(--accent) 12%, transparent);
  overflow: hidden;
}
.table-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 8%, transparent), transparent 40%);
  pointer-events: none;
}
.tables-count-1 .table-card {
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-width: 0;
  border-top: 3px solid var(--accent);
  min-height: 100%;
  padding: 24px 20px 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: inset 0 0 100px color-mix(in srgb, var(--accent) 10%, transparent);
}
.table-card.is-running { animation: card-pulse 3s ease-in-out infinite; }
.table-card.is-expired {
  border-color: var(--danger);
  animation: expired-pulse 1.2s ease-in-out infinite;
}
@keyframes card-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(0,0,0,0.35), 0 0 30px color-mix(in srgb, var(--accent) 15%, transparent); }
  50% { box-shadow: 0 8px 32px rgba(0,0,0,0.35), 0 0 50px color-mix(in srgb, var(--accent) 25%, transparent); }
}
@keyframes expired-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(244, 63, 94, 0.3); }
  50% { box-shadow: 0 0 40px rgba(244, 63, 94, 0.55); }
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}
.table-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  text-align: left;
  flex: 1;
}
.tables-count-1 .table-card h3 { font-size: 1.35rem; text-align: center; }
.table-card-header .tables-count-1 & { justify-content: center; }

.status-pill {
  font-size: 0.6rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.status-pill.idle { background: rgba(148, 163, 184, 0.2); color: var(--muted); }
.status-pill.live { background: rgba(34, 211, 238, 0.2); color: var(--cyan); }
.status-pill.free { background: rgba(52, 211, 153, 0.2); color: var(--success); }

.color-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.2);
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.timer-ring {
  --progress: 0;
  width: clamp(120px, 38vw, 160px);
  height: clamp(120px, 38vw, 160px);
  margin: 8px auto 12px;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) calc(var(--progress) * 1%),
    rgba(30, 41, 59, 0.9) 0
  );
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 0 12px color-mix(in srgb, var(--accent) 40%, transparent));
}
.tables-count-1 .timer-ring {
  width: min(78vw, 300px);
  height: min(78vw, 300px);
  margin: 16px auto 20px;
}
.timer-ring::after {
  content: "";
  position: absolute;
  inset: 12px;
  background: var(--bg2);
  border-radius: 50%;
  border: 1px solid var(--border);
}
.timer-inner {
  position: relative;
  z-index: 1;
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.tables-count-1 .timer-inner { font-size: clamp(1.5rem, 8vw, 2.2rem); }
.timer-sub {
  font-size: 0.65rem;
  color: var(--muted);
  display: block;
  font-weight: 600;
  margin-top: 4px;
}
.player {
  font-size: 0.85rem;
  color: var(--cyan);
  margin-bottom: 6px;
  font-weight: 600;
  position: relative;
  z-index: 1;
}
.tables-count-1 .player { font-size: 1rem; margin-bottom: 10px; }
.amount {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 6px 0;
  position: relative;
  z-index: 1;
}
.tables-count-1 .amount { font-size: 1.15rem; }
.pay-label {
  font-size: 0.7rem;
  color: var(--muted);
  min-height: 2.2em;
  line-height: 1.35;
  padding: 0 4px;
  position: relative;
  z-index: 1;
}
.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  position: relative;
  z-index: 1;
}
.tables-count-1 .card-actions { margin-top: 20px; max-width: 400px; margin-left: auto; margin-right: auto; width: 100%; }
.card-actions .btn { flex: 1; font-size: 0.9rem; min-height: 52px; }
.tables-count-1 .card-actions .btn { min-height: 56px; font-size: 1rem; }

/* —— Lists & toolbar —— */
.list-card {
  background: linear-gradient(135deg, rgba(17, 24, 39, 0.95), rgba(15, 23, 42, 0.98));
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--cyan);
  font-size: 0.85rem;
}
.list-card .row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.list-card .row:last-child { margin-bottom: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: rgba(5, 8, 16, 0.92);
  z-index: 5;
  padding: 10px 12px;
  margin: -12px -12px 12px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.toolbar label { font-size: 0.75rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.toolbar input, .toolbar select {
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
}

/* —— Modals & forms —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 16, 0.82);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}
@media (min-width: 500px) {
  .modal-backdrop { align-items: center; padding: 16px; }
}
.modal {
  background: linear-gradient(180deg, #1a2332, #0f172a);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  border: 1px solid var(--border);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}
@media (min-width: 500px) {
  .modal { border-radius: 24px; padding-bottom: 22px; }
}
.modal h2 {
  margin: 0 0 18px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--cyan);
}
.form-section {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.form-section-title {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin: 0 0 10px;
  text-transform: uppercase;
}
.modal label, .field-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 10px 0 6px;
  font-weight: 600;
}
.modal input, .modal select, .modal textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 1rem;
}
.modal textarea { min-height: 80px; resize: vertical; }
.modal .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.radio-group label, .check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  min-height: 44px;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
}
.radio-group input, .check-row input { width: 20px; height: 20px; accent-color: var(--cyan); }
.estimate-box {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid var(--border);
  color: var(--cyan);
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 8px;
}

/* —— Admin —— */
.admin-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}
.admin-tabs {
  display: flex;
  overflow-x: auto;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.admin-tabs button {
  flex-shrink: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.admin-tabs button.active {
  background: linear-gradient(135deg, var(--cyan), var(--cyan-dim));
  color: #041018;
  border-color: transparent;
}
.admin-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  padding-bottom: calc(88px + var(--safe-bottom));
}
.admin-body label { display: block; margin: 12px 0 6px; font-size: 0.8rem; color: var(--muted); }
.admin-body input, .admin-body select, .admin-body textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
}
.admin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(30, 58, 95, 0.5);
}
.admin-close {
  position: fixed;
  bottom: calc(12px + var(--safe-bottom));
  left: 14px;
  right: 14px;
  z-index: 310;
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px + var(--safe-bottom));
  left: 14px;
  right: 14px;
  background: var(--panel);
  border: 1px solid var(--cyan);
  padding: 14px 18px;
  border-radius: 14px;
  z-index: 400;
  text-align: center;
  font-size: 0.9rem;
  box-shadow: var(--glow);
}
.summary-bar {
  font-weight: 800;
  color: var(--cyan);
  margin-bottom: 12px;
  font-size: 1rem;
  padding: 0 4px;
}
.hint { font-size: 0.75rem; color: var(--muted); line-height: 1.45; }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 2.5rem; opacity: 0.5; margin-bottom: 12px; }
