:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --border: #2a2e37;
    --text: #e8e9ec;
    --text-muted: #9aa0ab;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #22c55e;
    --danger: #ef4444;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--border);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.stat-tile .label svg {
  width: 14px;
  height: 14px;
}

.stat-tile .value {
  font-size: 20px;
  font-weight: 700;
}

.stat-tile.masuk .value {
  color: var(--success);
}

.stat-tile.keluar .value {
  color: var(--danger);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 4px 0 -4px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filters select,
.filters input {
  flex: 1;
  min-width: 120px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.tx-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tx-item .icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tx-item .icon svg {
  width: 18px;
  height: 18px;
}

.tx-item.masuk .icon {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
}

.tx-item.keluar .icon {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
}

.tx-item .info {
  flex: 1;
  min-width: 0;
}

.tx-item .title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-item .meta {
  font-size: 12px;
  color: var(--text-muted);
}

.tx-item .amount {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.tx-item.masuk .amount {
  color: var(--success);
}

.tx-item.keluar .amount {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-block {
  width: 100%;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
}

.bottom-nav a svg {
  width: 22px;
  height: 22px;
}

.bottom-nav a.active {
  color: var(--primary);
}

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

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card .brand-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: var(--primary);
}

.login-card h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.pin-input {
  width: 100%;
  padding: 14px;
  font-size: 24px;
  letter-spacing: 0.4em;
  text-align: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 14px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge svg {
  width: 14px;
  height: 14px;
}

.status-badge.waiting {
  background: color-mix(in srgb, var(--text-muted) 15%, transparent);
  color: var(--text-muted);
}

.status-badge.connected {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid color-mix(in srgb, var(--primary) 20%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.install-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.install-toast span {
  flex: 1;
}

.install-toast-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.install-toast-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

#pwaInstallBtn {
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}

#pwaInstallBtn:hover {
  background: var(--primary-hover);
}

#pwaDismissBtn {
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
}
