:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #dfe3ec;
  --text: #1d2130;
  --muted: #646b80;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --warn: #b7791f;
  --danger: #d64545;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --gap: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --border: #2f3441;
    --text: #e7e9ef;
    --muted: #9aa1b2;
    --accent: #7983ff;
    --shadow: none;
  }
}
:root[data-theme='dark'] {
  --bg: #111318;
  --surface: #1a1d24;
  --surface-2: #232731;
  --border: #2f3441;
  --text: #e7e9ef;
  --muted: #9aa1b2;
  --accent: #7983ff;
  --shadow: none;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
body {
  font:
    15px/1.5 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a {
  color: var(--accent);
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 8px;
}
h1 {
  font-size: 22px;
}
h2 {
  font-size: 17px;
}
h3 {
  font-size: 15px;
}
p {
  margin: 0 0 8px;
}
code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.boot {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

/* Layout ------------------------------------------------------------------ */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.main {
  padding: 24px 28px 64px;
  min-width: 0;
}
.topbar {
  display: none;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 2px;
}
.nav a:hover {
  background: var(--surface-2);
}
.nav a.active {
  background: var(--accent);
  color: var(--accent-text);
}
.sidebar .bottom {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  flex: none;
  object-fit: cover;
}
.avatar.lg {
  width: 44px;
  height: 44px;
}
.guild-switch {
  width: 100%;
  margin-bottom: 16px;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 30;
    transform: translateX(-102%);
    transition: transform 0.18s ease;
    height: 100%;
    box-shadow: var(--shadow);
  }
  .shell.nav-open .sidebar {
    transform: none;
  }
  .shell.nav-open .scrim {
    display: block;
  }
  .scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 20;
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .topbar .title {
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .main {
    padding: 16px 16px 72px;
  }
}

/* Components -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: var(--gap);
}
.card > h2:first-child {
  margin-bottom: 4px;
}
.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row.spread {
  justify-content: space-between;
}
.stack > * + * {
  margin-top: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field > label {
  font-weight: 600;
  font-size: 14px;
}
.field .hint {
  font-size: 13px;
  color: var(--muted);
}
.counter {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.counter.over {
  color: var(--danger);
}

input[type='text'],
input[type='number'],
input[type='search'],
select,
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  min-height: 40px;
}
textarea {
  min-height: 110px;
  resize: vertical;
}
input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}
.btn:hover {
  background: var(--surface-2);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.ok {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
}
.btn.small {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tabs a {
  padding: 9px 14px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-weight: 600;
}
.tabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
}
.badge.pending {
  background: #f1c40f33;
  color: var(--warn);
}
.badge.approved,
.badge.on {
  background: #2ecc7133;
  color: var(--ok);
}
.badge.declined {
  background: #e74c3c33;
  color: var(--danger);
}
.badge.left,
.badge.off {
  background: var(--surface-2);
  color: var(--muted);
}
.banner {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.banner.warn {
  background: #f1c40f22;
  border: 1px solid #f1c40f66;
}
.banner.ok {
  background: #2ecc7122;
  border: 1px solid #2ecc7166;
}
.banner ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.switch {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.switch:last-child {
  border-bottom: 0;
}
.switch input {
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  flex: none;
  cursor: pointer;
  margin-top: 2px;
}
.switch input::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: left 0.15s;
}
.switch input:checked {
  background: var(--accent);
}
.switch input:checked::after {
  left: 21px;
}
.switch .label {
  font-weight: 600;
}

/* Picker */
.picker {
  position: relative;
}
.picker-btn {
  width: 100%;
  justify-content: space-between;
  font-weight: 500;
  text-align: left;
}
.picker-btn .value {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picker-pop {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 8px;
}
.picker-pop input {
  margin-bottom: 6px;
}
.picker-list {
  max-height: 280px;
  overflow-y: auto;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.picker-item:hover,
.picker-item.sel {
  background: var(--surface-2);
}
.picker-item .sub {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--muted);
}
.emoji-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
}
.chip button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0 6px;
  font-size: 15px;
  color: var(--muted);
}

/* Lists */
.list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-item:last-child {
  border-bottom: 0;
}
.list-item:hover {
  background: var(--surface-2);
}
.list-item .grow {
  flex: 1;
  min-width: 0;
}
.list-item .title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

/* Question builder */
.q-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  margin-bottom: 10px;
}
.q-item.dragging {
  opacity: 0.5;
}
.q-item.drop-target {
  outline: 2px dashed var(--accent);
}
.q-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.q-head .handle {
  cursor: grab;
  color: var(--muted);
  font-size: 18px;
  padding: 0 4px;
  user-select: none;
}
.q-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 560px) {
  .q-grid {
    grid-template-columns: 1fr;
  }
}

/* Discord-style preview */
.preview {
  background: #313338;
  color: #dbdee1;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 14px;
}
.embed {
  border-left: 4px solid #5865f2;
  background: #2b2d31;
  border-radius: 4px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.embed .e-title {
  font-weight: 700;
  color: #f2f3f5;
  margin-bottom: 4px;
}
.embed .e-desc {
  white-space: pre-wrap;
  word-break: break-word;
}
.embed .e-thumb {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
}
.embed .mention {
  background: #5865f24d;
  color: #c9cdfb;
  border-radius: 3px;
  padding: 0 2px;
}
.preview .d-btn {
  display: inline-block;
  margin-top: 10px;
  background: #5865f2;
  color: #fff;
  border-radius: 4px;
  padding: 6px 14px;
  font-weight: 600;
}

/* Detail drawer */
.drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: var(--bg);
  z-index: 51;
  overflow-y: auto;
  padding: 18px;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.2);
}
.answer {
  margin-bottom: 12px;
}
.answer .q {
  font-weight: 600;
}
.answer .a {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 4px;
}

/* Dialog + toasts */
.dialog-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dialog {
  background: var(--surface);
  border-radius: 12px;
  padding: 18px;
  width: min(440px, 100%);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}
.dialog .row {
  justify-content: flex-end;
  margin-top: 14px;
}
#toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(480px, calc(100% - 32px));
}
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
}
.toast.error {
  background: var(--danger);
  color: #fff;
}
.toast.warn {
  background: var(--warn);
  color: #fff;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th,
.table td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table-wrap {
  overflow-x: auto;
}
.stat {
  font-size: 26px;
  font-weight: 700;
}
.login {
  max-width: 420px;
  margin: 12vh auto;
  padding: 0 16px;
  text-align: center;
}
.login .card {
  padding: 28px;
}
pre.stack {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  background: var(--surface-2);
  padding: 8px;
  border-radius: 6px;
  margin: 6px 0 0;
}

.preview-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 12px 0;
}
.response-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.record-card {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.record-line {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(0, 3fr);
  gap: 10px;
  padding: 3px 0;
}
.record-line strong {
  overflow-wrap: anywhere;
}
.record-card pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 350px;
  overflow: auto;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.embed-preview {
  border-left: 4px solid var(--accent);
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px 0;
}
@media (max-width: 600px) {
  .record-line {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .row > .picker {
    width: 100%;
  }
}
.month-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.month-day {
  min-height: 95px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.month-weekday {
  text-align: center;
  padding: 5px 0;
}
.empty-day {
  opacity: 0.25;
}
.calendar-post {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  margin-top: 4px;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  overflow-wrap: anywhere;
}
@media (max-width: 600px) {
  .month-day {
    min-height: 65px;
    padding: 3px;
    font-size: 11px;
  }
  .month-calendar {
    gap: 2px;
  }
  .calendar-post {
    padding: 2px;
    font-size: 10px;
  }
}
