:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #14181f;
  --muted: #6b7280;
  --primary: #0a84ff;
  --primary-dark: #0866c6;
  --secondary: #eef2f7;
  --accent: #34c759;
  --warn: #ff9500;
  --error: #ff3b30;
  --border: #e3e7ee;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #181c24;
    --text: #f1f3f7;
    --muted: #9aa3b2;
    --secondary: #232936;
    --border: #2a313d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

* { 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 Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
}

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

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card.center {
  text-align: center;
  padding: 32px 16px;
}

.card h2, .card h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

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

.card-title {
  font-size: 17px;
  font-weight: 600;
}

.card-body {
  font-size: 15px;
  color: var(--muted);
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge.waiting { background: #ffe0a8; color: #8a4a00; }
.badge.pending { background: #cfe6ff; color: #0a4a93; }
.badge.accepted { background: #d4f3dd; color: #0d6b30; }

@media (prefers-color-scheme: dark) {
  .badge.waiting { background: #5a3d12; color: #ffd58a; }
  .badge.pending { background: #1a3c66; color: #a4ccff; }
  .badge.accepted { background: #15402a; color: #a8eebd; }
}

label {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}

input[type="text"], input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px 14px;
  font-size: 17px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

button.primary {
  background: var(--primary);
  color: white;
}
button.primary:hover { background: var(--primary-dark); }

button.secondary {
  background: var(--secondary);
  color: var(--text);
}

button.ghost {
  width: auto;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 18px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.history-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
}

.history-item .row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.history-item .period { font-weight: 600; font-size: 15px; }
.history-item .meta { color: var(--muted); font-size: 13px; }

.muted { color: var(--muted); }
.error { color: var(--error); font-size: 14px; margin-top: 8px; }
.hidden { display: none !important; }

.footer {
  text-align: center;
  padding: 16px;
  font-size: 13px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.tg-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 20px;
  background: #2ea2d8;
  color: white;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
  width: 100%;
}
.tg-button:hover {
  background: #258ec0;
  text-decoration: none;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 16px;
  color: var(--muted);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

#pwd-form {
  margin-top: 16px;
  text-align: left;
}

select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px 14px;
  font-size: 17px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
