:root {
  color-scheme: light dark;
  --bg: #0f1216;
  --card-bg: #1a1f27;
  --border: #2c333d;
  --text: #e7ebf0;
  --muted: #93a0af;
  --accent: #4caf6d;
  --danger: #e0574c;
  --warn: #d9a441;
}

* { box-sizing: border-box; }

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

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0 0 8px; font-size: 18px; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1216;
  color: var(--text);
  font-size: 14px;
}
.login-card button {
  margin-top: 6px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #06170c;
  font-weight: 600;
  cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; margin: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.host { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 8px; }
.logout-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.logout-link:hover { color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.card .warn { color: var(--warn); font-weight: 400; font-size: 12px; }

.row { display: flex; gap: 8px; margin: 8px 0; align-items: center; }
.row input:not([type="checkbox"]), .row #console-input, #wl-input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1216;
  color: var(--text);
}
button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #232a34;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-warn { border-color: var(--warn); color: var(--warn); }
.btn-warn:hover { background: var(--warn); color: #1a1300; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #1a0605; }

#server-control-log {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-height: 20px;
  max-height: 160px;
  overflow-y: auto;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 0;
}
#server-control-log:empty { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(360px, 90vw);
}
.modal-box h3 { margin: 0 0 12px; font-size: 16px; }
.modal-box p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; white-space: pre-wrap; }
.modal-actions { justify-content: flex-end; margin-top: 18px; }

.muted-small { color: var(--muted); font-weight: 400; font-size: 12px; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.metric-tile {
  background: #12161c;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.metric-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.metric-value { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.sparkline { width: 100%; height: 40px; display: block; }
.sparkline .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.sparkline .line-secondary { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 3 2; }
.sparkline .fill { fill: var(--accent); opacity: 0.08; stroke: none; }

.backup-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.backup-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.backup-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.backup-table tr:last-child td { border-bottom: none; }
.backup-table a { color: var(--accent); text-decoration: none; }
.backup-table a:hover { text-decoration: underline; }
.backup-table .cell-actions { display: flex; gap: 8px; justify-content: flex-end; }

#wl-list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; }
#wl-list li {
  background: #232a34;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#wl-list li button {
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--danger);
  font-size: 13px;
}

#ban-list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
#ban-list li {
  background: #232a34;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#ban-list .ban-info { display: flex; flex-direction: column; gap: 2px; }
#ban-list .ban-reason { color: var(--muted); font-size: 12px; }

.player-list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  background: #232a34;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.player-list .player-actions { display: flex; gap: 6px; }
.player-list .player-actions button { padding: 2px 8px; font-size: 12px; }

.msg { font-size: 13px; color: var(--muted); min-height: 18px; }
.msg.ok { color: var(--accent); }
.msg.error { color: var(--danger); }
.warn-banner {
  background: rgba(217, 164, 65, 0.12);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  min-height: auto;
}

.props-table-wrap { max-height: 420px; overflow-y: auto; }
.props-table-wrap table { table-layout: fixed; }
.props-table-wrap th:first-child, .props-table-wrap td:first-child { width: 40%; word-break: break-all; }
.props-key-locked { color: var(--muted); }
.props-value-input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0f1216;
  color: var(--text);
  font-size: 13px;
}
.props-value-input:disabled { color: var(--muted); background: transparent; border-color: transparent; cursor: not-allowed; }
.props-value-input.dirty { border-color: var(--warn); }
tr.props-row-hidden { display: none; }

#console-output, #logs-output {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

#logs-output { max-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

#logs-lines, #history-range {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1216;
  color: var(--text);
}

.status-line { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.online { background: var(--accent); }
.dot.offline { background: var(--danger); }

/* ---------- 모바일 대응 ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 6px; }
  .topbar h1 { font-size: 15px; }
  .host { display: block; margin-left: 0; font-size: 12px; }

  .grid { padding: 12px; gap: 12px; }
  .card { padding: 14px; }

  /* row 안의 입력창+버튼들을 세로로 쌓아서 좁은 화면에서 눌리지 않게 한다 */
  .row { flex-direction: column; align-items: stretch; }
  .row input:not([type="checkbox"]), .row select, .row button, .row .checkbox-label {
    width: 100%;
  }
  .row input[type="checkbox"] { width: auto; }

  .metrics-grid { grid-template-columns: 1fr 1fr; }

  /* 표는 옆으로만 스크롤되게 해서 페이지 전체가 가로로 밀리지 않도록 한다 */
  .backup-table, .props-table-wrap table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  .backup-table thead, .backup-table tbody, .backup-table tr {
    display: table;
    width: 100%;
    table-layout: auto;
  }

  #wl-list, .player-list, #ban-list { font-size: 12px; }
}
