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

:root {
  --color-bg: #eef2f7;
  --color-surface: #ffffff;
  --color-border: #dde3ec;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-label: #475569;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.05);
  --shadow-btn: 0 1px 2px rgba(37, 99, 235, 0.3), 0 3px 10px rgba(37, 99, 235, 0.2);
  --shadow-btn-hover: 0 2px 6px rgba(37, 99, 235, 0.35), 0 6px 20px rgba(37, 99, 235, 0.25);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-border: #30363d;
  --color-primary: #4f8ef7;
  --color-primary-hover: #2563eb;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-label: #8b949e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-btn: 0 1px 2px rgba(79, 142, 247, 0.2), 0 3px 10px rgba(79, 142, 247, 0.12);
  --shadow-btn-hover: 0 2px 6px rgba(79, 142, 247, 0.3), 0 6px 20px rgba(79, 142, 247, 0.18);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b949e' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1rem 5rem;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ── */
header {
  width: 100%;
  max-width: 660px;
  margin-bottom: 2rem;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.045em;
  color: var(--color-text);
  line-height: 1.1;
}

header p {
  color: var(--color-text-muted);
  margin-top: 0.4rem;
  font-size: 0.9375rem;
}

code {
  background: var(--color-border);
  color: var(--color-text);
  padding: 0.1em 0.4em;
  border-radius: 5px;
  font-size: 0.85em;
  font-family: ui-monospace, "SF Mono", monospace;
}

/* ── Theme toggle ── */
#theme-toggle {
  flex-shrink: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
  color: var(--color-text);
}

#theme-toggle:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12), var(--shadow);
}

/* ── Main layout ── */
main {
  width: 100%;
  max-width: 660px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}

/* ── Fields ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-label);
}

input,
textarea,
select {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  font-family: inherit;
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* ── Guest sections ── */
.guest-section {
  border-left: 3px solid var(--color-primary);
  margin-top: 0;
}

.guest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--color-border);
}

.guest-header h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.remove-guest {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.remove-guest:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.06);
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.fields-grid .full-width {
  grid-column: 1 / -1;
}

/* ── Form actions ── */
.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

#add-guest {
  background: none;
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 1.125rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

#add-guest:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(37, 99, 235, 0.04);
}

button[type="submit"] {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

button[type="submit"]:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow-btn-hover);
  transform: translateY(-1px);
}

button[type="submit"]:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-btn);
}

button[type="submit"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── AL select row / view-DATs button ── */
.al-select-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.al-select-row select { flex: 1; }

.view-dats-btn {
  flex-shrink: 0;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.view-dats-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(37, 99, 235, 0.04);
}
.view-dats-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── DAT history modal ── */
.dats-modal {
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.dats-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.dats-list:empty { display: none; }

.dat-item-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  text-align: left;
  padding: 0.65rem 0.85rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dat-item-btn:hover {
  border-color: var(--color-primary);
  background: rgba(37, 99, 235, 0.04);
}
.dat-item-btn strong { font-size: 0.88rem; }
.dat-item-btn span { font-size: 0.78rem; color: var(--color-text-muted); }

/* ── Popup ── */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.popup-overlay.hidden {
  display: none;
}

.popup {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2), 0 24px 60px rgba(0, 0, 0, 0.15);
}

.popup-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.12);
  border: 1.5px solid rgba(34, 197, 94, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.popup h2 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.popup-subtitle {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}

.popup-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem 1rem;
  margin-bottom: 1.5rem;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 1rem 1.125rem;
}

.popup-details dt {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  align-self: end;
}

.popup-details dd {
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-all;
}

.popup-actions {
  display: flex;
  gap: 0.625rem;
}

.btn-submit-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #16a34a;
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: 0 1px 2px rgba(22, 163, 74, 0.3), 0 3px 10px rgba(22, 163, 74, 0.2);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn-submit-link:hover {
  background: #15803d;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35), 0 6px 20px rgba(22, 163, 74, 0.25);
  transform: translateY(-1px);
}

.btn-submit-link:active {
  transform: translateY(0);
}

#popup-close {
  flex: 1;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

#popup-close:hover {
  border-color: var(--color-text-muted);
  background: var(--color-bg);
  transform: translateY(-1px);
}

#popup-close:active {
  transform: translateY(0);
}

/* ── Header actions (greeting / manage / theme / logout) ── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.user-greeting {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-right: 0.25rem;
  white-space: nowrap;
}

.header-actions #manage-toggle,
.logout-form button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, color 0.15s;
}

.header-actions #manage-toggle:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.logout-form { margin: 0; }
.logout-form button:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* ── AL management modal ── */
.al-modal {
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

.al-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.al-modal-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-x {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.modal-x:hover { color: var(--color-text); background: var(--color-bg); }

.al-add-btn {
  width: 100%;
  margin-top: 1rem;
  background: none;
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.al-add-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(37, 99, 235, 0.04);
}
.al-add-btn.hidden { display: none; }

.al-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.al-list:empty { display: none; }

.al-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.al-item-info { display: flex; flex-direction: column; gap: 0.15rem; }
.al-item-info strong { font-size: 0.9rem; }
.al-item-info span { font-size: 0.78rem; color: var(--color-text-muted); }
.al-empty { font-size: 0.85rem; color: var(--color-text-muted); }

.al-form {
  gap: 1rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}
.al-form.hidden { display: none; }

.al-form .popup-actions { justify-content: flex-end; }

#al-form-cancel {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6875rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#al-form-cancel:hover {
  border-color: var(--color-text-muted);
  color: var(--color-text);
  background: var(--color-bg);
}

.no-als-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}
.no-als-hint.hidden { display: none; }

/* ── Login page ── */
.login-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.045em;
  margin-bottom: 0.25rem;
}

.login-sub {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}
.login-error.hidden { display: none; }

/* ── Field error state ── */
.field.has-error label {
  color: #ef4444;
}

.field.has-error input,
.field.has-error select {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.field.has-error input:focus,
.field.has-error select:focus {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}
