/* ── Variables ── */
:root {
  --bg-1: #1e1f22;
  --bg-2: #2b2d31;
  --bg-3: #313338;
  --bg-4: #383a40;
  --bg-5: #404249;
  --text-1: #f2f3f5;
  --text-2: #b5bac1;
  --text-3: #80848e;
  --blurple: #5865f2;
  --blurple-h: #4752c4;
  --green: #248046;
  --green-h: #1a6334;
  --red: #da373c;
  --red-h: #a12d31;
  --yellow: #f0b232;
  --border: rgba(255,255,255,0.06);
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg-3);
  color: var(--text-1);
  font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Login ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #2e3050 0%, var(--bg-1) 70%);
}

.login-card {
  background: var(--bg-2);
  border-radius: 16px;
  padding: 48px 40px;
  width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo { margin-bottom: 16px; }

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-2);
  margin-bottom: 32px;
}

.btn-discord {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--blurple);
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 28px;
  border-radius: var(--radius);
  transition: background 0.15s;
  width: 100%;
  justify-content: center;
}

.btn-discord:hover { background: var(--blurple-h); }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  text-align: left;
  font-size: 13px;
}

.alert-error { background: rgba(218,55,60,0.15); border: 1px solid rgba(218,55,60,0.4); color: #f38186; }

/* ── App layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  padding: 0;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  position: relative;
}

.nav-item:hover { background: var(--bg-4); color: var(--text-1); }
.nav-item.active { background: var(--bg-5); color: var(--text-1); }

.badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.user-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }

.user-info { flex: 1; min-width: 0; }
.user-nick { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-id { display: block; font-size: 11px; color: var(--text-3); }

.logout-btn {
  color: var(--text-3);
  text-decoration: none;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  transition: color 0.1s;
}
.logout-btn:hover { color: var(--red); }

/* ── Main ── */
.main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.tab { display: none; flex: 1; flex-direction: column; padding: 24px; }
.tab.active { display: flex; }

.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.tab-header h2 { font-size: 20px; font-weight: 700; }
.tab-actions { display: flex; gap: 8px; }

/* ── Editor layout ── */
.editor-layout {
  display: flex;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.editor-form {
  width: 400px;
  min-width: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 8px;
}

/* Scrollbar */
.editor-form::-webkit-scrollbar { width: 6px; }
.editor-form::-webkit-scrollbar-track { background: transparent; }
.editor-form::-webkit-scrollbar-thumb { background: var(--bg-5); border-radius: 3px; }

/* ── Form sections ── */
.form-section {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-2);
  margin-bottom: 12px;
}

button.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 0;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transition: color 0.1s;
}

button.section-title:hover { color: var(--text-1); }

.chevron { transition: transform 0.2s; }
.collapsible[data-collapsed="true"] .chevron { transform: rotate(-90deg); }

.form-row { margin-bottom: 10px; }
.form-row:last-child { margin-bottom: 0; }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.form-label { display: block; font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }

.char-count { font-weight: 400; text-transform: none; letter-spacing: 0; float: right; }
.char-count.warn { color: var(--yellow); }
.char-count.over { color: var(--red); }

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus, .select:focus, .textarea:focus { border-color: var(--blurple); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; cursor: pointer; }

.mono { font-family: 'Consolas', 'Monaco', 'Courier New', monospace; font-size: 13px; }

.color-row { display: flex; gap: 8px; align-items: center; }
.color-picker { width: 40px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border); cursor: pointer; padding: 2px; background: var(--bg-3); }
.color-hex-input { flex: 1; }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.checkbox { width: 16px; height: 16px; accent-color: var(--blurple); cursor: pointer; }

.radio-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; padding: 4px 0; }
.radio { accent-color: var(--blurple); cursor: pointer; }

.send-mode { display: flex; gap: 20px; margin-bottom: 12px; }

.send-section { display: flex; flex-direction: column; gap: 12px; }

/* Fields */
.field-item {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  position: relative;
}

.field-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.field-number { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; }

.field-remove {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  transition: color 0.1s;
}
.field-remove:hover { color: var(--red); }

.field-inline-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blurple); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blurple-h); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-h); }
.btn-ghost { background: var(--bg-4); color: var(--text-1); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-5); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

.mt-2 { margin-top: 8px; }

/* ── Preview panel ── */
.editor-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
}

.preview-note { font-size: 11px; color: var(--text-3); font-weight: 400; }

.discord-ui {
  background: var(--bg-3);
  border-radius: var(--radius);
  padding: 24px 16px;
  border: 1px solid var(--border);
  flex: 1;
  overflow-y: auto;
}

.discord-message-wrap { display: flex; gap: 14px; }

.discord-avatar-placeholder {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--blurple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  overflow: hidden;
}

.discord-message-content { flex: 1; min-width: 0; }
.discord-username { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.bot-tag {
  display: inline-block;
  background: var(--blurple);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 4px;
}

.discord-content-text { font-size: 15px; margin-bottom: 6px; color: var(--text-1); word-break: break-word; }

/* ── Discord Embed ── */
.discord-embed {
  display: flex;
  max-width: 520px;
  border-radius: 4px;
  overflow: hidden;
  background: #2b2d31;
  margin-top: 4px;
}

.embed-pill { width: 4px; min-width: 4px; flex-shrink: 0; border-radius: 4px 0 0 4px; }

.embed-body {
  flex: 1;
  padding: 12px 16px 12px 12px;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.embed-inner { flex: 1; min-width: 0; }

.embed-author {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}

.embed-author-icon { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }

.embed-title {
  font-size: 15px;
  font-weight: 700;
  color: #00aff4;
  margin-bottom: 6px;
  word-break: break-word;
}

.embed-title a { color: #00aff4; text-decoration: none; }
.embed-title a:hover { text-decoration: underline; }

.embed-description {
  font-size: 13.5px;
  color: #dbdee1;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
  line-height: 1.5;
}

.embed-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.embed-field { min-width: 0; }
.embed-field.full { grid-column: 1 / -1; }
.embed-field-name { font-size: 13px; font-weight: 700; color: #f2f3f5; margin-bottom: 2px; }
.embed-field-value { font-size: 13px; color: #dbdee1; white-space: pre-wrap; word-break: break-word; }

.embed-image { margin-top: 8px; }
.embed-image img { max-width: 100%; max-height: 300px; border-radius: 4px; display: block; }

.embed-thumbnail {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  align-self: flex-start;
}

.embed-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #b5bac1;
}

.embed-footer-icon { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }

/* Markdown in preview */
.embed-description strong, .embed-field-value strong { font-weight: 700; }
.embed-description em, .embed-field-value em { font-style: italic; }
.embed-description u, .embed-field-value u { text-decoration: underline; }
.embed-description s, .embed-field-value s { text-decoration: line-through; }
.embed-description code, .embed-field-value code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 85%;
  background: rgba(255,255,255,0.07);
  padding: 1px 4px;
  border-radius: 3px;
}
.embed-description a, .embed-field-value a { color: #00aff4; text-decoration: none; }
.embed-description a:hover, .embed-field-value a:hover { text-decoration: underline; }

/* ── Message list (scheduled / history) ── */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.message-card-info { flex: 1; min-width: 0; }

.message-card-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-card-meta {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}

.status-pending  { background: rgba(240,178,50,0.2); color: var(--yellow); }
.status-sent     { background: rgba(36,128,70,0.2); color: #57f287; }
.status-failed   { background: rgba(218,55,60,0.2); color: #f38186; }
.status-cancelled{ background: rgba(128,132,142,0.2); color: var(--text-3); }

.message-card-embed-preview {
  width: 200px;
  min-width: 200px;
}

.mini-embed {
  border-left: 3px solid var(--blurple);
  background: #2b2d31;
  border-radius: 2px 4px 4px 2px;
  padding: 8px 10px;
  font-size: 12px;
}

.mini-embed-title { font-weight: 700; color: #00aff4; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-embed-desc { color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.message-card-actions { display: flex; gap: 8px; align-items: flex-start; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.4; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--bg-2);
  border-radius: var(--radius);
  width: 640px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text-1); background: var(--bg-4); }

.modal .textarea { margin: 16px 20px; width: calc(100% - 40px); flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }
.modal-body { overflow-y: auto; flex: 1; padding: 16px 20px; }
.modal-wide { width: 860px; }

/* ── Templates ── */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.template-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}

.template-card:hover { border-color: var(--blurple); }

.template-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.template-card-name { font-weight: 700; font-size: 14px; word-break: break-word; }
.template-card-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.template-card-actions { display: flex; gap: 6px; margin-top: auto; }

.template-card-delete {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.1s;
}
.template-card-delete:hover { color: var(--red); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slide-in 0.2s ease;
  max-width: 360px;
}

.toast-success { background: var(--green); color: #fff; }
.toast-error   { background: var(--red); color: #fff; }
.toast-info    { background: var(--blurple); color: #fff; }

@keyframes slide-in {
  from { transform: translateX(60px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .editor-layout { flex-direction: column; }
  .editor-form { width: 100%; min-width: 0; }
  .sidebar { width: 200px; min-width: 200px; }
}

@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav { flex-direction: row; padding: 8px; }
  .main { flex: 1; }
  .tab { padding: 16px; }
}
