*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #eaeaea;
  --muted: #888;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', sans-serif;
  min-height: 100vh;
  padding-bottom: 80px;
}

header {
  text-align: center;
  padding: 28px 16px 14px;
  background: linear-gradient(135deg, #16213e, #0f3460);
  border-bottom: 2px solid var(--accent);
}
header h1 { font-size: 1.9rem; }
.tagline { color: var(--accent); font-size: 0.9rem; margin-top: 4px; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid #2a2a4a;
}
.card h2 { margin-bottom: 14px; font-size: 1.05rem; }
.hidden { display: none !important; }
.hint { font-size: 0.82rem; color: var(--muted); margin-bottom: 14px; }

/* Tabs */
.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.tab-btn {
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid #3a3a6a;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.tab-btn.active {
  background: var(--accent2);
  color: var(--text);
  border-color: var(--accent);
}

/* API key row */
.api-key-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.api-key-row input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #3a3a6a;
  background: #111122;
  color: var(--text);
  font-size: 0.9rem;
}
.api-key-row input:focus { outline: none; border-color: var(--accent); }

/* Upload area */
.upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #3a3a6a;
  border-radius: var(--radius);
  padding: 28px;
  cursor: pointer;
  color: var(--muted);
  text-align: center;
  transition: border-color 0.2s;
  margin-top: 14px;
}
.upload-area:hover { border-color: var(--accent); color: var(--text); }
.upload-area input { display: none; }

#img-preview-wrap img {
  max-width: 200px;
  max-height: 140px;
  border-radius: 8px;
  border: 2px solid #2a2a4a;
  object-fit: cover;
}

/* Row inputs */
.row-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.row-input-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 5px;
}
.row-hint { font-size: 0.75rem; opacity: 0.6; }
.row-input-group input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid #3a3a6a;
  background: #111122;
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 1px;
  transition: border-color 0.2s;
}
.row-input-group input:focus {
  outline: none;
  border-color: var(--accent);
}
.row-input-group input.error { border-color: var(--accent); }

.input-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: #2a2a4a; color: var(--text); }
.btn.success { background: #27ae60; color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.status-msg {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 18px;
}

/* Ticket grid (display + preview) */
.ticket-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.ticket-grid.preview { margin-top: 4px; }

.ticket-cell {
  background: var(--accent2);
  border-radius: 6px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.25s;
  position: relative;
}
.ticket-cell.empty { background: #111122; color: transparent; }
.ticket-cell.marked { background: var(--accent); color: #fff; }
.ticket-cell.marked::after {
  content: '✓';
  position: absolute;
  top: 3px; right: 5px;
  font-size: 0.55rem;
  opacity: 0.8;
}

/* Tickets section */
#tickets-container { display: flex; flex-direction: column; gap: 20px; }
.ticket-wrapper {}
.ticket-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.ticket-label { font-size: 0.8rem; color: var(--muted); }
.win-tags { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.win-tag {
  background: #1a3a1a;
  color: #4caf50;
  border: 1px solid #4caf50;
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 0.72rem;
  white-space: nowrap;
}

.ticket-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.ticket-label {
  font-size: 0.8rem;
  color: var(--muted);
}
.win-tags {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.win-tag {
  background: #1a3a1a;
  color: #4caf50;
  border: 1px solid #4caf50;
  border-radius: 20px;
  padding: 2px 7px;
  font-size: 0.68rem;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .win-tag {
    font-size: 0.62rem;
    padding: 2px 6px;
  }
}

.btn-delete {
  background: transparent;
  border: 1px solid #c0392b;
  color: #c0392b;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-delete:hover { background: #c0392b; color: #fff; }

.delete-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.delete-confirm.hidden { display: none; }
.btn-confirm-yes {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-confirm-no {
  background: #2a2a4a;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* Caller */
.caller-input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.caller-input-row input {
  flex: 1;
  min-width: 180px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #3a3a6a;
  background: #111122;
  color: var(--text);
  font-size: 1rem;
}
.caller-input-row input:focus { outline: none; border-color: var(--accent); }

#called-numbers-display h3 {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 14px 0 8px;
}
#called-list { display: flex; flex-wrap: wrap; gap: 6px; }
.called-chip {
  background: #16213e;
  border: 1px solid #3a3a6a;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.8rem;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 1000;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }
.toast-warn { background: #c0392b; color: #fff; }
.toast-info { background: #0f3460; color: #fff; }

/* Win Banner */
.win-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #e94560, #c0392b);
  color: #fff;
  padding: 14px 28px;
  border-radius: 40px;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 4px 24px rgba(233,69,96,0.5);
  z-index: 999;
  animation: popIn 0.3s ease;
  white-space: nowrap;
}
@keyframes popIn {
  from { transform: translateX(-50%) scale(0.8); opacity: 0; }
  to   { transform: translateX(-50%) scale(1);   opacity: 1; }
}

@media (max-width: 520px) {
  .ticket-cell { height: 34px; font-size: 0.75rem; }
  header h1 { font-size: 1.4rem; }
}

/* Footer */
footer {
  text-align: center;
  padding: 24px 16px;
  border-top: 1px solid #2a2a4a;
  margin-top: 12px;
}
.about-link {
  display: inline-block;
  margin-bottom: 14px;
  background: var(--accent2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 9px 20px;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s;
}
.about-link:hover { background: var(--accent); }
.footer-brand {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  transition: color 0.2s;
}
.footer-links a:hover { color: var(--accent); }
