:root {
  --bg: #1e1f22;
  --bg-elevated: #2b2d31;
  --bg-card: #313338;
  --border: #3f4147;
  --text: #f2f3f5;
  --text-muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --danger: #ed4245;
  --danger-hover: #c13639;
  --success: #57f287;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.topbar .user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.topbar .user img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

.container.wide {
  max-width: 1200px;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 6px;
}
h2 {
  font-size: 1.2rem;
  margin: 28px 0 12px;
}
.subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
}

.breadcrumbs {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.breadcrumbs a {
  color: var(--text-muted);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.server-card,
.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.15s;
}
.server-card:hover,
.item-card:hover {
  border-color: var(--accent);
}

.server-card .name,
.item-card .name {
  font-weight: 600;
}
.item-card .meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(87, 242, 135, 0.15);
  color: var(--success);
}
.badge.muted {
  background: rgba(148, 155, 164, 0.15);
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}
.btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.secondary:hover {
  border-color: var(--accent);
  background: transparent;
}
.btn.danger {
  background: var(--danger);
}
.btn.danger:hover {
  background: var(--danger-hover);
}
.btn.small {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

form.field-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field .hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

input[type='text'],
input[type='url'],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: inherit;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea {
  resize: vertical;
  min-height: 80px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkbox-row label {
  font-weight: 500;
  color: var(--text);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.checkbox-grid .checkbox-row {
  font-size: 0.85rem;
}

.row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.row .field {
  flex: 1;
  min-width: 220px;
}

.error-banner {
  background: rgba(237, 66, 69, 0.15);
  border: 1px solid var(--danger);
  color: #ffb3b3;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 24px;
}

.question-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  gap: 12px;
}
.question-item .q-text {
  font-weight: 500;
}
.question-item .q-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
}
.login-card h1 {
  margin-bottom: 8px;
}
.login-card p {
  color: var(--text-muted);
  margin-bottom: 28px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-box .num {
  font-size: 1.8rem;
  font-weight: 700;
}
.stat-box .label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.section-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.section-nav a {
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.section-nav a:hover,
.section-nav a.active {
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

/* ==========================================================================
   App shell + sidebar
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: calc(100vh - 61px);
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 61px;
  align-self: flex-start;
  height: calc(100vh - 61px);
  overflow-y: auto;
}

.sidebar .sidebar-title {
  padding: 0 20px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active {
  background: rgba(88, 101, 242, 0.12);
  border-left-color: var(--accent);
  color: var(--text);
}

.nav-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nav-item .dot.on {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(87, 242, 135, 0.18);
}
.nav-item .dot.off {
  background: var(--text-muted);
  opacity: 0.6;
}

.app-shell .main-content {
  flex: 1;
  min-width: 0;
}

/* ==========================================================================
   Toggle switch
   ========================================================================== */

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.switch-row .switch-label {
  font-weight: 500;
  color: var(--text);
}
.switch-row .hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .track::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .track {
  background: var(--accent);
}
.switch input:checked + .track::before {
  transform: translateX(18px);
}
.switch input:disabled + .track {
  opacity: 0.5;
  cursor: not-allowed;
}

.is-disabled {
  opacity: 0.5;
}
.is-disabled input,
.is-disabled select,
.is-disabled textarea,
.is-disabled button {
  pointer-events: none;
}

/* ==========================================================================
   Pickers (searchable checkbox lists for roles/channels)
   ========================================================================== */

.picker {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.picker-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.picker-search {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.85rem;
}
.picker-search:focus {
  outline: none;
  border-color: var(--accent);
}

.picker-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.picker-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.picker-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.picker-item .role-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.picker-item.is-hidden {
  display: none;
}

/* ==========================================================================
   Status / feedback
   ========================================================================== */

.badge.warn {
  background: rgba(250, 166, 26, 0.15);
  color: #faa61a;
}

.notice {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  border: 1px solid transparent;
}
.notice.info {
  background: rgba(88, 101, 242, 0.12);
  border-color: rgba(88, 101, 242, 0.4);
  color: #c7cbf9;
}
.notice.warn {
  background: rgba(250, 166, 26, 0.12);
  border-color: rgba(250, 166, 26, 0.4);
  color: #ffd399;
}
.notice.success {
  background: rgba(87, 242, 135, 0.12);
  border-color: rgba(87, 242, 135, 0.4);
  color: #b9f7cf;
}

.field-error {
  color: var(--danger);
  font-size: 0.78rem;
}

input.invalid {
  border-color: var(--danger) !important;
}

/* ==========================================================================
   Module cards (guild home / overview grid)
   ========================================================================== */

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.15s;
}
.module-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.module-card .module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.module-card .module-icon {
  font-size: 1.3rem;
}
.module-card .module-title {
  font-weight: 600;
  color: var(--text);
  flex: 1;
}
.module-card .module-summary {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

/* ==========================================================================
   Bare inputs (number/time/color)
   ========================================================================== */

input[type='number'],
input[type='time'],
input[type='color'] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: inherit;
}
input[type='number']:focus,
input[type='time']:focus,
input[type='color']:focus {
  outline: none;
  border-color: var(--accent);
}
input[type='color'] {
  padding: 4px;
  width: 56px;
  height: 40px;
  cursor: pointer;
}

/* ==========================================================================
   Editor + live-preview split layout
   ========================================================================== */

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.editor-split .preview-col {
  position: sticky;
  top: 20px;
}
@media (max-width: 1100px) {
  .editor-split {
    grid-template-columns: 1fr;
  }
  .editor-split .preview-col {
    position: static;
  }
}

/* ==========================================================================
   Repeatable rows / time-range helper
   ========================================================================== */

.repeat-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.repeat-row .field {
  flex: 1;
  min-width: 140px;
}
.time-range {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.time-range .checkbox-row {
  margin-left: 6px;
}

/* ==========================================================================
   Discord live preview mockup
   ========================================================================== */

.dc-preview {
  background: #313338;
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'gg sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #dbdee1;
  font-size: 0.92rem;
  line-height: 1.4;
}

.dc-msg {
  display: flex;
  gap: 14px;
}
.dc-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
}
.dc-msg-body {
  flex: 1;
  min-width: 0;
}
.dc-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.dc-author {
  font-weight: 600;
  color: #f2f3f5;
}
.dc-bot-tag {
  background: var(--accent);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
}
.dc-timestamp {
  color: #949ba4;
  font-size: 0.72rem;
}

.dc-embed {
  display: flex;
  margin-top: 6px;
  max-width: 520px;
  border-radius: 4px;
  overflow: hidden;
  background: #2b2d31;
}
.dc-accent {
  width: 4px;
  flex-shrink: 0;
  background: var(--accent);
}
.dc-embed-body {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  display: flex;
  gap: 14px;
}
.dc-embed-main {
  flex: 1;
  min-width: 0;
}
.dc-embed-title {
  font-weight: 700;
  color: #f2f3f5;
  margin-bottom: 4px;
  word-break: break-word;
}
.dc-embed-desc {
  color: #dbdee1;
  white-space: pre-wrap;
  word-break: break-word;
}
.dc-embed-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}
.dc-embed-field-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: #f2f3f5;
}
.dc-embed-field-value {
  font-size: 0.85rem;
  color: #dbdee1;
  white-space: pre-wrap;
  word-break: break-word;
}
.dc-embed-thumb {
  width: 80px;
  height: 80px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: #1e1f22;
}
.dc-embed-image {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  max-height: 220px;
  border-radius: 4px;
  object-fit: cover;
  background: #1e1f22;
}
.dc-embed-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  color: #949ba4;
  font-size: 0.75rem;
}
.dc-embed-footer .dc-footer-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1e1f22;
  flex-shrink: 0;
}

.dc-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.dc-buttons .dc-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #fff;
  border: none;
  cursor: default;
}
.dc-btn-primary {
  background: var(--accent);
}
.dc-btn-secondary {
  background: #4e5058;
}
.dc-btn-success {
  background: #248046;
}
.dc-btn-danger {
  background: #da373c;
}

.dc-select {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 320px;
  background: #2b2d31;
  border: 1px solid #1e1f22;
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: #dbdee1;
}
.dc-select .dc-select-caret {
  color: #949ba4;
}

.dc-mention {
  background: rgba(88, 101, 242, 0.3);
  color: #c9cdfb;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 500;
}
.dc-code {
  background: #2b2d31;
  border: 1px solid #1e1f22;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: 'Consolas', monospace;
  font-size: 0.85em;
}
.dc-quote {
  border-left: 4px solid #4e5058;
  padding-left: 10px;
  margin: 4px 0;
  color: #b5bac1;
  display: block;
}

/* -- Emoji picker (web/views/partials/emojiPicker.ejs + web/public/js/emoji-picker.js) -- */
.emoji-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}
.emoji-picker-trigger {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.emoji-picker-trigger:hover {
  border-color: var(--accent);
}
.emoji-picker-current {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emoji-picker-caret {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.emoji-picker-clear {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  flex-shrink: 0;
}
.emoji-picker-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.emoji-picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: 300px;
  max-width: 90vw;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.emoji-picker-search {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
}
.emoji-picker-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.emoji-picker-tab {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}
.emoji-picker-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.emoji-picker-option {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 0;
  cursor: pointer;
}
.emoji-picker-option:hover {
  background: var(--bg);
  border-color: var(--border);
}
.emoji-picker-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 12px 0;
}
