@font-face {
  font-family: "Cardo";
  src: url("/cardo-bold.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #1b2230;
  --ink-2: #252e3f;
  --ink-3: #34405a;
  --parch: #f3ede2;
  --card: #fffcf6;
  --line: #e2d9c9;
  --text: #1b2230;
  --muted: #5b6170;
  --ember: #d9572a;
  --ember-dark: #b4441c;
  --ok: #2f7a4a;
  --warn: #9a6a00;
  --bad: #b3261e;
  --radius: 12px;
  --serif: "Cardo", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--parch); }
[hidden] { display: none !important; }
a { color: var(--ember-dark); }
a:hover { color: var(--ink); }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0; letter-spacing: 0.01em; }
h1 { font-size: 34px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.5em; font-size: 14px; }
.small { font-size: 13px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 10px; }
.login-icon { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 8px; }
.login-card h1 { font-size: 26px; }
.login-card .btn { margin-top: 4px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--ink); color: var(--parch); display: flex; flex-direction: column; padding: 22px 14px; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: block; padding: 4px 8px 10px; }
.brand img { width: 100%; height: auto; display: block; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a, .logout { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: #d6dbe6; text-decoration: none; font-size: 15px; font: inherit; }
#nav a:hover, .logout:hover { background: var(--ink-2); color: #fff; }
#nav a.active { background: var(--ink-3); color: #fff; }
#nav a.active svg { stroke: var(--ember); }
#nav svg, .logout svg { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.logout { margin-top: auto; background: none; border: 0; cursor: pointer; text-align: left; }
main { flex: 1; min-width: 0; padding: 36px 40px 64px; outline: none; }
.page { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 6px; }

/* ---------- Cards & grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.tile { gap: 6px; }
.tile .label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.tile .value { font-family: var(--serif); font-size: 34px; line-height: 1.1; }
.tile .sub { font-size: 13px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

/* ---------- Forms ---------- */
label { font-size: 13px; font-weight: 600; color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid #cfc5b3; border-radius: 9px; padding: 10px 12px; min-height: 44px; width: 100%; }
textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, .seg button:focus-visible { outline: 3px solid rgba(217, 87, 42, 0.45); outline-offset: 1px; border-color: var(--ember-dark); }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--ember-dark); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }

.btn { font: inherit; font-weight: 600; border-radius: 9px; padding: 10px 16px; min-height: 44px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--ember-dark); color: #fff; }
.btn.primary:hover { background: #9c3a17; color: #fff; }
.btn.ghost { background: transparent; border-color: #cfc5b3; color: var(--text); }
.btn.ghost:hover { background: #efe7d8; color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover { background: #8f1d17; color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.seg { display: inline-flex; background: #e9e0d0; border-radius: 10px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { font: inherit; font-weight: 600; font-size: 14px; border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 7px; cursor: pointer; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(27, 34, 48, 0.15); }

.files { display: flex; gap: 10px; flex-wrap: wrap; }
.file-chip { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px 6px 6px; font-size: 13px; max-width: 260px; }
.file-chip img, .file-chip .file-kind { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: #eee5d6; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; padding: 0 4px; min-height: 32px; }

/* ---------- Discord preview ---------- */
.preview { background: #313338; border-radius: var(--radius); padding: 18px; color: #dbdee1; font-size: 15px; }
.preview .ping { color: #c9cdfb; background: rgba(88, 101, 242, 0.3); border-radius: 3px; padding: 0 2px; font-weight: 500; }
.dc-embed { margin-top: 8px; background: #2b2d31; border-left: 4px solid var(--ember); border-radius: 4px; padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 6px; max-width: 520px; }
.dc-author { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #fff; }
.dc-author img { width: 22px; height: 22px; border-radius: 50%; }
.dc-title { font-weight: 700; color: #fff; font-size: 16px; }
.dc-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.dc-field-name { font-weight: 700; font-size: 13px; color: #fff; }
.dc-image { border-radius: 6px; margin-top: 6px; max-height: 280px; object-fit: cover; }
.dc-footer { font-size: 12px; color: #b5bac1; margin-top: 4px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; gap: 16px; }
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.item-title { font-weight: 700; font-size: 16px; }
.item-text { white-space: pre-wrap; word-break: break-word; color: #2c3342; max-height: 9.5em; overflow: hidden; }
.item-meta { font-size: 13px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.item-thumb { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #eee5d6; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #ece4d5; color: var(--text); }
.chip.ok { background: #d9eedf; color: #1d5532; }
.chip.warn { background: #f6e7c1; color: #6e4d00; }
.chip.bad { background: #eedad8; color: #7d1f19; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); border: 1px dashed #cfc5b3; border-radius: var(--radius); }

.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #ddd3c2; flex-shrink: 0; }
.avatar.lg { width: 48px; height: 48px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #efe7d9; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.bar { height: 8px; background: #e7dfd0; border-radius: 999px; overflow: hidden; min-width: 90px; }
.bar > div { height: 100%; background: var(--ember); border-radius: 999px; }
.rank { font-family: var(--serif); font-size: 18px; width: 40px; }

/* ---------- Tickets ---------- */
.tickets { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.ticket-list { display: flex; flex-direction: column; gap: 8px; }
.ticket-btn { text-align: left; font: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-height: 44px; color: var(--text); }
.ticket-btn[aria-current="true"] { border-color: var(--ember-dark); box-shadow: inset 3px 0 0 var(--ember); }
.ticket-btn strong { font-size: 15px; }
.convo { display: flex; flex-direction: column; gap: 14px; max-height: 520px; overflow-y: auto; padding-right: 4px; }
.msg { display: flex; gap: 10px; }
.msg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-head { font-size: 13px; color: var(--muted); }
.msg-head strong { color: var(--text); margin-right: 6px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-img { max-width: 260px; border-radius: 8px; margin-top: 4px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.toast.bad { background: var(--bad); }
.toast a { color: #ffd2bf; }

.danger-zone { border-color: #e3bdb9; }
.log { font-size: 14px; display: flex; flex-direction: column; }
.log div { padding: 8px 0; border-bottom: 1px solid #efe7d9; display: flex; gap: 12px; }
.log div:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 12px; white-space: nowrap; padding-top: 2px; min-width: 96px; }
.log span { word-break: break-word; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 10; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .brand { width: 150px; padding: 0; }
  #nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; order: 3; width: 100%; gap: 4px; scrollbar-width: none; }
  #nav a { padding: 8px 10px; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
  .logout { margin: 0 0 0 auto; padding: 8px 10px; }
  main { padding: 24px 16px 48px; }
  .tickets { grid-template-columns: minmax(0, 1fr); }
  .item { flex-direction: column; }
  .item-thumb { width: 100%; height: 160px; }
  h1 { font-size: 28px; }
}

/* ---------- Logs ---------- */
.logs { display: flex; flex-direction: column; }
.log-entry { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid #efe7d9; }
.log-entry:last-child { border-bottom: 0; }
.log-entry time { font-size: 12px; color: var(--muted); padding-top: 3px; }
.log-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.log-title { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.log-fields { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; font-size: 13px; }
.log-fields dt { color: var(--muted); font-weight: 600; }
.log-fields dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.chip.cat-mod { background: #f3d6d3; color: #7d1f19; }
.chip.cat-member { background: #d6e6f5; color: #1d4a72; }
.chip.cat-message { background: #f6eac1; color: #6b5200; }
.chip.cat-server { background: #e6dbf1; color: #533076; }
.chip.cat-voice { background: #d2eeea; color: #135c52; }
.chip.cat-bot { background: #f6dccf; color: #7a3215; }
.chip.cat-dashboard { background: #dfe1f7; color: #2e3a85; }
.chip.cat-command { background: #e7e3dc; color: #474b57; }
.toggle-row { display: flex; align-items: flex-start; gap: 12px; }
.toggle-row input { margin-top: 2px; }
.toggle-row strong { display: block; }
@media (max-width: 900px) {
  .log-entry { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}
