/* ===== CSS Variables — Notion Light Theme ===== */
:root {
  /* Background Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #f7f6f3;
  --bg-tertiary: #fbfbfa;
  --bg-hover: rgba(55, 53, 47, 0.04);
  --bg-table-alt: #f7f6f3;
  --bg-input: #ffffff;

  /* Accent Colors */
  --accent-blue: #2eaadc;
  --accent-blue-hover: #2496c4;
  --accent-red: #eb5757;
  --accent-red-bright: #d44;

  /* Text */
  --text-primary: #37352f;
  --text-secondary: #787774;
  --text-muted: #9b9a97;

  /* Borders */
  --border: #e9e9e7;
  --border-dark: #dfdfde;

  /* Geometry */
  --radius: 4px;
  --radius-sm: 3px;

  /* Shadows */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);

  /* Backward-compatible aliases (referenced in app.js inline styles) */
  --accent-gold: #2eaadc;
  --accent-gold-bright: #37352f;
  --accent-gold-dim: #9b9a97;
  --bg-dark: #f7f6f3;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f7f6f3;
  --border-gold: #e9e9e7;
  --border-ornate: #dfdfde;
  --shadow-gold: 0 1px 3px rgba(0, 0, 0, 0.08);
  --border-width-ornate: 1px;
  --corner-size: 0px;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg-primary:    #191919;
  --bg-secondary:  #2f2f2f;
  --bg-tertiary:   #252525;
  --bg-hover:      rgba(255, 255, 255, 0.055);
  --bg-table-alt:  #2f2f2f;
  --bg-input:      #252525;

  --text-primary:   #e8e6e1;
  --text-secondary: #a0a09d;
  --text-muted:     #787774;

  --border:      #373737;
  --border-dark: #444444;

  --shadow:    0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);

  /* Backward-compatible aliases */
  --accent-gold-bright: #e8e6e1;
  --accent-gold-dim:    #787774;
  --bg-dark:            #2f2f2f;
  --bg-panel:           #191919;
  --bg-panel-alt:       #2f2f2f;
  --border-gold:        #373737;
  --border-ornate:      #444444;
  --shadow-gold:        0 1px 3px rgba(0, 0, 0, 0.3);
}


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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header__row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 12px;
}

.header__title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0;
}

.btn-settings {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 2.0rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
}
.btn-settings:hover {
  color: var(--text-primary);
}

.btn-state {
  font-size: 0.75rem;
  padding: 4px 10px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-state:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ===== 2-Tier Tabs ===== */
.tabs-top {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 0;
}

.tab-top {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-top:hover { color: var(--text-primary); }
.tab-top.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-blue);
}

.tabs-sub {
  display: flex;
  justify-content: center;
  gap: 4px;
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.tab-sub {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color 0.15s, background 0.15s;
}
.tab-sub:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.tab-sub.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
  font-weight: 600;
}

.tab-sub-divider {
  width: 1px;
  align-self: stretch;
  margin: 6px 8px;
  background: var(--border-dark);
}

/* Legacy tab classes (kept for compatibility) */
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
  font-weight: 600;
}

/* ===== Main ===== */
.main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Panel System (simplified) ===== */
.filter-bar,
.affair-info,
.modal {
  position: relative;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ===== Internal Affairs Selector ===== */
.affair-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.affair-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.affair-btn:hover {
  border-color: var(--border-dark);
  background: var(--bg-hover);
  color: var(--text-primary);
}
.affair-btn.active {
  background: rgba(46, 170, 220, 0.08);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  font-weight: 700;
}

/* ===== Affair Info ===== */
.affair-info {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.affair-info strong { color: var(--text-primary); font-weight: 600; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 32px;
  max-width: 550px;
  margin-left: auto;
  margin-right: auto;
  border-radius: 8px;
  padding: 20px 18px;
  background: var(--bg-primary);
}

.search-range-bar {
  flex-direction: column;
  max-width: 700px;
  gap: 12px;
  margin-bottom: 12px;
}
.search-range-bar .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
}
.search-range-bar .filter-group--wide {
  flex: 0 0 auto;
  width: 320px;
}
.search-toggle-row {
  justify-content: center;
  gap: 20px;
}
.search-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.search-toggle input[type="checkbox"] {
  accent-color: var(--accent-blue);
  cursor: pointer;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}
.range-inputs input[type="number"] {
  width: 70px;
  min-width: 0;
}
.range-sep {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group--wide { flex: 1; min-width: 200px; }

.filter-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.filter-group select,
.filter-group input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  min-width: 100px;
  text-align: center;
}

.filter-group input[type="number"] { width: 80px; }
.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(46, 170, 220, 0.15);
}

.btn-reset {
  background: transparent;
  border: 1px solid var(--border-dark);
  color: var(--accent-red);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  align-self: flex-end;
}
.btn-reset:hover {
  background: rgba(235, 87, 87, 0.06);
  border-color: var(--accent-red);
}

/* ===== Result Count ===== */
.result-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}

.result-count-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.btn-reset-inline {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 2px 8px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-reset-inline:hover {
  background: var(--bg-hover);
  color: var(--accent-red);
}

/* ===== Confirm Modal ===== */
.modal.confirm-modal {
  width: 400px;
  max-width: 400px;
  min-width: 0;
  height: 150px;
}
.confirm-modal .modal__content {
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.confirm-message {
  text-align: center;
  font-size: 1.05rem;
  color: var(--text-primary);
  padding: 12px 6px 14px;
}

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 0 6px 12px;
}

.btn-confirm-cancel,
.btn-confirm-ok {
  width: 90px;
  height: 34px;
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-confirm-cancel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-dark);
  color: var(--text-secondary);
}
.btn-confirm-cancel:hover {
  background: var(--bg-hover);
}

.btn-confirm-ok {
  background: var(--accent-red);
  border: none;
  color: #fff;
}
.btn-confirm-ok:hover {
  opacity: 0.85;
}

/* ===== Data Table ===== */
.table-wrap { overflow-x: auto; }

#tab-roster .table-wrap { overflow: visible; }

.roster-scroll-area {
  overflow-x: auto;
  scrollbar-width: none;
}
#tab-roster .roster-add,
#tab-roster .result-count-row {
  position: sticky;
  left: 0;
  width: calc(min(100vw, 1400px) - 48px);
  max-width: 100%;
  background: var(--bg-secondary);
  z-index: 4;
}
#tab-roster .roster-add {
  z-index: 5;
}
.roster-scroll-area::-webkit-scrollbar {
  display: none;
}

.data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  border-left: 1px solid var(--border-dark);
  border-right: 1px solid var(--border-dark);
}

.data-table th {
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: center;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-dark);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.data-table th.sortable:hover { color: var(--text-primary); }

.data-table th.sort-asc::after { content: ' ▲'; color: var(--accent-blue); }
.data-table th.sort-desc::after { content: ' ▼'; color: var(--accent-blue); }

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
}

.data-table tbody tr:nth-child(even) { background: var(--bg-table-alt); }
.data-table tbody tr:hover { background: var(--bg-hover); }

/* ===== Roster Table — Sticky First Column ===== */
#roster-table tbody td { background: var(--bg-secondary); }
#roster-table tbody td:first-child { background: var(--bg-primary); }
#roster-table tbody tr:hover td {
  background: linear-gradient(var(--bg-hover), var(--bg-hover)), var(--bg-secondary);
}
#roster-table tbody tr:hover td:first-child {
  background: linear-gradient(var(--bg-hover), var(--bg-hover)), var(--bg-primary);
}

#roster-table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 1px solid var(--border-dark);
}
#roster-table tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  border-right: 1px solid var(--border-dark);
}

/* ===== Search Table — Sticky First Column (mirror of roster) ===== */
#search-table tbody td { background: var(--bg-secondary); }
#search-table tbody td:nth-child(2) { background: var(--bg-primary); }
#search-table tbody tr:hover td {
  background: linear-gradient(var(--bg-hover), var(--bg-hover)), var(--bg-secondary);
}
#search-table tbody tr:hover td:nth-child(2) {
  background: linear-gradient(var(--bg-hover), var(--bg-hover)), var(--bg-primary);
}
#search-table thead th:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 1px solid var(--border-dark);
}
#search-table tbody td:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 1;
  border-right: 1px solid var(--border-dark);
}

.search-scroll-area {
  overflow-x: auto;
  scrollbar-width: none;
}
.search-scroll-area::-webkit-scrollbar {
  display: none;
}
#tab-search .table-wrap { overflow: visible; }
#tab-search .result-count-row {
  position: sticky;
  left: 0;
  width: calc(min(100vw, 1400px) - 48px);
  max-width: 100%;
  background: var(--bg-secondary);
  z-index: 4;
}
#tab-search .search-range-bar {
  position: sticky;
  left: 0;
  z-index: 4;
  background: #ececec;
  border: 1px solid var(--border-dark);
}
[data-theme="dark"] #tab-search .search-range-bar {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
}

.col-group-start {
  border-left: 1px solid var(--border-dark);
}

/* ===== Header Filter Search ===== */
.th-filter {
  position: relative;
}
.th-filter__label {
  display: inline;
  margin-right: 10px;
}
.th-filter__search {
  position: relative;
  display: inline-block;
}
.th-filter__input {
  width: 75px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 400;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  text-align: center;
}
.th-filter__input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

/* Column widths */
.col-rank { width: 50px; text-align: center; }
.col-id { width: 50px; text-align: center; }
.col-name { width: 100px; }
.col-stat { width: 60px; text-align: center; }
.col-total { width: 60px; text-align: center; }
.col-score { width: 160px; }
.col-traits { width: 200px; }
.col-traits-sm { width: 180px; }
.col-location { width: 80px; }
.col-corps { width: 80px; }

/* ===== Clickable Name ===== */
.officer-name {
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
  font-weight: 500;
}
.officer-name:hover {
  text-decoration-color: var(--text-primary);
  color: var(--accent-blue);
}

/* ===== Score Bar ===== */
.score-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-bar {
  flex: 1;
  height: 18px;
  background: var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-width: 60px;
  border: none;
}

.score-bar__fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: width 0.3s;
}

.score-value {
  min-width: 32px;
  text-align: right;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Score colors — Notion palette */
.score--low .score-bar__fill { background: #eb5757; }
.score--mid .score-bar__fill { background: #f2994a; }
.score--good .score-bar__fill { background: #27ae60; }
.score--high .score-bar__fill { background: #2eaadc; }
.score--exceptional .score-bar__fill {
  background: linear-gradient(90deg, #2eaadc, #6fcf97);
}
.score--exceptional .score-value {
  color: var(--accent-blue);
  font-weight: 700;
}

/* Stat colors in table */
.stat-high { color: var(--accent-blue); font-weight: 700; }
.stat-mid { color: var(--text-primary); }
.stat-low { color: var(--text-muted); }

.stat-sum-high { color: #2e7d32; font-weight: 700; }
.stat-sum-mid { color: var(--text-primary); }
.stat-sum-low { color: var(--text-muted); }

[data-theme="dark"] .stat-sum-high { color: #66bb6a; }

/* ===== Trait Badges ===== */
.trait-badges { display: flex; flex-wrap: nowrap; gap: 4px; justify-content: center; }

.trait-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.trait-badge--key {
  background: #d3e5ef;
  color: #2874a6;
  border: none;
}

.trait-badge--support {
  background: #d4edda;
  color: #388e3c;
  border: none;
}

.trait-badge--normal {
  background: #f1f1ef;
  color: var(--text-secondary);
  border: none;
}

.trait-badge--금색 {
  background: #fef3cd;
  color: #856404;
}
.trait-badge--청색 {
  background: #d3e5ef;
  color: #2874a6;
}
.trait-badge--적색 {
  background: #f8d7da;
  color: #721c24;
}

[data-theme="dark"] .trait-badge--금색 {
  background: #5c4a1e;
  color: #ffd95a;
}
[data-theme="dark"] .trait-badge--청색 {
  background: #1a3a4a;
  color: #7ec8e3;
}
[data-theme="dark"] .trait-badge--적색 {
  background: #4a1c1e;
  color: #f5a3a8;
}

.trait-badge[data-tooltip] {
  cursor: help;
}

.trait-badge--active {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

/* ===== Filter Count ===== */
.filter-count {
  color: var(--accent-blue);
}

/* ===== Filter Tag ===== */
.filter-tags {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.filter-tag--금색 {
  background: #fef3cd;
  color: #856404;
}
.filter-tag--청색 {
  background: #d3e5ef;
  color: #2874a6;
}
.filter-tag--적색 {
  background: #f8d7da;
  color: #721c24;
}
[data-theme="dark"] .filter-tag--금색 {
  background: #5c4a1e;
  color: #ffd95a;
}
[data-theme="dark"] .filter-tag--청색 {
  background: #1a3a4a;
  color: #7ec8e3;
}
[data-theme="dark"] .filter-tag--적색 {
  background: #4a1c1e;
  color: #f5a3a8;
}
.filter-tag__close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 2px;
  opacity: 0.7;
}
.filter-tag__close:hover {
  opacity: 1;
}

.filter-tag--formation {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-dark);
}

/* ===== Formation Badges ===== */
.formation-badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: center;
}

.formation-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  background: #c0c0c0;
  color: #3a3a3a;
  border: none;
  cursor: help;
}
.formation-badge--siege {
  background: #e8e8e8;
  color: #555;
}
.formation-badge--etc {
  background: #999;
  color: #2a2a2a;
}

[data-theme="dark"] .formation-badge {
  background: #454545;
  color: #bbb;
}
[data-theme="dark"] .formation-badge--siege {
  background: #606060;
  color: #ddd;
}
[data-theme="dark"] .formation-badge--etc {
  background: #333;
  color: #999;
}

.formation-badge--active {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

/* ===== Tooltip Table ===== */
.tooltip-table {
  border-collapse: collapse;
}
.tooltip-table td {
  padding: 1px 6px;
  font-size: 0.75rem;
  line-height: 1.4;
}
.tooltip-table__label {
  color: inherit;
  opacity: 0.7;
  text-align: right;
}
.tooltip-table__value {
  font-weight: 700;
  text-align: left;
}

/* ===== Tactic Badges ===== */
.tactic-badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
}

.tactic-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  background: #d5d5d5;
  color: #444;
  border: none;
  cursor: help;
  position: relative;
}
.tactic-badge--unique {
  background: #f8d0e0;
  color: #8b2252;
}
[data-theme="dark"] .tactic-badge {
  background: #505050;
  color: #ccc;
}
[data-theme="dark"] .tactic-badge--unique {
  background: #5c2040;
  color: #f0a0c0;
}

.tactic-badge--active {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.tactic-badge--added {
  background: #e0d4f5;
  color: #5b3a8c;
}
[data-theme="dark"] .tactic-badge--added {
  background: #3d2a5c;
  color: #c4a8e8;
}
.tactic-remove-btn {
  background: none;
  border: none;
  color: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 2px;
  opacity: 0.5;
}
.tactic-remove-btn:hover {
  opacity: 1;
  color: var(--accent-red);
}

.tactic-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 0.8rem;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-dark);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tactic-add-btn:hover {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.tactic-add-popup {
  display: none;
  position: fixed;
  z-index: 300;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  width: 160px;
}
.tactic-add-popup.show {
  display: block;
}

/* Tactic Filter Tags */
.filter-tag--tactic {
  background: #d5d5d5;
  color: #444;
}
.filter-tag--tactic-unique {
  background: #f8d0e0;
  color: #8b2252;
}
[data-theme="dark"] .filter-tag--tactic {
  background: #505050;
  color: #ccc;
}
[data-theme="dark"] .filter-tag--tactic-unique {
  background: #5c2040;
  color: #f0a0c0;
}

/* ===== Relation Badges ===== */
.relation-badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: center;
}

.relation-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--accent-blue);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}
.relation-badge:hover {
  background: var(--bg-hover);
}
.relation-badge--active {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.relation-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-dark);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.relation-more-btn:hover {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.relation-modal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
  justify-content: center;
}

.filter-tag--relation {
  background: var(--bg-secondary);
  color: var(--accent-blue);
  border: 1px solid var(--border-dark);
}

.tooltip {
  display: none;
  position: fixed;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: 0.75rem;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: var(--radius);
  white-space: nowrap;
  line-height: 1.4;
  z-index: 400;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.tooltip.show {
  display: block;
}

/* ===== Load More Button ===== */
.btn-load-more {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-load-more:hover {
  border-color: var(--border-dark);
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ===== Compare Tab ===== */
.compare-selector {
  margin-bottom: 20px;
}

.compare-search-wrap {
  position: relative;
  width: 100%;
  max-width: 550px;
  margin-bottom: 0;
}

.compare-search-wrap label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.compare-search-wrap input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: var(--radius);
  text-align: center;
}

.compare-search-wrap input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(46, 170, 220, 0.15);
}

/* ===== Autocomplete ===== */
.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-lg);
}

.autocomplete-list.show { display: block; }

.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}

.autocomplete-item:hover {
  background: var(--bg-hover);
}

.autocomplete-item__stats {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== Compare Chips ===== */
.compare-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compare-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.compare-chip__remove {
  background: none;
  border: none;
  color: var(--accent-red);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.compare-chip__remove:hover { color: var(--accent-red-bright); }

/* ===== Compare Grid ===== */
.compare-grid { overflow-x: auto; }

.compare-placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-size: 1rem;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
}

.compare-table th,
.compare-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-size: 0.9rem;
}

.compare-table th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
}

.compare-table th:first-child,
.compare-table td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--text-secondary);
  width: 100px;
}

.compare-table td.best-value {
  color: var(--accent-blue);
  font-weight: 700;
}

.compare-bar {
  display: inline-block;
  height: 14px;
  border-radius: var(--radius-sm);
  vertical-align: middle;
  margin-right: 6px;
}

.compare-section-header {
  background: var(--bg-secondary);
}

.compare-section-header td {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-dark);
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-primary);
  border: none;
  border-radius: 6px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 2;
}
.modal__close:hover { color: var(--accent-red); }

.modal__content { padding: 24px; }

/* Modal inner styles */
.modal-header {
  margin: -24px -24px 16px -24px;
  padding: 20px 24px 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.modal-header h2 {
  font-size: 1.3rem;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: 0;
  font-weight: 700;
}

.modal-header__meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.modal-stat {
  text-align: center;
  padding: 8px 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.modal-stat__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.modal-stat__value {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-section {
  margin-bottom: 14px;
}

.modal-section__title {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 700;
  margin-bottom: 8px;
  padding-left: 10px;
  border-left: 3px solid var(--accent-blue);
}

.modal-affair-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.modal-affair-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

.modal-affair-item__icon { font-size: 1rem; }

.modal-affair-item__name {
  color: var(--text-secondary);
  min-width: 35px;
}

.modal-affair-item__bar {
  flex: 1;
  height: 12px;
  background: var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: none;
}

.modal-affair-item__bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
}

.modal-affair-item__score {
  min-width: 28px;
  text-align: right;
  font-weight: 700;
  font-size: 0.8rem;
}

.modal-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* ===== Settings Modal ===== */
.settings-modal { max-width: 220px; }
.settings-modal .modal-header h2 { text-align: center; }

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
}
.settings-item:hover {
  background: var(--bg-hover);
}

/* ===== Roster Tab ===== */
.roster-add {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.cell-row-remove {
  width: 0;
  padding: 0 !important;
  border-bottom: none !important;
  position: relative;
  overflow: visible;
}

.row-remove {
  position: absolute;
  right: -30px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--accent-red);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}
tr:hover .row-remove {
  opacity: 1;
}
.row-remove:hover {
  color: var(--accent-red-bright);
  background: rgba(235, 87, 87, 0.06);
}

@keyframes flash-success {
  0%   { border-color: #4caf50; box-shadow: 0 0 12px rgba(76, 175, 80, 0.6); background: rgba(76, 175, 80, 0.08); }
  100% { border-color: var(--border); box-shadow: none; background: transparent; }
}

@keyframes flash-fail {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

#roster-input.flash-success {
  animation: flash-success 0.4s ease-out;
}

#roster-input.flash-fail {
  animation: flash-fail 0.35s ease-out;
  border-color: #e53935;
  box-shadow: 0 0 12px rgba(229, 57, 53, 0.5);
  background: rgba(229, 57, 53, 0.08);
}

.col-stat-sm {
  width: 45px;
  text-align: center;
}

.autocomplete-item.active {
  background: var(--bg-secondary);
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: #d4d4d2;
  border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
  background: #b4b4b2;
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: #d4d4d2 var(--bg-secondary);
}

/* ===== Cities Tab ===== */
.cities-add {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

#cities-table {
  width: auto;
  min-width: 0;
  margin: 0 auto;
}

.city-move-up,
.city-move-down {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  transition: all 0.15s;
  margin: 0 2px;
}
.city-move-up:hover,
.city-move-down:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
.city-move-up:disabled,
.city-move-down:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ===== Corps Management ===== */
.corps-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 44px;
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
}

.corps-card__header {
  height: 135px;
  padding: 20px 16px 15px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.corps-card--점령 .corps-card__header { background: rgba(235, 87, 87, 0.3); }
.corps-card--전투 .corps-card__header { background: rgba(242, 153, 74, 0.3); }
.corps-card--방어 .corps-card__header { background: rgba(46, 170, 220, 0.3); }

[data-theme="dark"] .corps-card--점령 .corps-card__header { background: rgba(235, 87, 87, 0.15); }
[data-theme="dark"] .corps-card--전투 .corps-card__header { background: rgba(242, 153, 74, 0.15); }
[data-theme="dark"] .corps-card--방어 .corps-card__header { background: rgba(46, 170, 220, 0.15); }

.corps-card__header-row1 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  height: 50px;
  margin-bottom: 15px;
}

.corps-card__title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.corps-card__title-group .corps-card__delete {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.corps-card__header:hover .corps-card__delete {
  opacity: 1;
}

.corps-card__header-row2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 35px;
}
.corps-card__header-row2 > *:not(:last-child)::after {
  content: '';
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border-dark);
  margin-left: 16px;
  vertical-align: middle;
}

.corps-card__name {
  font-size: 1.4rem;
  color: var(--text-primary);
  margin: 0;
  font-weight: 700;
}

.corps-card__count {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  height: 28px;
  line-height: 28px;
}

.corps-card__delete {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--accent-red);
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.corps-card__delete:hover {
  color: var(--accent-red-bright);
  background: rgba(235, 87, 87, 0.06);
}

.role-badge {
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: var(--radius);
  font-weight: 700;
  border: none;
}
.role-badge--점령 {
  background: #fde2e2;
  color: #c43030;
}
.role-badge--전투 {
  background: #fdecc8;
  color: #9a6700;
}
.role-badge--방어 {
  background: #d3e5ef;
  color: #2874a6;
}

/* Corps city selector */
.corps-city-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}
.corps-city-field {
  display: flex;
}
.corps-city-field label {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.corps-city-field select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0 8px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
}
.corps-city-arrow {
  font-size: 1.1rem;
  color: var(--text-muted);
  padding-bottom: 4px;
  font-weight: 700;
}

.corps-card__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px;
}

.corps-search-wrap {
  max-width: 300px;
}

.corps-member-autocomplete .autocomplete-item > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.corps-member-autocomplete .autocomplete-item__stats {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Corps member list — horizontal layout */
.corps-card__member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.corps-card__member-list:empty {
  min-height: 40px;
  width: 100%;
}

.corps-member {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 220px;
  white-space: nowrap;
}
.corps-member .officer-name {
  width: 48px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.corps-member__stats {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 25px);
  white-space: nowrap;
}
.corps-member__stats > span {
  text-align: center;
}

.corps-member__remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  transition: color 0.15s;
}
.corps-member__remove:hover {
  color: var(--accent-red);
}


/* Rank add input row */
.corps-rank-add {
  display: flex;
  align-items: center;
  gap: 8px;
}
.corps-card__body > .corps-rank-add {
  align-self: center;
  margin-top: 8px;
}
.corps-rank-input {
  flex: 1;
  max-width: 200px;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0 10px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
}
.corps-rank-add-btn {
  background: var(--accent-blue);
  border: 1px solid var(--accent-blue);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0 12px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.corps-rank-add-btn:hover {
  background: var(--accent-blue-hover);
}

/* Rank section */
.corps-rank {
  display: flex;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
}
.corps-card--점령 .corps-rank { background: rgba(235, 87, 87, 0.12); }
.corps-card--전투 .corps-rank { background: rgba(242, 153, 74, 0.12); }
.corps-card--방어 .corps-rank { background: rgba(46, 170, 220, 0.12); }

[data-theme="dark"] .corps-card--점령 .corps-rank { background: rgba(235, 87, 87, 0.08); }
[data-theme="dark"] .corps-card--전투 .corps-rank { background: rgba(242, 153, 74, 0.08); }
[data-theme="dark"] .corps-card--방어 .corps-rank { background: rgba(46, 170, 220, 0.08); }
.corps-rank__delete {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--accent-red);
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.corps-rank:hover .corps-rank__delete {
  opacity: 1;
}
.corps-rank__delete:hover {
  color: var(--accent-red-bright);
  background: rgba(235, 87, 87, 0.06);
}

.corps-rank__left {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding-right: 16px;
}
.corps-rank__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.corps-rank__name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}
.corps-rank__count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.corps-rank__right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Rank body — horizontal layout with search at right */
.corps-rank__body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}
.corps-rank__body .corps-card__member-list {
  flex: 1;
  min-width: 200px;
}
.corps-rank__body .corps-search-wrap {
  margin-left: auto;
  flex-shrink: 0;
}

/* Drag handle */
.corps-member__drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1rem;
  user-select: none;
  touch-action: none;
  padding: 0 2px;
  flex-shrink: 0;
  line-height: 1;
}
.corps-member__drag-handle:active {
  cursor: grabbing;
}

/* SortableJS state classes */
.sortable-ghost {
  opacity: 0.4;
  background: var(--bg-hover);
}
.sortable-chosen {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.sortable-drag {
  opacity: 0.9;
}

/* Stat highlighting for corps members */
.stat--high { color: #eb5757; font-weight: 700; }
.stat--mid  { color: #f2994a; font-weight: 600; }

.btn-add {
  background: var(--accent-blue);
  border: 1px solid var(--accent-blue);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  align-self: flex-end;
}
.btn-add:hover {
  background: var(--accent-blue-hover);
}

/* ===== Admin Tab ===== */
.admin-config {
  margin-bottom: 24px;
}

.admin-section,
#admin-city-slots {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 30px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
#admin-city-slots:empty {
  display: none;
}
#admin-city-slots .admin-section {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin-bottom: 0;
}

/* ===== Collapsible Sections ===== */
.collapsible-section .admin-section__title {
  cursor: pointer;
  user-select: none;
}

.collapsible-section .admin-section__title::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid var(--text-secondary);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-right: 4px;
}

.collapsible-section.collapsed .admin-section__title::before {
  transform: rotate(-90deg);
}

.collapsible-section__body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease;
}

.collapsible-section.collapsed .collapsible-section__body {
  grid-template-rows: 0fr;
}
.collapsible-section.collapsed {
  padding-bottom: 0;
}
.collapsible-section.collapsed > .admin-section__title {
  margin-bottom: 0;
  border-bottom: none;
  border-radius: 8px;
}
#admin-city-slots:has(.collapsible-section.collapsed) {
  padding-bottom: 0;
}
#admin-city-slots:has(.collapsible-section.collapsed) .admin-section__title {
  margin-bottom: 0;
  border-bottom: none;
  border-radius: 8px;
}

.collapsible-section__inner {
  overflow: hidden;
}

/* ===== Trade Section Layout ===== */
.admin-trade-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.trade-nation-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.trade-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.trade-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.trade-checkbox input[type="checkbox"] {
  accent-color: var(--accent-blue);
  width: 16px;
  height: 16px;
}

/* 수동 교역 배정 */
#trade-manual-config:empty { display: none; }

.trade-manual {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.trade-manual:last-child { border-bottom: none; }

.trade-manual__label {
  min-width: 56px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding-top: 5px;
  flex-shrink: 0;
}

.trade-manual__body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.trade-manual__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.82rem;
  color: var(--text-primary);
}

.trade-manual__chip-remove {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1;
  padding: 0 2px;
}

.trade-manual__chip-remove:hover {
  color: var(--text-primary);
}

.trade-manual__search {
  position: relative;
  flex-shrink: 0;
}

.trade-manual__input {
  width: 120px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.82rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
}

.trade-manual__input:focus {
  border-color: var(--accent-blue);
}

.trade-manual-autocomplete {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  width: 220px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 100;
}

.trade-manual-autocomplete.show { display: block; }

.admin-section__title {
  background: var(--bg-secondary);
  font-size: 1.1rem;
  color: var(--text-primary);
  font-weight: 700;
  margin: -20px -30px 20px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
}
#assignment-config-section > .admin-section__title {
  background: rgba(155, 81, 224, 0.18);
}
[data-theme="dark"] #assignment-config-section > .admin-section__title {
  background: rgba(155, 81, 224, 0.12);
}
#admin-city-slots > .admin-section > .admin-section__title {
  background: rgba(224, 81, 155, 0.18);
}
[data-theme="dark"] #admin-city-slots > .admin-section > .admin-section__title {
  background: rgba(224, 81, 155, 0.12);
}
.admin-section__title .btn-reset {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.admin-group {
  margin-bottom: 12px;
}

.admin-group__title {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0 0 6px 0;
}

.admin-city-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--accent-blue);
}

.admin-city-card__title {
  color: var(--text-primary);
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 700;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.admin-city-card__province {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.admin-role {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.admin-role__label {
  min-width: 120px;
  color: var(--text-muted);
  font-weight: 500;
}

.admin-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 10px;
  font-size: 0.85rem;
}

.admin-chip__stat {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Trait tags for admin officer chips */
.trait-tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 3px;
  font-weight: 500;
  margin-left: 4px;
  vertical-align: middle;
}
.trait-tag--모집 { background: #fde2e2; color: #c43030; }
.trait-tag--교련 { background: #d3e5ef; color: #2874a6; }
.trait-tag--특사 { background: #e8deee; color: #6b3fa0; }

.text-muted {
  color: var(--text-muted);
}

/* Admin city slots */
.admin-city-slots-table {
  max-width: 420px;
}

.city-slot-input {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 4px;
  font-size: 0.85rem;
}

.city-slot-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 2px 5px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-left: 4px;
}
.city-slot-reset:hover {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .corps-card {
    max-width: 100%;
  }
  .corps-card__body {
    padding: 16px;
  }
  .corps-card__header-row2 {
    flex-wrap: wrap;
    height: auto;
    min-height: 35px;
    padding: 8px;
  }
}

@media (max-width: 768px) {
  .main { padding: 12px; }
  #tab-roster .roster-add,
  #tab-roster .result-count-row,
  #tab-search .search-range-bar,
  #tab-search .result-count-row {
    width: calc(100vw - 24px);
  }
  .affair-selector { gap: 6px; }
  .affair-btn { padding: 8px 12px; font-size: 0.85rem; }
  .filter-bar { flex-direction: column; gap: 8px; }
  .filter-group--wide { min-width: 0; }
  .corps-create.filter-bar {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 12px;
  }
  .corps-create .filter-group--wide { flex: 1; min-width: 0; }
  .corps-create #corps-name-input { width: 100%; min-width: 0; }
  .corps-create #corps-role-select { min-width: 0; }
  .corps-create #corps-add-btn { white-space: nowrap; flex-shrink: 0; }
  .modal-stats { grid-template-columns: repeat(3, 1fr); }
  .modal-affair-list { grid-template-columns: 1fr; }
  .header__title { letter-spacing: 0; }

  /* 2-tier tabs responsive */
  .tabs-top, .tabs-sub {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-top { padding: 6px 14px; font-size: 0.85rem; }
  .tab-sub { padding: 5px 10px; font-size: 0.8rem; white-space: nowrap; }

  /* Corps horizontal layout: stack on mobile */
  .corps-rank__body { flex-direction: column; }
  .corps-rank__body .corps-search-wrap { margin-left: 0; width: 100%; }

  /* Summon tab responsive */
  .summon-header { flex-direction: column; gap: 8px; align-items: flex-start; }
}

/* ===== Summon Status Tab ===== */

.summon-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.summon-progress-global {
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.summon-progress-global strong {
  color: var(--text-primary);
  font-weight: 700;
}

.summon-city-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-dark);
  border-left: 3px solid var(--accent-blue);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.summon-city-card--done {
  border-left-color: #27ae60;
  background: #eafaf1;
}

.summon-city-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.summon-city-card__title {
  color: var(--text-primary);
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.summon-city-card__progress {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.summon-officer-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summon-officer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-primary);
}

.summon-officer:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
}

.summon-officer__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-dark);
  border-radius: 3px;
  font-size: 0.7rem;
  color: transparent;
  background: var(--bg-primary);
  transition: all 0.15s;
}

.summon-officer--done .summon-officer__check {
  background: #27ae60;
  border-color: #27ae60;
  color: #ffffff;
}

.summon-officer--done .summon-officer__name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.summon-officer--done {
  opacity: 0.65;
}

.summon-officer__name {
  font-weight: 500;
}

.summon-officer__role {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 1px 6px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.appointment-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* ===== Assignment Config Grid ===== */

#assignment-config-section {
  margin-bottom: 16px;
}
.btn-reset {
  font-size: 0.75rem;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
}
.btn-reset:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.config-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 20px;
}
.config-group:last-child {
  margin-bottom: 0;
}
.config-group__title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
}
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 24px;
}
.config-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
}
.config-row--full {
  grid-column: 1 / -1;
  align-items: flex-start;
}
.config-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  min-width: 100px;
  flex-shrink: 0;
}
.config-select,
.config-input {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.82rem;
  background: var(--bg-card);
  color: var(--text-primary);
}
.config-select {
  min-width: 110px;
}
.config-input {
  width: 64px;
  text-align: center;
}
.config-sep {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Unassigned Table ===== */

.unassigned-table {
  width: auto;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.unassigned-table th {
  text-align: center;
  padding: 6px 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  font-size: 0.82rem;
}
.unassigned-table th:first-child {
  text-align: left;
}
.unassigned-table td {
  padding: 5px 12px;
  text-align: center;
}
.unassigned-table td:first-child {
  text-align: left;
  padding-right: 24px;
}
.unassigned-table tbody tr:nth-child(even) {
  background: var(--bg-table-alt);
}
.unassigned-table tr:hover {
  background: var(--bg-hover);
}

@media (max-width: 768px) {
  .config-grid {
    grid-template-columns: 1fr;
  }
}
