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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Poppins', sans-serif;
  color: #1a1a1a;
  background: #faf9f6;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 3.5rem;
}

.container {
  width: 100%;
  max-width: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Header */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.subtitle {
  font-style: italic;
  color: #888;
  font-size: 1.05rem;
  margin-left: 0.15rem;
}

.header-link a {
  font-size: 1rem;
  color: #999;
  text-decoration: none;
  transition: color 0.15s;
}

.header-link a:hover {
  color: #1a1a1a;
}

.divider {
  border: none;
  border-top: 2px solid #1a1a1a;
  margin-bottom: 1rem;
}

/* Form elements */
label {
  display: block;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
  color: #555;
}

select {
  width: 100%;
  padding: 0.7rem 1rem;
  font-family: 'Poppins', sans-serif;
  font-size: 1.1rem;
  border: 1.5px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  transition: border-color 0.15s;
}

select:focus {
  outline: none;
  border-color: #1a1a1a;
}

.btn {
  display: inline-block;
  padding: 0.6rem 1.6rem;
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  background: #1a1a1a;
  color: #faf9f6;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: #333;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

/* Textarea */
textarea {
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 0.85rem;
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  border: 1.5px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  resize: none;
  transition: border-color 0.15s;
}

textarea:focus {
  outline: none;
  border-color: #1a1a1a;
}

input[type="text"],
input[type="number"] {
  padding: 0.5rem 0.7rem;
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  border: 1.5px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: #1a1a1a;
}

.field-hint {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0.15rem;
}

/* File upload */
.upload-area {
  padding: 1rem;
  border: 1.5px dashed #ccc;
  border-radius: 4px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.upload-area:hover {
  border-color: #999;
  background: #f5f4f0;
}

.upload-area.has-file {
  border-color: #1a1a1a;
  border-style: solid;
  background: #f5f4f0;
}

.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-label {
  font-size: 1rem;
  color: #888;
}

.upload-label strong {
  color: #1a1a1a;
}

.upload-filename {
  font-size: 0.9rem;
  color: #1a1a1a;
  font-style: italic;
  margin-top: 0.15rem;
}

.or-divider {
  text-align: center;
  margin: 0.85rem 0;
  font-size: 0.8rem;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Messages */
.message {
  padding: 0.65rem 1rem;
  border-radius: 4px;
  margin-bottom: 1.25rem;
  font-size: 1rem;
  border-left: 3px solid;
}

.message.success {
  background: #f0f7f0;
  border-color: #4a8c5c;
  color: #2d5a3a;
}

.message.error {
  background: #fdf0ee;
  border-color: #c0392b;
  color: #8b2020;
}

.message.info {
  background: #f5f4f0;
  border-color: #999;
  color: #555;
}

/* ---- Main page: two-column layout ---- */
.main-layout {
  flex: 1;
  display: flex;
  gap: 3rem;
  min-height: 0;
}

.main-left {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* People list */
.people-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.people-group {
  margin-bottom: 0.75rem;
}

.people-group-label {
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: gray;
  padding: 0 0.5rem;
  margin-bottom: 0.15rem;
}

.person-link {
  display: block;
  padding: 0.25rem 0.5rem;
  font-size: 0.95rem;
  color: #1a1a1a;
  text-decoration: none;
  border-radius: 3px;
  transition: background 0.1s;
  cursor: pointer;
}

.person-link:hover {
  background: #f0eeea;
}

.person-link.active {
  background: #1a1a1a;
  color: #faf9f6;
}

/* Preview card */
.preview-card {
  flex: 1;
  display: none;
  flex-direction: column;
  background: #fff;
  border: 1.5px solid #e0ddd8;
  border-radius: 6px;
  padding: 1.5rem;
  min-height: 0;
}

.preview-card.visible {
  display: flex;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.preview-name {
  font-size: 1.5rem;
  font-weight: 700;
}

.preview-roles {
  font-size: 1rem;
  color: #888;
  font-style: italic;
  margin-top: 0.1rem;
}

.preview-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.preview-section {
  margin-bottom: 0.85rem;
}

.preview-section-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #999;
  margin-bottom: 0.3rem;
}

.preview-list {
  list-style: none;
  padding: 0;
}

.preview-list li {
  font-size: 1.05rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid #f0eeea;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.preview-list li:last-child {
  border-bottom: none;
}

.preview-date {
  color: darkgreen;
  font-size: 1rem;
  white-space: nowrap;
}

.writer-tag {
  display: inline-block;
  font-size: 0.95rem;
  padding: 0.15rem 0.5rem;
  background: #f0eeea;
  border-radius: 3px;
  margin: 0.1rem 0.25rem 0.1rem 0;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-style: italic;
  font-size: 1.1rem;
  border: 1.5px dashed #e0ddd8;
  border-radius: 6px;
}

/* Meta info */
.meta {
  font-size: 0.85rem;
  color: #aaa;
  font-style: italic;
  margin-top: 0.5rem;
}

/* Parse progress */
.parse-progress {
  padding: 0.75rem 1rem;
  background: #f5f4f0;
  border: 1.5px solid #e0ddd8;
  border-radius: 4px;
  margin-bottom: 1.25rem;
}

.progress-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #ccc;
  border-top-color: #1a1a1a;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.progress-text {
  font-size: 0.95rem;
  color: #555;
}

/* ---- Admin page: two-column layout ---- */
.admin-layout {
  flex: 1;
  display: flex;
  gap: 3rem;
  min-height: 0;
}

.admin-left {
  flex: 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.admin-right {
  flex: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.paste-label {
  margin-top: 0.85rem;
}

.paste-area {
  flex: none !important;
  min-height: 5rem;
  max-height: 8rem;
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-top: 0.85rem;
}

.form-row .btn {
  white-space: nowrap;
}

#school-year {
  width: 9rem;
}

/* ---- Roster management ---- */
.roster-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e0ddd8;
}

.roster-section-top {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.roster-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-content: flex-start;
  margin-bottom: 0.65rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.roster-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.9rem;
  padding: 0.1rem 0.4rem;
  background: #f0eeea;
  border-radius: 3px;
  height: fit-content;
}

.roster-remove {
  background: none;
  border: none;
  font-size: 1rem;
  line-height: 1;
  color: #bbb;
  cursor: pointer;
  padding: 0 0.15rem;
  font-family: inherit;
}

.roster-remove:hover {
  color: #c0392b;
}

.add-name-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.add-name-input {
  flex: 1;
}

.bulk-add-section {
  margin-top: 0.5rem;
  flex-shrink: 0;
}

.bulk-names-input {
  width: 100%;
  min-height: 3.5rem;
  max-height: 8rem;
  padding: 0.45rem 0.6rem;
  font-family: 'Poppins', sans-serif;
  font-size: 0.95rem;
  border: 1.5px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  resize: vertical;
  margin-bottom: 0.35rem;
}

.bulk-names-input:focus {
  outline: none;
  border-color: #1a1a1a;
}

/* Disambiguation modal */
.disambig-card {
  width: 380px;
}

.disambig-item {
  padding: 0.75rem 0;
}

.disambig-item + .disambig-item {
  border-top: 1px solid #e0ddd8;
}

.disambig-context {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.disambig-raw {
  font-weight: 600;
  font-size: 1rem;
  color: #1a1a1a;
}

.disambig-meta {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #999;
}

.disambig-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-left: 0.1rem;
}

.disambig-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.disambig-option:hover {
  background: #f0eeea;
}

.disambig-option input[type="radio"] {
  accent-color: #1a1a1a;
  margin: 0;
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid #e0ddd8;
  display: flex;
  justify-content: flex-end;
}

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

/* Breakdown link in success message */
.breakdown-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}

.breakdown-link:hover {
  text-decoration-style: solid;
}

/* Breakdown modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: #faf9f6;
  border: 1.5px solid #e0ddd8;
  border-radius: 6px;
  width: 460px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e0ddd8;
}

.modal-title {
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #999;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  font-family: inherit;
}

.modal-close:hover {
  color: #1a1a1a;
}

.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-group {
  margin-bottom: 1rem;
}

.modal-group:last-child {
  margin-bottom: 0;
}

.modal-group-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.modal-group-label {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
}

.modal-group-count {
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a1a1a;
}

.modal-people {
  border-left: 2px solid #e0ddd8;
  padding-left: 0.75rem;
}

.modal-person {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.15rem 0;
  font-size: 0.95rem;
}

.modal-person-title {
  font-size: 0.85rem;
  color: #999;
  font-style: italic;
}

/* Person edit modal */
.person-edit-card {
  width: 1080px;
  height: 85vh;
}

.roster-name-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s;
}

.roster-name-link:hover {
  color: #555;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.pe-loading, .pe-empty {
  color: #999;
  font-style: italic;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.pe-section {
  margin-bottom: 1.25rem;
}

.pe-section:last-child {
  margin-bottom: 0;
}

.pe-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.pe-section-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
}

.pe-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a1a;
}

.pe-title-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.pe-title-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  font-family: 'Poppins', sans-serif;
  font-size: 0.95rem;
  border: 1.5px solid #e0ddd8;
  border-radius: 4px;
  background: #fff;
  color: #1a1a1a;
  transition: border-color 0.15s;
}

.pe-title-input:focus {
  outline: none;
  border-color: #1a1a1a;
}

.pe-save-btn {
  padding: 0.35rem 0.85rem;
  font-family: 'Poppins', sans-serif;
  font-size: 0.8rem;
  background: #fff;
  color: #1a1a1a;
  border: 1.5px solid #1a1a1a;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.pe-save-btn:hover {
  background: #1a1a1a;
  color: #faf9f6;
}

.pe-detail {
  font-size: 0.95rem;
  color: #555;
  padding: 0.2rem 0;
}

.pe-list {
  border-left: 2px solid #e0ddd8;
  padding-left: 0;
}

.pe-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  transition: background 0.1s;
}

.pe-item:hover {
  background: #f5f4f0;
}

.pe-item + .pe-item {
  border-top: 1px solid #f0eeea;
}

.pe-item-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.pe-item-desc {
  font-size: 0.9rem;
  font-weight: 500;
  color: #1a1a1a;
}

.pe-item-when {
  font-size: 0.8rem;
  color: #888;
}

.pe-item-editor {
  font-size: 0.8rem;
  color: #aaa;
  font-style: italic;
}

.pe-delete-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #ccc;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.pe-delete-btn:hover {
  color: #c0392b;
  background: #fdf0ee;
}

.pe-add-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pe-add-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.pe-add-row select {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border: 1.5px solid #e0ddd8;
  border-radius: 4px;
}

.pe-add-input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-family: 'Poppins', sans-serif;
  font-size: 0.85rem;
  border: 1.5px solid #e0ddd8;
  border-radius: 4px;
  background: #fff;
}

.pe-add-input:focus {
  outline: none;
  border-color: #1a1a1a;
}

.pe-add-sm {
  max-width: 5rem;
}

.pe-add-btn {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.pe-add-section-wrap {
  flex-shrink: 0;
  border-top: 1px solid #e0ddd8;
  padding-top: 0.75rem;
  margin-top: 0.75rem;
}

.pe-add-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.6rem;
  border-bottom: 1.5px solid #e0ddd8;
}

.pe-add-tab {
  padding: 0.4rem 1rem;
  font-family: 'Poppins', sans-serif;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  transition: color 0.15s, border-color 0.15s;
}

.pe-add-tab:hover {
  color: #555;
}

.pe-add-tab.active {
  color: #1a1a1a;
  border-bottom-color: #1a1a1a;
}

.pe-columns {
  display: flex;
  gap: 2rem;
  flex: 4;
  min-height: 0;
  overflow-y: auto;
}

.pe-col {
  flex: 1;
  min-width: 0;
}

.person-edit-card .modal-body {
  display: flex;
  flex-direction: column;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 1.5rem 1rem;
    overflow: auto;
  }

  .main-layout, .admin-layout {
    flex-direction: column;
    overflow: auto;
  }

  .main-left {
    width: 100%;
  }

  .preview-card {
    max-height: 50vh;
  }
}
