/* ============================================
   SKY BOT S2 - Modern SaaS UI
   Style: Vercel + Discord Dev Portal + Railway
   ============================================ */

:root {
  /* Colors */
  --bg-primary: #0f1117;
  --bg-secondary: #161921;
  --bg-tertiary: #1c1f29;
  --bg-card: #1e2130;
  --bg-hover: #252836;
  --bg-active: #2a2d3b;

  --text-primary: #f2f3f5;
  --text-secondary: #949ba4;
  --text-muted: #6b7280;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-light: rgba(88, 101, 242, 0.15);
  --accent-border: rgba(88, 101, 242, 0.3);

  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;

  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 200ms ease;
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  min-height: 100vh;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* ============================================
   Login Page - Split Screen
   ============================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-split {
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
  max-width: 560px;
  min-height: 0;
  margin: 24px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

/* Left Panel - Brand */
.login-brand-panel {
  background: linear-gradient(135deg, #5865f2 0%, #7c3aed 50%, #a855f7 100%);
  padding: 64px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.login-brand-panel::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: pulse 8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.brand-content {
  position: relative;
  z-index: 1;
}

.brand-logo {
  margin-bottom: 24px;
}

.brand-title {
  font-size: 2.5rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.brand-tagline {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 40px;
}

.brand-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-size: 0.95rem;
}

.feature-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.brand-footer {
  position: relative;
  z-index: 1;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
}

/* Right Panel - Login Form */
.login-form-panel {
  background: var(--bg-secondary);
  padding: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-md);
}

.login-card .stat-label {
  color: var(--text-secondary);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-card .stat-value {
  color: var(--text-primary);
  font-weight: 600;
  margin-top: 2px;
}

.login-card-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.login-heading {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.login-subheading {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.discord-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 14px 24px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition);
  border: none;
  cursor: pointer;
}

.discord-login-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.4);
}

.discord-login-btn:active {
  transform: translateY(0);
}

.discord-icon {
  flex-shrink: 0;
}

.login-note {
  text-align: center;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ============================================
   Dashboard Page
   ============================================ */
.dashboard-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* Topbar */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.topbar-center {
  display: flex;
  align-items: center;
}

.guild-selector {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text-primary);
  font-size: 0.85rem;
  min-width: 200px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.guild-selector:hover,
.guild-selector:focus {
  border-color: var(--accent-border);
  outline: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.topbar-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-tertiary);
}

.topbar-username {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Toolbar */
.toolbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.toolbar-tabs {
  display: flex;
  gap: 4px;
}

.toolbar-tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.toolbar-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.toolbar-tab.active {
  color: var(--accent);
  background: var(--accent-light);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-secondary-sm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary-sm:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-remove {
  padding: 6px 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-remove:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
}

.btn-icon-sm {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon-sm:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Main Layout */
.main-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  gap: 0;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.template-actions {
  display: flex;
  gap: 4px;
}

.quick-templates {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-template-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.quick-template-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.qt-icon {
  font-size: 1rem;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Builder Area */
.builder-area {
  padding: 20px;
  overflow-y: auto;
  background: var(--bg-primary);
}

.tab-content {
  max-width: 700px;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Form Fields */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.field-grid .full-width {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="url"],
input[type="color"],
textarea,
select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input[type="color"] {
  padding: 4px;
  height: 40px;
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Buttons Builder */
.buttons-builder,
.mentions-builder {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.button-config,
.mention-config {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.config-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* Preview Panel */
.preview-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

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

.preview-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.preview-toggle {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.toggle-btn {
  padding: 4px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.toggle-btn.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.preview-card {
  flex: 1;
  background: #313338;
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-y: auto;
  min-height: 300px;
}

/* Discord Preview */
.preview-message {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-message-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-bot-avatar-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.preview-bot-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.preview-bot-tag {
  background: var(--accent);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 500;
  margin-left: 4px;
}

.preview-content {
  color: var(--text-secondary);
  font-size: 0.9rem;
  white-space: pre-wrap;
  padding-left: 46px;
}

/* Embed Preview */
.preview-embed {
  background: #2b2d31;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 16px;
  max-width: 400px;
  margin-top: 4px;
}

.preview-embed-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.preview-embed-description {
  color: var(--text-secondary);
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.preview-embed-footer {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 8px;
}

.preview-embed-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 12px;
}

.preview-embed-thumbnail {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  float: right;
  margin-left: 12px;
}

/* Buttons Preview */
.preview-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding-left: 46px;
}

.preview-button {
  background: #5865f2;
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-button.link {
  background: #4e5058;
}

/* Containers Builder */
.containers-builder {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.container-config {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.container-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.container-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.container-actions {
  display: flex;
  gap: 4px;
}

.container-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.container-item-config {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.item-type-select {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 0.85rem;
}

.item-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Template List */
.template-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.template-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.template-chip-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.template-chip-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-chip-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.template-chip-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}

.template-chip:hover .template-chip-actions {
  opacity: 1;
}

.template-chip-action-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.template-chip-action-btn:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}

.template-chip-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

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

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: slideIn 300ms ease;
  max-width: 360px;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

.toast-icon {
  flex-shrink: 0;
}

.toast-message {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.toast-close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.toast-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.toast.hiding {
  animation: slideOut 300ms ease forwards;
}

/* Send Button States */
.btn-primary.sending {
  pointer-events: none;
  opacity: 0.7;
}

.btn-primary.sending .btn-spinner {
  display: inline-block;
}

.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
  }

  .sidebar-section {
    margin-bottom: 0;
    flex: 1;
    min-width: 200px;
  }

  .preview-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .login-split {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .login-brand-panel {
    padding: 48px 32px;
  }

  .brand-title {
    font-size: 2rem;
  }

  .brand-features {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 12px;
  }

  .topbar-title {
    display: none;
  }

  .topbar-username {
    display: none;
  }

  .toolbar {
    flex-direction: column;
    height: auto;
    padding: 12px;
    gap: 12px;
  }

  .toolbar-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .btn-primary,
  .btn-secondary {
    flex: 1;
    justify-content: center;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .config-row {
    grid-template-columns: 1fr;
  }

  .login-form-panel {
    padding: 32px 24px;
  }

  .login-card {
    padding: 32px 24px;
  }
}
