*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.7; color: #2d3748; background: #f7fafc;
}

/* Header */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
  color: #fff; padding: 0 2rem; height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 12px rgba(26,54,93,0.18);
}
.header-left { display: flex; align-items: center; gap: 0.8rem; }
.header-logo { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.header-logo span { color: #90cdf4; font-weight: 400; }
.sidebar-toggle {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.3); }
.header-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-select {
  padding: 6px 10px; border: 1px solid rgba(255,255,255,0.25); border-radius: 6px;
  font-size: 0.82rem; background: rgba(255,255,255,0.12); color: #fff;
  cursor: pointer; outline: none;
}
.filter-select option { color: #2d3748; background: #fff; }

/* App Layout */
.app-layout {
  display: flex; margin-top: 64px; min-height: calc(100vh - 64px);
}

/* Sidebar */
.sidebar {
  width: 260px; min-width: 260px; background: #fff;
  border-right: 1px solid #e2e8f0;
  padding: 1rem 0; overflow-y: auto;
  max-height: calc(100vh - 64px); position: sticky; top: 64px;
  transition: margin-left 0.25s ease, opacity 0.25s ease;
}
.sidebar.closed {
  margin-left: -260px; opacity: 0; pointer-events: none;
}

.sidebar-search { padding: 10px 16px; border-bottom: 1px solid #e2e8f0; }
.sidebar-search-label {
  display: block; font-size: 0.72rem; font-weight: 700; color: #4a5568;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px;
}
.sidebar-search input {
  width: 100%; padding: 7px 10px; border: 1px solid #e2e8f0; border-radius: 6px;
  font-size: 0.82rem; color: #2d3748; background: #f7fafc; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.sidebar-search input::placeholder { color: #a0aec0; }
.sidebar-search input:focus { border-color: #2b6cb0; box-shadow: 0 0 0 3px rgba(43,108,176,0.1); background: #fff; }
.sidebar-section { border-bottom: 1px solid #f0f4f8; }
.sidebar-section:last-child { border-bottom: none; }

.sidebar-section-header {
  padding: 10px 16px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 700; color: #4a5568;
  text-transform: uppercase; letter-spacing: 0.05em;
  transition: background 0.15s;
}
.sidebar-section-header:hover { background: #f7fafc; }
.sidebar-section-header .sidebar-count {
  font-weight: 400; color: #a0aec0; font-size: 0.72rem; margin-left: auto;
}
.sidebar-section-header .sidebar-arrow {
  font-size: 0.6rem; color: #a0aec0; transition: transform 0.2s;
}
.sidebar-section-header.collapsed .sidebar-arrow { transform: rotate(-90deg); }
.sidebar-section-body { padding: 0 12px 10px; }
.sidebar-section-header.collapsed + .sidebar-section-body { display: none; }

.sidebar-check {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer;
  font-size: 0.82rem; color: #4a5568; transition: background 0.1s;
}
.sidebar-check:hover { background: #f7fafc; }
.sidebar-check input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: #2b6cb0; cursor: pointer; flex-shrink: 0;
}
.sidebar-check .check-label { flex: 1; display: flex; align-items: center; gap: 6px; }
.sidebar-check .check-count {
  font-size: 0.72rem; color: #a0aec0; margin-left: auto; min-width: 20px; text-align: right;
}
.sidebar-check-all {
  font-weight: 600; color: #2d3748; margin-bottom: 4px;
  padding-bottom: 6px; border-bottom: 1px solid #f0f4f8;
}
.sidebar-check .country-flag { font-size: 1rem; }

/* Active filter chips */
.active-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; background: #ebf8ff; color: #2b6cb0;
  border-radius: 10px; font-size: 0.72rem; font-weight: 500;
}
.filter-chip .chip-remove {
  cursor: pointer; font-size: 0.85rem; color: #a0aec0;
  margin-left: 2px; line-height: 1;
}
.filter-chip .chip-remove:hover { color: #c53030; }

/* Main */
.main-content { flex: 1; padding: 1.5rem 2rem 2rem; min-width: 0; overflow-x: hidden; }

/* Stats */
.stats-bar { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.stat-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 0.8rem 1.2rem; flex: 1; min-width: 130px;
}
.stat-card .stat-label { font-size: 0.72rem; color: #718096; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: #2d3748; }

/* Result count */
.result-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.8rem; font-size: 0.82rem; color: #718096;
}

/* Refresh button */
.refresh-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border: 1px solid #e2e8f0; border-radius: 6px;
  background: #fff; color: #4a5568; font-size: 0.78rem; font-weight: 500;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.refresh-btn:hover { background: #f7fafc; border-color: #cbd5e0; }
.refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.refresh-btn.spinning svg { animation: spin 0.8s linear infinite; }

/* Table */
.table-wrap {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  overflow: auto; max-height: calc(100vh - 240px);
}
table { width: 100%; min-width: 1200px; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  background: #f7fafc; padding: 10px 14px; text-align: left;
  font-weight: 600; color: #4a5568; border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 10;
  cursor: pointer; user-select: none; transition: background 0.15s;
}
thead th:hover { background: #edf2f7; }
.th-content { display: inline; }
.col-resize-handle {
  position: absolute; top: 0; right: 0; width: 6px; height: 100%;
  cursor: col-resize; z-index: 11;
  background: transparent; transition: background 0.15s;
}
.col-resize-handle:hover,
.col-resize-handle:active { background: #2b6cb0; opacity: 0.4; }
.sort-arrow { font-size: 0.7rem; margin-left: 4px; color: #a0aec0; }
.sort-arrow.active { color: #2b6cb0; }
tbody tr { border-bottom: 1px solid #f0f4f8; transition: background 0.1s; cursor: pointer; }
tbody tr:hover { background: #f7fafc; }
tbody td { padding: 10px 14px; vertical-align: top; overflow: hidden; text-overflow: ellipsis; }
tbody td.name-col { font-weight: 600; color: #2d3748; }
tbody td.name-col .sub-name { font-weight: 400; color: #718096; font-size: 0.78rem; }
.cell-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-narrow { white-space: nowrap; }
.cell-contract-period { white-space: nowrap; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.72rem; font-weight: 500; white-space: nowrap;
}
.badge-university { background: #ebf8ff; color: #2b6cb0; }
.badge-tafe { background: #f0fff4; color: #38a169; }
.badge-private { background: #faf5ff; color: #6b46c1; }
.badge-school { background: #fffaf0; color: #c05621; }
.status-badge-active { background: #f0fff4; color: #38a169; }
.status-badge-expired, .status-badge-inactive { background: #fff5f5; color: #c53030; }
.status-badge-other { background: #f7fafc; color: #718096; }

/* Country badges */
.country-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.72rem; font-weight: 500; white-space: nowrap;
  background: #edf2f7; color: #4a5568;
}
.country-aust { background: #fff8e1; color: #b7791f; }
.country-nz { background: #e8f5e9; color: #2e7d32; }
.country-korea { background: #e3f2fd; color: #1565c0; }
.country-uk { background: #fce4ec; color: #c62828; }
.country-uae { background: #f3e5f5; color: #7b1fa2; }
.country-us { background: #e8eaf6; color: #283593; }
.country-canada { background: #ffebee; color: #c62828; }
.country-malaysia { background: #e0f7fa; color: #00838f; }
.country-singapore { background: #fff3e0; color: #e65100; }
.country-indonesia { background: #ffebee; color: #b71c1c; }
.country-vietnam { background: #fff8e1; color: #f57f17; }
.badge-country { background: rgba(255,255,255,0.2); color: #fff; }

mark { background: #fefcbf; color: #975a16; padding: 0 2px; border-radius: 2px; }

/* Loading */
.loading { text-align: center; padding: 3rem 1rem; color: #718096; }
.loading .spinner {
  width: 36px; height: 36px; border: 3px solid #e2e8f0; border-top-color: #2b6cb0;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 200;
  justify-content: center; align-items: flex-start; padding-top: 80px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 90%; max-width: 860px;
  max-height: calc(100vh - 120px); display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3); overflow: hidden;
}
.modal-header {
  position: sticky; top: 0; z-index: 1;
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
  color: #fff; padding: 1.2rem 1.5rem; border-radius: 12px 12px 0 0;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header-content { flex: 1; min-width: 0; }
.modal-header-content h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 2px; }
.modal-header-content .detail-sub { font-size: 0.82rem; color: #90cdf4; }
.modal-header-content .detail-meta { display: flex; gap: 6px; margin-top: 6px; }
.modal-header-content .detail-meta .badge { font-size: 0.7rem; }
.modal-refresh {
  background: rgba(255,255,255,0.2); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-left: 12px; transition: background 0.2s;
}
.modal-refresh:hover { background: rgba(255,255,255,0.35); }
.modal-refresh.spinning svg { animation: spin 0.8s linear infinite; }
.modal-close {
  background: rgba(255,255,255,0.2); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-left: 4px;
}
.modal-close:hover { background: rgba(255,255,255,0.35); }
.modal-body { padding: 1.5rem; overflow-y: auto; overflow-x: hidden; flex: 1; min-width: 0; width: 100%; }

/* Detail sections */
.detail-section { margin-bottom: 1.5rem; overflow: hidden; }
.detail-section h3 {
  font-size: 0.82rem; font-weight: 600; color: #2b6cb0;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 0.6rem; padding-bottom: 0.3rem;
  border-bottom: 2px solid #ebf8ff;
}
.detail-grid {
  display: grid; grid-template-columns: 160px minmax(0, 1fr);
  gap: 4px 12px; font-size: 0.85rem;
}
.detail-label { color: #718096; font-weight: 500; }
.detail-value { color: #2d3748; word-break: break-word; }
.detail-value a { color: #2b6cb0; text-decoration: none; }
.detail-value a:hover { text-decoration: underline; }

/* Commission table in modal */
.commission-table { width: 100%; max-width: 100%; min-width: 0; border-collapse: collapse; font-size: 0.82rem; margin-top: 0.5rem; table-layout: fixed; }
.commission-table th, .commission-table td {
  padding: 8px 10px; border: 1px solid #e2e8f0; text-align: left;
  word-wrap: break-word; overflow-wrap: break-word; word-break: break-word;
}
.commission-table th { background: #f7fafc; font-weight: 600; color: #4a5568; }
.commission-table th:first-child, .commission-table td:first-child { width: 50%; }
.commission-table th:last-child, .commission-table td:last-child { width: 50%; }
.commission-table tbody tr:hover { background: #f7fafc; }

/* Collapsible */
.collapsible { margin-top: 0.8rem; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; }
.collapsible-header {
  padding: 10px 14px; cursor: pointer; font-weight: 500; font-size: 0.85rem;
  color: #4a5568; display: flex; justify-content: space-between; align-items: center;
  user-select: none; background: #f7fafc;
}
.collapsible-header:hover { background: #edf2f7; }
.collapsible-header .arrow { transition: transform .2s; font-size: 11px; color: #a0aec0; }
.collapsible-header.open .arrow { transform: rotate(90deg); }
.collapsible-body { padding: 12px 14px; font-size: 0.82rem; line-height: 1.7; color: #4a5568; white-space: pre-wrap; }
.collapsible-body.hidden { display: none; }

/* Sub-institutions */
.sub-inst-list { list-style: none; }
.sub-inst-item {
  padding: 8px 14px; cursor: pointer; border-bottom: 1px solid #f0f4f8;
  font-size: 0.85rem; display: flex; align-items: center; gap: 8px;
  transition: background .15s; color: #2d3748;
}
.sub-inst-item:hover { background: #ebf8ff; }
.sub-inst-item:last-child { border-bottom: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-active { background: #38a169; }
.status-inactive { background: #c53030; }

/* Login */
.login-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 300;
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 60%, #2c5282 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: #fff; border-radius: 16px; padding: 2.5rem 2rem;
  width: 360px; max-width: 90vw; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { font-size: 1.6rem; font-weight: 700; color: #1a365d; margin-bottom: 4px; }
.login-sub { font-size: 0.85rem; color: #718096; margin-bottom: 1.5rem; }
.login-box input {
  width: 100%; padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px;
  font-size: 0.9rem; outline: none; margin-bottom: 0.8rem; text-align: center;
}
.login-box input:focus { border-color: #2b6cb0; box-shadow: 0 0 0 3px rgba(43,108,176,0.15); }
.login-box button {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: linear-gradient(135deg, #1a365d, #2b6cb0); color: #fff;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.login-box button:hover { opacity: 0.9; }
.login-box button:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error { color: #c53030; font-size: 0.82rem; margin-top: 0.8rem; min-height: 1.2em; }
.logout-btn {
  padding: 6px 14px; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
  background: rgba(255,255,255,0.1); color: #fff; font-size: 0.82rem;
  cursor: pointer; transition: background 0.2s;
}
.logout-btn:hover { background: rgba(255,255,255,0.25); }
.role-badge {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 0.72rem; font-weight: 600; margin-left: 8px;
}
.role-staff { background: rgba(255,255,255,0.2); color: #fff; }
.role-partner { background: rgba(144,205,244,0.3); color: #90cdf4; }

/* Responsive */
@media (max-width: 1024px) {
  .sidebar { position: fixed; top: 64px; left: 0; bottom: 0; z-index: 90; box-shadow: 4px 0 20px rgba(0,0,0,0.15); }
  .sidebar.closed { margin-left: -260px; }
}
@media (max-width: 768px) {
  .site-header { padding: 0 1rem; flex-wrap: wrap; height: auto; padding: 10px 1rem; gap: 8px; }
  .header-search { max-width: 100%; }
  .header-filters { width: 100%; }
  .main-content { padding: 1rem; }
  .stats-bar { flex-direction: column; }
  .modal { max-width: 100%; border-radius: 10px; }
  .modal-body { padding: 1rem; }
  .detail-grid { grid-template-columns: 1fr; }
  .cell-truncate { max-width: 120px; }
  table { font-size: 0.78rem; }
  tbody td, thead th { padding: 8px 10px; }
}
