:root {
  --bg: #f0ede7;
  --bg-elev: #fcfaf6;
  --ink: #1f2a37;
  --ink-soft: #576174;
  --line: #d8d0c4;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #b45309;
  --danger: #b42318;
  --success: #107569;
  --warn: #b54708;
  --shadow: 0 14px 28px rgba(31, 42, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Noto Sans SC", "Segoe UI", sans-serif;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 10%, #efe6d8 0%, transparent 45%),
    radial-gradient(circle at 90% 0%, #d8ece7 0%, transparent 40%),
    linear-gradient(180deg, #f7f3eb 0%, #f0ede7 100%);
}

a {
  color: inherit;
}

.page {
  width: min(1360px, 96vw);
  margin: 0 auto;
  padding: 20px 0 40px;
}

.banner {
  background: linear-gradient(110deg, #1f2937 0%, #334155 36%, #115e59 100%);
  color: #f8fafc;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  animation: rise 360ms ease-out;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-sub {
  color: #c4d7d4;
  font-size: 13px;
}

.banner-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.role-chip {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: #d7f4ef;
}

.main {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
}

.nav {
  background: rgba(252, 250, 246, 0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  height: fit-content;
}

.nav h3 {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.nav button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  margin-bottom: 8px;
  padding: 10px 12px;
  text-align: left;
  color: var(--ink);
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms ease;
}

.nav button:hover {
  background: #eef4f2;
}

.nav button.active {
  background: linear-gradient(90deg, #d5ebe7 0%, #f0f8f6 100%);
  color: #0f4f49;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: rgba(252, 250, 246, 0.95);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: rise 260ms ease-out;
}

.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
}

.panel-head h4 {
  margin: 0;
  font-size: 16px;
}

.panel-body {
  padding: 14px 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  background: linear-gradient(165deg, #fffdf8 0%, #f5efe4 100%);
  border: 1px solid #e4d9c9;
  border-radius: 14px;
  padding: 12px 14px;
}

.metric-name {
  color: var(--ink-soft);
  font-size: 12px;
}

.metric-value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 700;
  color: #243447;
}

.metric-sub {
  margin-top: 3px;
  color: #6b7280;
  font-size: 12px;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 13px;
}

.check-row input {
  width: auto;
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  background: rgba(0, 0, 0, 0.02);
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  border: 1px dashed rgba(216, 208, 196, 0.6);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-stack input,
.form-stack textarea,
.form-stack select {
  width: 100%;
}

.announcement-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.82fr);
  gap: 14px;
  align-items: stretch;
}

.announcement-editor-pane,
.announcement-preview-pane {
  min-width: 0;
}

.announcement-html-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.announcement-html-editor {
  min-height: 270px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  line-height: 1.55;
  resize: vertical;
}

.announcement-preview-pane {
  border: 1px solid #d8d0c4;
  border-radius: 10px;
  background: #fffdf8;
  padding: 10px;
}

.announcement-preview-frame {
  width: 100%;
  min-height: 292px;
  border: 1px solid #e4d9c9;
  border-radius: 8px;
  background: #fff;
}

input,
select,
textarea {
  border: 1px solid #d1cdc5;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  min-width: 0;
  transition: all 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #0f766e;
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

button {
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
}

button.primary {
  color: #f8fafc;
  background: linear-gradient(120deg, var(--brand) 0%, #0d9488 100%);
}

button.primary:hover {
  filter: brightness(1.06);
}

button.ghost {
  color: var(--ink);
  background: #ece7dc;
}

button.ghost:hover {
  background: #e4ddcf;
}

button.danger {
  color: #fff;
  background: linear-gradient(120deg, #b42318 0%, #9d1d14 100%);
}

button.warn {
  color: #fff;
  background: linear-gradient(120deg, #b54708 0%, #9a3b08 100%);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid #e8e0d3;
  padding: 10px 8px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: #4b5563;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

tr:hover td {
  background: #fcf8ef;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}

.tag.ok {
  color: #0f5132;
  background: #d1f0e2;
}

.tag.off {
  color: #842029;
  background: #f8d7da;
}

.tag.info {
  color: #0c4a6e;
  background: #dbeafe;
}

.tag.warn {
  color: #7c2d12;
  background: #ffedd5;
}

.status-line {
  color: var(--ink-soft);
  font-size: 12px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 94vw);
  border-radius: 18px;
  border: 1px solid #d7cdbd;
  background: rgba(252, 250, 246, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-head {
  padding: 18px 22px;
  background: linear-gradient(130deg, #1f2937 0%, #134e4a 100%);
  color: #f8fafc;
}

.login-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.error-box {
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  color: #842029;
  border: 1px solid #f1b7bf;
  background: #fbe7ea;
}

.success-box {
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  color: #0f5132;
  border: 1px solid #b9e5c5;
  background: #e4f7e9;
}

.inline-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.joined-group {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid #d1cdc5;
  border-radius: 9px;
  background: #fff;
  transition: all 140ms ease;
  overflow: hidden;
}
.joined-group:focus-within {
  border-color: #0f766e;
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}
.joined-group input {
  border: none;
  border-radius: 0;
  background: transparent;
  width: 72px;
  padding: 6px 10px;
}
.joined-group input:focus {
  box-shadow: none;
}
.joined-group button {
  border-radius: 0;
  border: none;
  border-left: 1px solid #d1cdc5;
  background: #fcfaf6;
  padding: 6px 12px;
  color: var(--ink);
  font-weight: 500;
}
.joined-group button:hover {
  background: #f0ede7;
}

.action-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
}

.footer-note {
  margin-top: 12px;
  color: #6b7280;
  font-size: 12px;
}

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

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .announcement-editor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .page {
    width: 96vw;
    padding-top: 14px;
  }

  .banner {
    border-radius: 14px;
    padding: 14px;
  }

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

  .panel-head,
  .panel-body {
    padding: 12px;
  }
}

/* ---------- Mail form ---------- */
.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.field-hint {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.5;
}

.mail-segmented {
  display: inline-flex;
  border: 1px solid #d1cdc5;
  border-radius: 10px;
  background: #fff;
  padding: 3px;
  gap: 3px;
}

.mail-segmented button {
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
}

.mail-segmented button.active {
  background: linear-gradient(120deg, #e3f3ef 0%, #d2e9e4 100%);
  color: var(--brand-strong);
  box-shadow: inset 0 0 0 1px #b9d9d2;
}

.mail-server-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.mail-server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.mail-server-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid #d8d0c4;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.mail-server-option.selected {
  border-color: #86c7bd;
  background: #eef8f5;
}

.mail-server-option.disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.mail-server-option input {
  width: auto;
  min-width: 0;
}

.mail-server-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mail-server-main > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(15, 118, 110, 0.05);
  border: 1px dashed rgba(15, 118, 110, 0.3);
  border-radius: 10px;
  color: var(--ink);
  font-size: 13px;
}

.check-row input[type="checkbox"] {
  width: auto;
  min-width: 0;
}

.mail-grid-2 {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 680px) {
  .mail-grid-2 {
    grid-template-columns: 1fr;
  }
}

.reward-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 120px auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

@media (max-width: 680px) {
  .reward-row {
    grid-template-columns: 1fr 100px auto auto;
  }
}

/* ---------- Item picker (searchable combobox) ---------- */
.item-picker {
  position: relative;
}

.item-picker-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 440px;
  max-width: 560px;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 36px rgba(31, 42, 55, 0.18);
  max-height: 380px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.item-picker-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 2px 0;
}

.item-picker-option {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1eadc;
  gap: 10px;
}

.item-picker-option:last-child {
  border-bottom: 0;
}

.item-picker-option:hover {
  background: #f5efe2;
}

.item-picker-option .po-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.item-picker-option .po-name {
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-picker-option .po-id {
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-picker-option .po-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.item-picker-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}

.item-picker-count {
  padding: 7px 12px;
  font-size: 11px;
  color: var(--ink-soft);
  background: rgba(0, 0, 0, 0.02);
  border-top: 1px solid var(--line);
  letter-spacing: 0.2px;
}

/* ---------- Admin list/page layout helpers ---------- */
.admin-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(15, 118, 110, 0.04);
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 12px;
}

.toolbar-grow {
  flex: 1 1 260px;
}

.toolbar-input-sm {
  width: 140px;
}

.toolbar-input-md {
  width: 180px;
}

.toolbar-input-lg {
  width: 240px;
}

.toolbar-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.table-status-bar {
  margin-bottom: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid #e7dfd2;
  border-radius: 10px;
}

.table-cell-mono {
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 12px;
}

.table-cell-wrap {
  white-space: pre-wrap;
  word-break: break-word;
}

.action-stack {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.pager-row {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-block {
  margin-bottom: 10px;
}

.detail-card {
  white-space: pre-wrap;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 72px 20px 24px;
  background: rgba(15, 23, 42, 0.36);
  overflow: auto;
}

.modal-panel {
  width: min(960px, 100%);
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22);
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.player-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.player-detail-field {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.025);
}

.player-detail-field span {
  display: block;
  color: #64748b;
  font-size: 12px;
  margin-bottom: 4px;
}

.player-detail-field strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  color: #0f172a;
}

.player-detail-assets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.player-detail-assets span {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- SSH files ---------- */
.ssh-connection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.ssh-connection-grid label,
.ssh-secret-row label,
.ssh-key-grid label {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.ssh-connection-grid input,
.ssh-connection-grid select,
.ssh-secret-row input,
.ssh-key-grid input,
.ssh-key-grid textarea {
  width: 100%;
  box-sizing: border-box;
}

.ssh-secret-row {
  display: grid;
  grid-template-columns: minmax(260px, 420px);
  gap: 12px;
  margin-bottom: 12px;
}

.ssh-key-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(180px, 260px);
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.ssh-key-file-button {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 8px;
  border-radius: 9px;
  padding: 7px 11px;
  color: var(--ink);
  background: #ece7dc;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ssh-key-file-button:hover {
  background: #e4ddcf;
}

.ssh-key-file-button input {
  display: none;
}

.ssh-preview {
  margin: 0;
  max-height: 560px;
  overflow: auto;
  padding: 12px;
  border: 1px solid #e3dbcf;
  border-radius: 10px;
  background: #111827;
  color: #e5e7eb;
  font: 12px/1.55 "JetBrains Mono", "SF Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 680px) {
  .toolbar-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }

  .toolbar-grow,
  .toolbar-input-sm,
  .toolbar-input-md,
  .toolbar-input-lg {
    width: 100%;
    flex: 1 1 100%;
  }

  .pager-row {
    justify-content: flex-start;
  }

  .ssh-connection-grid,
  .ssh-secret-row,
  .ssh-key-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
