:root {
  --bg: #0b0d12;
  --bg-2: #12151d;
  --bg-3: #171b25;
  --panel: #12151d;
  --border: #232838;
  --border-2: #2c3242;
  --text: #e6e8ec;
  --muted: #9aa1b1;
  --muted-2: #6b7280;
  --primary: #5865f2;
  --primary-2: #4752c4;
  --success: #3ba55d;
  --warn: #faa61a;
  --danger: #ed4245;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #1a1f2e 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Login ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  width: 380px; max-width: 92vw; padding: 40px 32px; text-align: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
}
.auth-logo { font-size: 44px; }
.auth-card h1 { margin: 12px 0 2px; font-size: 22px; }
.btn-discord {
  display: inline-flex; align-items: center; gap: 10px; margin: 22px 0 14px;
  background: var(--primary); color: #fff; padding: 12px 22px; border-radius: 12px; font-weight: 600;
  transition: background .15s ease, transform .05s ease;
}
.btn-discord:hover { background: var(--primary-2); }
.btn-discord:active { transform: translateY(1px); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  display: flex; flex-direction: column; gap: 8px; padding: 18px 14px;
  background: linear-gradient(180deg, #12151d, #0e1118); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 8px 10px 16px; }
.brand-icon { font-size: 22px; }
.brand-logo { height: 26px; width: auto; }
.credit { margin-top: 10px; color: var(--muted-2); font-size: 11px; text-align: center; }
.auth-logo-img { height: 68px; width: auto; margin-bottom: 8px; object-fit: contain; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.guild-switch { padding: 2px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.guild-switch > span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); margin-bottom: 6px; }
.guild-switch select { width: 100%; }
.guild-switch .guild-name { font-weight: 600; font-size: 14px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500; cursor: pointer;
}
.nav a .ic { width: 20px; text-align: center; }
.nav a:hover { background: var(--bg-3); color: var(--text); }
.nav a.active { background: rgba(88, 101, 242, 0.16); color: #fff; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 6px 8px 10px; }
.user-box img { width: 34px; height: 34px; border-radius: 50%; background: #222; }
.user-box .u-name { font-weight: 600; font-size: 13px; }
.user-box .u-role { font-size: 11px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 26px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: rgba(11, 13, 18, 0.8); backdrop-filter: blur(8px); z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; gap: 8px; }
.view { padding: 24px 26px 60px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border-2);
  background: var(--bg-3); color: var(--text); padding: 9px 14px; border-radius: 10px;
  cursor: pointer; font-size: 13px; font-weight: 600; transition: filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); border-color: transparent; color: #fff; }
.btn-success { background: var(--success); border-color: transparent; color: #fff; }
.btn-warn { background: var(--warn); border-color: transparent; color: #1a1a1a; }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat-card .stat-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat-accent-open { color: #8ea2ff; }
.stat-accent-closed { color: #7ee0a1; }
.stat-accent-warn { color: var(--warn); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }

/* ---------- Table ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; font-size: 13px; }
thead th { background: var(--bg-3); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { border-top: 1px solid var(--border); cursor: pointer; }
tbody tr:hover { background: var(--bg-3); }
td.mono, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-open { background: rgba(88,101,242,.18); color: #9db0ff; }
.badge-closed { background: rgba(120,130,150,.18); color: #aeb6c6; }
.badge-claimed { background: rgba(59,165,93,.18); color: #7ee0a1; }
.badge-cat { background: var(--bg-3); color: var(--muted); }
.badge-lvl-error { background: rgba(237, 66, 69, .18); color: #ff8a8c; }
.badge-lvl-warn { background: rgba(250, 166, 26, .18); color: #f6c667; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border-2); border-radius: 10px;
  padding: 9px 11px; font-size: 13px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { width: 100%; resize: vertical; min-height: 90px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
label.field input, label.field select, label.field textarea { width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.switch { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.switch input { width: auto; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { width: 760px; max-width: 96vw; max-height: 90vh; overflow: auto; background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-2); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }

/* ---------- Ticket detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-bottom: 16px; }
.detail-grid .k { color: var(--muted); font-size: 12px; }
.detail-grid .v { font-size: 13px; }
.chat { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-height: 320px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; }
.msg img { width: 34px; height: 34px; border-radius: 50%; flex: none; background: #222; }
.msg .m-head { display: flex; align-items: baseline; gap: 8px; }
.msg .m-author { font-weight: 600; font-size: 13px; }
.msg .m-author.bot::after { content: "BOT"; margin-left: 6px; background: var(--primary); color: #fff; font-size: 9px; padding: 1px 5px; border-radius: 4px; vertical-align: middle; }
.msg .m-time { color: var(--muted-2); font-size: 11px; }
.msg .m-content { font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg .m-embed { border-left: 3px solid var(--primary); background: var(--bg-3); padding: 6px 10px; border-radius: 6px; margin-top: 4px; }
.send-box { display: flex; gap: 8px; margin-top: 12px; }
.send-box textarea { min-height: 44px; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---------- Misc ---------- */
.loading { color: var(--muted); padding: 30px; text-align: center; }
.empty { color: var(--muted); padding: 40px; text-align: center; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.role-pick { display: flex; flex-wrap: wrap; gap: 8px; max-height: 160px; overflow: auto; padding: 10px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--bg); }
.role-pick label { display: flex; align-items: center; gap: 6px; font-size: 12px; background: var(--bg-3); padding: 5px 9px; border-radius: 8px; cursor: pointer; }
.role-pick input { width: auto; }
.cat-editor { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: var(--panel); }
.cat-editor h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.kb-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.kb-files { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow: auto; }
.kb-files .kb-file { padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 13px; }
.kb-files .kb-file:hover { background: var(--bg-3); color: var(--text); }
.kb-files .kb-file.active { background: rgba(88,101,242,.16); color: #fff; }
.kb-files .kb-cat { font-size: 11px; text-transform: uppercase; color: var(--muted-2); margin: 10px 4px 4px; }
.kb-editor textarea { min-height: 55vh; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ---------- Charts ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar { width: 70%; min-height: 2px; border-radius: 5px 5px 0 0; transition: height .3s ease; }
.bar-x { font-size: 10px; color: var(--muted-2); margin-top: 6px; white-space: nowrap; }

/* ---------- Form editor ---------- */
.form-field-row { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: var(--panel); }
.ff-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ff-num { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.ff-move { display: flex; gap: 6px; }
.preview-modal { background: #313338; border: 1px solid var(--border); border-radius: 12px; padding: 16px; position: sticky; top: 90px; }
.pm-title { font-weight: 700; font-size: 16px; margin-bottom: 14px; color: #fff; }
.pm-field { margin-bottom: 12px; }
.pm-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #b5bac1; margin-bottom: 6px; }
.pm-input { background: #1e1f22; border: 1px solid #111318; border-radius: 6px; padding: 9px 10px; color: var(--muted-2); font-size: 13px; min-height: 20px; }
.pm-area { min-height: 60px; }
.pm-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.pm-btn { background: var(--primary); color: #fff; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--border-2); box-shadow: var(--shadow); font-size: 13px; animation: slideIn .18s ease; }
.toast.ok { border-left: 3px solid var(--success); }
.toast.err { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .nav { flex-direction: row; }
  .sidebar-footer { border: none; }
  .row, .detail-grid, .kb-layout { grid-template-columns: 1fr; }
}
