:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f3f4f6;
  --card: #fff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --error: #dc2626;
  --success: #059669;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.5;
}

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

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

.meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fee2e2;
  color: var(--error);
}

.badge.ok {
  background: #d1fae5;
  color: var(--success);
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}

.card h2 small {
  font-size: 13px;
  font-weight: normal;
  color: var(--muted);
  margin-left: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

label em {
  color: var(--error);
  font-style: normal;
}

input[type="text"],
input[type="password"],
input[type="datetime-local"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

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

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  transition: all 0.15s;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

.dropzone p { margin: 4px 0; color: var(--muted); }
.dropzone strong { color: var(--text); }
.hint { font-size: 13px; color: var(--muted); }
.hint a { color: var(--primary); }

.btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover:not(:disabled) {
  background: #f9fafb;
}

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

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #e5e7eb !important;
  color: #9ca3af !important;
  border-color: #e5e7eb !important;
}

.normalize-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-hint {
  font-size: 14px;
  color: var(--muted);
}
.btn-hint.ready {
  color: var(--success);
  font-weight: 500;
}
.btn-hint.warn {
  color: #d97706;
}

.progress-box {
  margin-top: 16px;
  padding: 16px 20px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-info {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-info > div:first-child {
  font-size: 15px;
  font-weight: 500;
  color: #1e40af;
}

.progress-elapsed {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.progress-box .spinner {
  width: 22px;
  height: 22px;
  border-width: 3px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  font-family: inherit;
}

.btn-link:hover { text-decoration: underline; }

.hidden { display: none !important; }

#file-info {
  margin-top: 12px;
  padding: 10px 14px;
  background: #f9fafb;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#paste-area textarea {
  width: 100%;
  resize: vertical;
}

#progress {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fee2e2;
  border-left: 3px solid var(--error);
  color: var(--error);
  border-radius: 4px;
  font-size: 14px;
  white-space: pre-wrap;
}

.table-wrap {
  overflow-x: auto;
  max-height: 500px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f9fafb;
  position: sticky;
  top: 0;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}

td[contenteditable="true"]:focus {
  outline: 2px solid var(--primary);
  background: #eff6ff;
}

td.empty-required {
  background: #fef3c7;
}

.actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

label.full-width {
  display: block;
  margin-top: 14px;
}
label.full-width textarea {
  width: 100%;
  resize: vertical;
  font-family: inherit;
}
label em.optional {
  color: var(--muted);
  font-style: normal;
  font-weight: normal;
}

.result-banner {
  margin: 12px 0;
  padding: 10px 14px;
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  font-size: 14px;
  color: #1e40af;
}

#csv-preview-wrap {
  margin-top: 16px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
#csv-preview-wrap summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
}
#csv-preview-wrap[open] summary { color: var(--primary); }
.csv-preview {
  background: #1f2937;
  color: #e5e7eb;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 300px;
  margin: 8px 0 0;
  white-space: pre;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
}

/* ===== Room summary cards ===== */
.room-summary { margin-bottom: 16px; }
.room-summary:empty { display: none; }

.room-summary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.room-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fafafa;
  transition: all 0.15s;
}

.room-card.empty { opacity: 0.55; }
.room-card.full  { background: #ecfdf5; border-color: #a7f3d0; }
.room-card.over  { background: #fef2f2; border-color: #fca5a5; }

.room-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.room-card .badge-cap {
  font-size: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
}

.room-card.full .badge-cap { background: #d1fae5; color: var(--success); border-color: #6ee7b7; }
.room-card.over .badge-cap { background: #fee2e2; color: var(--error);   border-color: #fca5a5; }

.room-card .room-note {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
}

.room-card ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}

.room-card .age {
  font-size: 11px;
  color: var(--muted);
}

.room-card .muted {
  color: var(--muted);
  font-style: italic;
  list-style: none;
  margin-left: -18px;
}

.tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.tag.master { background: #fef3c7; color: #92400e; }
.tag.dorm   { background: #ddd6fe; color: #5b21b6; }

.overflow-warn {
  margin-top: 10px;
  padding: 8px 12px;
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 13px;
  color: #92400e;
}

dialog {
  border: none;
  border-radius: 8px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

dialog::backdrop {
  background: rgba(0,0,0,0.4);
}

dialog h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

dialog menu {
  margin: 20px 0 0;
  padding: 0;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

dialog menu button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}

dialog menu button.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

dialog label { margin: 12px 0; }
dialog label input, dialog label select { width: 100%; }
