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

:root {
  --bg:          #f5f6f3;
  --sidebar-bg:  #eef1ec;
  --surface:     #ffffff;
  --surface2:    #eef1ec;
  --border:      #dadfd9;
  --border-lite: #e4e8e2;
  --accent:      #355e56;
  --accent-dim:  rgba(53,94,86,0.10);
  --accent2:     #6d4c5c;
  --accent2-dim: rgba(109,76,92,0.10);
  --success:     #4f7942;
  --success-dim: rgba(79,121,66,0.10);
  --error:       #a23b3b;
  --error-dim:   rgba(162,59,59,0.08);
  --warn:        #b8860b;
  --warn-dim:    rgba(184,134,11,0.10);
  --text:        #1c2321;
  --text-dim:    #5b6b66;
  --text-faint:  #838f89;
  --mono:        'IBM Plex Mono', monospace;
  --sans:        'IBM Plex Sans', sans-serif;
  --serif:       'Source Serif 4', serif;
  --sidebar-w:   220px;
  --radius:      10px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  height: 100vh;
}

/* ════════════════════════════
   SIDEBAR
════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-lite);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--border-lite);
}
.sidebar-logo {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0;
}
.sidebar-logo span { color: var(--accent); }
.sidebar-sub {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 3px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
}

.nav-section-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  text-transform: uppercase;
  padding: 18px 18px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  margin: 1px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
  user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(53,94,86,0.2);
  font-weight: 600;
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--border-lite);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ════════════════════════════
   MAIN CONTENT
════════════════════════════ */
.main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 36px 36px 64px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.main::-webkit-scrollbar { width: 5px; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* top accent line */
.main::before {
  content: '';
  display: block;
  height: 3px;
  background: var(--accent);
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  z-index: 10;
}

.page { display: none; max-width: 680px; }
.page.active { display: block; }

/* ── Page header ── */
.page-header { margin-bottom: 28px; margin-top: 4px; }
.page-tag {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 7px;
}
.page-title {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  line-height: 1.2;
}
.page-title span { color: var(--accent); }
.page-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
  font-weight: 300;
  line-height: 1.55;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 14px;
}
.card-title {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 16px;
}

/* ── Form elements ── */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
input[type=text], input[type=password] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 13px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder { color: var(--text-faint); }

/* ── Env selector ── */
.env-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.env-btn {
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}
.env-btn:hover:not(.active) { border-color: rgba(53,94,86,0.4); }
.env-btn.active { border-color: var(--accent); background: var(--accent-dim); }
.env-btn .env-name {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.env-btn.active .env-name { color: var(--accent); }
.env-btn .env-desc { display: block; font-size: 10px; color: var(--text-dim); margin-top: 2px; }

/* ── UUID list (lock page) ── */
.uuid-list { display: flex; flex-direction: column; gap: 8px; }
.uuid-row { display: flex; gap: 8px; align-items: center; animation: slideIn 0.15s ease; }
.uuid-row input { flex: 1; }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-5px); }
  to   { opacity: 1; transform: translateY(0); }
}
.btn-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: all 0.15s;
  font-family: var(--mono);
}
.btn-icon.remove:hover { border-color: var(--error); color: var(--error); background: var(--error-dim); }
.btn-icon:disabled { opacity: 0.25; pointer-events: none; }

.uuid-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 11px; }
.btn-add {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-add:hover:not(:disabled) { background: rgba(53,94,86,0.2); }
.btn-add:disabled { opacity: 0.3; pointer-events: none; }
.count-badge {
  font-family: var(--mono); font-size: 10px; color: var(--text-dim);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px;
}
.count-badge b { color: var(--text); }

/* ── Primary button ── */
.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  transition: opacity 0.15s, transform 0.1s;
  margin-bottom: 14px;
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-primary:active:not(:disabled) { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.38; pointer-events: none; }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error banner ── */
.app-error {
  padding: 10px 14px;
  background: var(--error-dim);
  border: 1px solid var(--error);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--error);
  margin-bottom: 12px;
  display: none;
}

/* ════════════════════════════
   LOCK RESULTS
════════════════════════════ */
.results-wrap { display: flex; flex-direction: column; gap: 8px; }
.results-label {
  font-family: var(--mono); font-size: 9px; font-weight: 600;
  letter-spacing: 0.14em; color: var(--text-faint); text-transform: uppercase;
}
.summary-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 9px; font-family: var(--mono); font-size: 11px;
}
.sdot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.sdot.ok  { background: var(--success); box-shadow: 0 0 5px var(--success); }
.sdot.bad { background: var(--error);   box-shadow: 0 0 5px var(--error); }
.result-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 12px 14px;
  display: flex; align-items: flex-start; gap: 10px;
  animation: slideIn 0.15s ease;
}
.result-item.success { border-color: var(--success); background: var(--success-dim); }
.result-item.error   { border-color: var(--error);   background: var(--error-dim); }
.rdot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }
.success .rdot { background: var(--success); }
.error   .rdot { background: var(--error); }
.rbody { flex: 1; min-width: 0; }
.ruuid { font-family: var(--mono); font-size: 11px; color: var(--text-dim); word-break: break-all; margin-bottom: 2px; }
.rstatus { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.success .rstatus { color: var(--success); }
.error   .rstatus { color: var(--error); }
.rdetail { font-size: 11px; color: var(--text-dim); margin-top: 2px; word-break: break-all; }
.rcode { font-family: var(--mono); font-size: 10px; background: rgba(28,35,33,0.07); border-radius: 3px; padding: 1px 5px; color: var(--text-dim); float: right; }

/* ════════════════════════════
   LEAVER HANDLER — UUID+DATE ROWS
════════════════════════════ */
.leaver-list { display: flex; flex-direction: column; gap: 10px; }
.leaver-row {
  display: grid;
  grid-template-columns: 1fr 160px 34px;
  gap: 8px;
  align-items: center;
  animation: slideIn 0.15s ease;
}
.leaver-row input[type=text] { font-size: 11px; }
.date-input-wrap { position: relative; }
.date-input-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 13px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.date-input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.date-input-wrap input.date-invalid {
  border-color: var(--error);
  box-shadow: 0 0 0 3px var(--error-dim);
}
.date-input-wrap input.date-valid {
  border-color: var(--success);
}
.leaver-col-labels {
  display: grid;
  grid-template-columns: 1fr 160px 34px;
  gap: 8px;
  margin-bottom: 8px;
}
.leaver-col-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
}

/* progress bar for leaver run */
.leaver-progress-wrap {
  margin-bottom: 12px;
  display: none;
}
.leaver-progress-wrap.visible { display: block; }
.leaver-progress-bar-bg {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.leaver-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}
.leaver-progress-text {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 5px;
  text-align: right;
}

/* ════════════════════════════
   PERSON METADATA DISPLAY
════════════════════════════ */
.person-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: slideIn 0.2s ease;
}
.person-hero {
  background: linear-gradient(135deg, var(--surface2) 0%, rgba(53,94,86,0.08) 100%);
  border-bottom: 1px solid var(--border);
  padding: 24px 24px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.person-avatar {
  width: 56px; height: 56px; flex-shrink: 0;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--accent);
}

.person-fullname { font-size: 20px; font-weight: 600; color: var(--text); line-height: 1.2; }
.person-uuid-small { font-family: var(--mono); font-size: 10px; color: var(--text-dim); margin-top: 4px; word-break: break-all; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 20px; border: 1px solid;
}
.badge-green { color: var(--success); border-color: rgba(79,121,66,0.3); background: var(--success-dim); }
.badge-blue  { color: var(--accent);  border-color: rgba(53,94,86,0.3);  background: var(--accent-dim); }
.badge-purple { color: var(--accent2); border-color: rgba(109,76,92,0.3);  background: var(--accent2-dim); }
.badge-warn  { color: var(--warn);    border-color: rgba(184,134,11,0.3);   background: var(--warn-dim); }
.badge-grey  { color: var(--text-dim); border-color: var(--border); background: transparent; }
.meta-section {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-lite);
}
.meta-section:last-child { border-bottom: none; }
.meta-section-title {
  font-family: var(--mono); font-size: 9px; font-weight: 600;
  letter-spacing: 0.14em; color: var(--text-faint); text-transform: uppercase;
  margin-bottom: 14px;
}
.kv-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.kv-key { font-family: var(--mono); font-size: 11px; color: var(--text-dim); padding-top: 1px; }
.kv-val { font-size: 13px; color: var(--text); font-weight: 400; word-break: break-word; }
.kv-val.mono { font-family: var(--mono); font-size: 11px; }
.affil-list { display: flex; flex-direction: column; gap: 8px; }
.affil-item {
  background: var(--bg); border: 1px solid var(--border-lite);
  border-radius: 7px; padding: 10px 13px;
}
.affil-name { font-size: 13px; color: var(--text); font-weight: 500; }
.affil-meta { font-family: var(--mono); font-size: 10px; color: var(--text-dim); margin-top: 3px; }
.affil-period { font-family: var(--mono); font-size: 10px; color: var(--text-faint); margin-top: 2px; }
.name-tag {
  display: inline-block;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; margin: 3px 3px 0 0;
  font-size: 12px; color: var(--text);
}
.name-tag-type { font-family: var(--mono); font-size: 9px; color: var(--text-faint); display: block; margin-bottom: 1px; }
.id-list { display: flex; flex-direction: column; gap: 6px; }
.id-row { display: flex; align-items: center; gap: 10px; }
.id-source { font-family: var(--mono); font-size: 10px; color: var(--text-dim); min-width: 130px; }
.id-value { font-family: var(--mono); font-size: 11px; color: var(--text); word-break: break-all; }
.raw-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10px; color: var(--text-dim);
  cursor: pointer; padding: 5px 0; border: none; background: none;
  transition: color 0.15s;
}
.raw-toggle:hover { color: var(--accent); }
.raw-block {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; padding: 14px;
  font-family: var(--mono); font-size: 10px; color: var(--text-dim);
  white-space: pre-wrap; word-break: break-all;
  max-height: 320px; overflow-y: auto;
  margin-top: 10px; display: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  line-height: 1.6;
}
.raw-block.open { display: block; }

/* ── Author Reorder list ── */
.reorder-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.reorder-list::-webkit-scrollbar { width: 4px; }
.reorder-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.reorder-author-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  cursor: grab;
}
.reorder-author-item:active { cursor: grabbing; }
.reorder-author-item.draggable-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.reorder-author-item.dragging {
  opacity: 0.4;
}
.reorder-author-item.locked {
  cursor: default;
  opacity: 0.7;
  border-style: dashed;
}
.reorder-author-item.unnamed {
  border-color: rgba(109,76,92,0.35);
  background: var(--accent2-dim);
}
.reorder-author-item.locked.unnamed {
  opacity: 0.65;
}

.reorder-drag-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
  opacity: 0.35;
}
.reorder-drag-handle span {
  display: block;
  width: 14px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}
.reorder-author-item.locked .reorder-drag-handle { visibility: hidden; }

.reorder-pos {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  min-width: 20px;
  text-align: right;
  flex-shrink: 0;
}

.reorder-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.reorder-dot.named   { background: var(--accent); }
.reorder-dot.unnamed { background: var(--accent2); }

.reorder-author-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reorder-author-name .reorder-name-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 1px;
}

.reorder-lock-badge {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ── Toggle switch ── */
.reorder-toggle-wrap {
  width: 40px; height: 22px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 11px;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
.reorder-toggle-wrap.on {
  background: var(--accent);
  border-color: var(--accent);
}
.reorder-toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.reorder-toggle-wrap.on .reorder-toggle-knob {
  transform: translateX(18px);
  background: #fff;
}

/* ── File Download ── */
.files-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.files-actions .btn-primary { width: auto; padding-left: 18px; padding-right: 18px; margin-bottom: 0; }
.files-hint { font-size: 11px; color: var(--text-dim); }
.files-list { display: flex; flex-direction: column; gap: 6px; }
.files-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 12px;
}
.files-item.done  { border-color: var(--success); background: var(--success-dim); }
.files-item.fail  { border-color: var(--error);   background: var(--error-dim); }
.files-name {
  max-width: 100%; text-align: left; background: none; border: none; padding: 0;
  font: inherit; font-size: 13px; color: var(--accent); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; word-break: break-all;
}
.files-name:hover { opacity: 0.8; }
.files-name:disabled { cursor: progress; opacity: 0.6; }
.files-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.files-meta { font-family: var(--mono); font-size: 10px; color: var(--text-dim); }
.files-status { font-family: var(--mono); font-size: 10px; }
.files-item.done .files-status { color: var(--success); }
.files-item.fail .files-status { color: var(--error); }
