:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-card: #162033;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --danger: #f87171;
  --ok: #4ade80;
  --new: #facc15;
  --prepaid: #60a5fa;
  --checked: #4ade80;
  --completed: #94a3b8;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", "SF Pro Text", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.app-header .sub {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
}

.view {
  display: none;
  padding: 14px 14px 8px;
}

.view.active {
  display: block;
}

.card {
  background: linear-gradient(180deg, var(--bg-card), #121a2b);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

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

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.3;
}

.card-meta-line {
  margin-top: 2px;
}

.card-meta .dot {
  opacity: 0.55;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-NEW {
  background: rgba(250, 204, 21, 0.15);
  color: var(--new);
  border: 1px solid rgba(250, 204, 21, 0.35);
}

.badge-PREPAID {
  background: rgba(96, 165, 250, 0.15);
  color: var(--prepaid);
  border: 1px solid rgba(96, 165, 250, 0.35);
}

.badge-CHECKED_IN {
  background: rgba(74, 222, 128, 0.15);
  color: var(--checked);
  border: 1px solid rgba(74, 222, 128, 0.35);
}

.badge-COMPLETED,
.badge-CANCELLED {
  background: rgba(148, 163, 184, 0.12);
  color: var(--completed);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.actions .btn-confirm {
  grid-column: 1 / -1;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  color: #0b1220;
  background: var(--accent);
  width: 100%;
  text-align: center;
  line-height: 1.25;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-pin {
  background: #38bdf8;
}

.btn-deposit {
  background: #4ade80;
  color: #052e16;
}

.btn-confirm {
  background: #facc15;
  color: #1c1917;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 0.8rem;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

.field textarea {
  min-height: 140px;
  line-height: 1.4;
}

.template-list {
  display: grid;
  gap: 10px;
}

.template-item {
  text-align: left;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}

.template-item strong {
  display: block;
  margin-bottom: 4px;
}

.template-item span {
  color: var(--muted);
  font-size: 0.8rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 12px;
  font-size: 0.95rem;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 30;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}

.nav-btn .glyph {
  font-size: 1.15rem;
  line-height: 1;
}

.nav-btn.active {
  color: var(--accent);
}

.toast-wrap {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  z-index: 50;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: slideUp 0.22s ease-out;
}

.toast.ok {
  border-color: rgba(74, 222, 128, 0.45);
}

.toast.err {
  border-color: rgba(248, 113, 113, 0.5);
}

@keyframes slideUp {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.settings-block p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, #1e293b 0%, #0f172a 55%);
}

.login-gate[hidden] {
  display: none !important;
}

.login-card {
  width: min(100%, 360px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 18px;
}

.login-card h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.login-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 12px;
}

body.locked .app-header,
body.locked #appShell {
  visibility: hidden;
}

@media (min-width: 720px) {
  .view {
    max-width: 720px;
    margin: 0 auto;
  }

  .app-header {
    padding-left: max(16px, calc(50% - 360px));
    padding-right: max(16px, calc(50% - 360px));
  }

  .bottom-nav {
    left: 50%;
    right: auto;
    width: min(720px, 100%);
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}
