/* Card game admin panel — components: table, form, modal, messages */

/* ---------------------------------------------------------------- tables */
.panel-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.panel-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
thead th {
  text-align: start; font-size: 12px; color: var(--muted);
  background: var(--panel-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--row-border); vertical-align: middle; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
.empty-row { text-align: center; color: var(--muted); padding: 26px 0; }
.panel-loading { padding: 26px; text-align: center; color: var(--muted); }
.panel-pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mono { font-family: Consolas, monospace; font-size: 12px; }

/* --------------------------------------------------------------- elements */
.input, .select, textarea {
  background: var(--input-bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 8px 10px; font: inherit; min-width: 130px;
}
.input:focus, .select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 8px 12px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--btn-hover-border); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: #f8514922; border-color: #f8514966; color: #ffb3ae; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid transparent; }
.badge.ok { background: #3fb95022; color: #7ee787; border-color: #3fb95055; }
.badge.warn { background: #d2992222; color: #e3b341; border-color: #d2992255; }
.badge.danger { background: #f8514922; color: #ff9c96; border-color: #f8514955; }
.badge.info { background: #2f81f722; color: #9ecbff; border-color: #2f81f755; }
.badge.vip { background: #a371f722; color: #d2b8ff; border-color: #a371f755; }
.badge.muted { background: #8b98a522; color: var(--muted); border-color: #8b98a544; }

/* --------------------------------------------------------------- modal */
.modal-root { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; }
.modal-backdrop { position: absolute; inset: 0; background: var(--overlay); }
.modal {
  position: relative; z-index: 1; width: min(520px, 94vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px;
  box-shadow: var(--shadow);
}
.modal form { display: grid; gap: 12px; margin-top: 10px; }
.modal label.field input, .modal label.field select, .modal label.field textarea { width: 100%; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal.wide { width: min(860px, 96vw); }

/* ---------------------------------------------------------- layout fixes */
/* Overlaps: the modal keeps a margin on small screens and long values wrap. */
.modal-root { padding: 16px; }
.modal { width: min(520px, 100%); }
.modal.wide { width: min(860px, 100%); }
.card .value { word-break: break-word; }
.field { min-width: 0; }
.field * { min-width: 0; }
.detail { display: grid; gap: 10px; }
.detail img, .detail video { max-width: 100%; border-radius: 10px; display: block; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 8px;
}
img, video { max-width: 100%; }

/* Views stack sibling blocks (toolbar → KPI cards → table → call log). One rule
 * keeps a gap between them so two boxes never end up glued together. */
.view > * + * { margin-top: 12px; }
.view > .section + .section { margin-top: 18px; }
/* Nested blocks keep the same rhythm (e.g. the API summary, list and call log). */
[data-role="summary"] + [data-role="list"],
[data-role="list"] + .card,
.panel-table-wrap + .panel-table-wrap,
.grid + .panel-table-wrap { margin-top: 12px; }
/* Long values (URLs, keys, ids) wrap inside their own cell instead of running
 * into the next column, and badges never break in half. */
.card, .field, .detail, .panel-table-wrap, table { overflow-wrap: anywhere; }
.panel-table-wrap { max-width: 100%; }
thead th { vertical-align: middle; }
.badge { white-space: nowrap; }
.actions { align-items: center; }

/* Label/value blocks used by the database, server and log views. */
.detail-grid {
  display: grid; gap: 10px 16px; margin-top: 8px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.detail-grid > div { min-width: 0; overflow-wrap: anywhere; }

/* Console output (migrations, backups) inside the database and server views. */
.console-wrap { margin-top: 8px; }
.console {
  margin: 6px 0 0; padding: 10px 12px; max-height: 260px; overflow: auto;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* Log entries: level badge, channel, time and the (collapsible) stack trace. */
.log-entry { border-bottom: 1px solid var(--border); padding: 8px 2px; }
.log-entry:last-child { border-bottom: 0; }
.log-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.log-message { margin-top: 4px; font-size: 12.5px; overflow-wrap: anywhere; }
.log-entry details { margin-top: 4px; }
.log-entry summary { cursor: pointer; font-size: 11.5px; color: var(--muted); }
.log-context {
  margin: 6px 0 0; padding: 8px; max-height: 220px; overflow: auto; border-radius: 8px;
  background: var(--panel-2); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.lvl-emergency, .lvl-alert, .lvl-critical, .lvl-error { color: #ff6b6b; }
.lvl-warning { color: #ffb020; }
.lvl-notice, .lvl-info { color: #4dabf7; }
.lvl-debug { color: var(--muted); }
.snippet-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

/* Permission matrix inside the role dialog: one checkbox per permission code. */
.perm-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.perm-option { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px; border-radius: 8px; }
.perm-option:hover { background: var(--panel-2); }
.perm-option input { margin-top: 4px; flex: 0 0 auto; }
.perm-option span { font-size: 12px; color: var(--text); }
.perm-summary { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

/* Light theme badges need darker text on light backgrounds. */
[data-theme="light"] .badge.ok { background: #e6f4ea; color: #116329; border-color: #a8d5b5; }
[data-theme="light"] .badge.warn { background: #fff4e0; color: #8a5a00; border-color: #f0c98a; }
[data-theme="light"] .badge.danger { background: #fdecea; color: #a3231b; border-color: #f2b8b5; }
[data-theme="light"] .badge.info { background: #e7f0fd; color: #0b4a9c; border-color: #a9c9f5; }
[data-theme="light"] .badge.vip { background: #f2eafd; color: #5b2bb8; border-color: #cbb2f0; }
[data-theme="light"] .badge.muted { background: #eef1f5; color: #5a6673; border-color: #d7dee6; }
[data-theme="light"] .btn.danger { background: #fdecea; color: #a3231b; border-color: #f2b8b5; }
[data-theme="light"] .panel-table-wrap, [data-theme="light"] .modal { box-shadow: var(--shadow); }

/* ------------------------------------------------------- toast messages */
.toasts { position: fixed; inset-block-end: 16px; inset-inline-start: 16px; display: grid; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-inline-start: 3px solid var(--primary);
  border-radius: 10px; padding: 8px 12px; max-width: 360px; box-shadow: 0 10px 30px #0007;
}
.toast.ok { border-inline-start-color: var(--ok); }
.toast.err { border-inline-start-color: var(--danger); }

/* ------------------------------------------------------ language toggle */
.lang-switch { display: flex; align-items: center; gap: 6px; }
.lang-switch.center { justify-content: center; }

.mobile-only { display: none; }
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; z-index: 30;
    transform: translateX(-102%); transition: transform .2s;
  }
  body.nav-open .sidebar { transform: none; }
  .mobile-only { display: inline-block; }
  .main { padding: 16px 14px 60px; }
  .grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
}
