/* ========================================
   MERIDIAN DASHBOARD — Premium Dark Theme
   Finance-grade design system
   ======================================== */

/* --- CSS Variables (Design Tokens) --- */
:root {
  /* Core */
  --bg-primary: #0F1115;
  --bg-surface: rgba(255, 255, 255, 0.05);
  --bg-surface-elevated: rgba(255, 255, 255, 0.08);

  /* Glassmorphism */
  --glass-blur: 16px;

  /* Gold Accent */
  --gold: #C9A34A;
  --gold-hover: #d4af55;
  --gold-subtle: rgba(201, 163, 74, 0.12);

  /* Neutrals */
  --text-primary: #EAEAEA;
  --text-secondary: #A0A0A0;
  --text-muted: #707070;

  /* Borders */
  --border: rgba(255, 255, 255, 0.12);
  --border-hover: rgba(201, 163, 74, 0.35);

  /* Status */
  --success: #22c55e;
  --error: #ef4444;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);

  /* Spacing & Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* --- Login Page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  text-align: center;
  padding: 3rem;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 90%;
}

.login-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
  object-fit: contain;
}

.login-card h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-discord {
  background: #5865F2;
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.25);
}

.btn-discord:hover {
  background: #6b77f5;
}

.btn-primary {
  background: var(--gold);
  color: #0F1115;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--gold-hover);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #f87171;
}

/* --- Top Bar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.topbar-brand-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-user span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --- Container --- */
.container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.section {
  margin-bottom: 2rem;
}

.section h2 {
  margin-bottom: 1.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.section h3 {
  margin: 2rem 0 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --- Guild Grid --- */
.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.guild-card {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.guild-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.guild-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold);
  flex-shrink: 0;
}

.guild-icon img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.guild-card-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

/* --- Glass Card --- */
.glass-card {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

/* --- Forms --- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-right: 0.5rem;
  accent-color: var(--gold);
  cursor: pointer;
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="color"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color 0.15s ease;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-subtle);
}

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A8A8A' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

.file-input {
  padding: 0.75rem 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.file-input:hover {
  border-color: var(--border-hover);
}

.file-input::file-selector-button {
  padding: 0.4rem 0.8rem;
  margin-right: 0.75rem;
  background: var(--gold);
  color: #0F1115;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.file-input::file-selector-button:hover {
  background: var(--gold-hover);
}

.form-row {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* Color Input */
.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-input-wrapper input[type="color"] {
  width: 48px;
  height: 48px;
  padding: 4px;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.color-input-wrapper input[type="text"] {
  flex: 1;
  font-family: 'SF Mono', Monaco, monospace;
  text-transform: uppercase;
}

/* --- Status Messages --- */
.save-status {
  margin-left: 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--success);
}

.save-status.error {
  color: var(--error);
}

/* --- Avatar Preview --- */
.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0.75rem 0 1rem;
  border: 2px solid var(--gold);
  object-fit: cover;
}

#avatar-preview-container {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* --- TV Link Section --- */
.tv-link-section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.tv-link-section h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.tv-link-section p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.tv-url {
  display: block;
  padding: 0.75rem 1rem;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  word-break: break-all;
  font-size: 0.85rem;
  font-family: 'SF Mono', Monaco, monospace;
  color: var(--gold);
  border: 1px solid var(--border);
}

/* --- Leaderboard Customization Section --- */
.customization-section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.customization-section h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.customization-section h3 svg {
  width: 20px;
  height: 20px;
  color: var(--gold);
}

.customization-section > p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.customization-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

/* Logo Preview */
.logo-preview-wrapper {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.logo-preview {
  max-width: 120px;
  max-height: 60px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  padding: 0.5rem;
}

/* Background Style Select */
.bg-style-options {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.bg-style-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s ease;
  min-width: 80px;
}

.bg-style-option:hover {
  border-color: var(--border-hover);
}

.bg-style-option.active {
  border-color: var(--gold);
}

.bg-style-option .preview {
  width: 48px;
  height: 32px;
  border-radius: 4px;
  overflow: hidden;
}

.bg-style-option .preview.solid {
  background: #09090b;
}

.bg-style-option .preview.gradient {
  background: linear-gradient(135deg, #09090b, #1a1a2e);
}

.bg-style-option .preview.radial {
  background: radial-gradient(circle at center, #1a1a2e, #09090b);
}

.bg-style-option span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Live Preview Box */
.live-preview {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface-elevated);
}

.live-preview-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.live-preview-content {
  height: 120px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.live-preview-content .preview-logo {
  max-width: 80px;
  max-height: 40px;
  object-fit: contain;
}

.live-preview-content .preview-rank {
  position: absolute;
  bottom: 0.5rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.live-preview-content .preview-rank span {
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

/* --- Crop Modal --- */
.crop-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crop-modal-content {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
}

.crop-modal-content h3 {
  margin: 0 0 1rem;
  color: var(--gold);
}

.crop-container {
  max-height: 350px;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: #000;
}

.crop-container img {
  display: block;
  max-width: 100%;
}

.crop-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

.crop-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* --- Company Toggles --- */
.company-toggle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}

.company-toggle-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease;
}

.company-toggle-item:hover {
  border-color: var(--border-hover);
}

.company-toggle-item label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  flex: 1;
}

.company-toggle-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
}

.company-toggle-item.disabled {
  opacity: 0.5;
}

.admin-company-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.admin-company-item button {
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.admin-company-item button:hover {
  background: var(--error);
  color: white;
}

/* --- Admin Page --- */
.admin-input {
  flex: 1;
  padding: 0.6rem 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.admin-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-subtle);
}

.admin-company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}

.hierarchy-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hierarchy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease;
}

.hierarchy-row:hover {
  border-color: var(--border-hover);
}

.hierarchy-guild {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.hierarchy-guild-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--gold);
  flex-shrink: 0;
  overflow: hidden;
}

.hierarchy-guild-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hierarchy-guild-name {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hierarchy-parent {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.hierarchy-parent label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.hierarchy-parent select {
  padding: 0.45rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  min-width: 180px;
}

.hierarchy-parent select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-subtle);
}

/* --- Webhook Items --- */
.webhook-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.webhook-item-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.webhook-item-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.webhook-field label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.webhook-copy-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.webhook-copy-row code {
  background: var(--bg-surface-elevated);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 400px;
}

.webhook-token-text {
  max-width: 260px !important;
}

.webhook-payload {
  background: var(--bg-surface-elevated);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
  overflow-x: auto;
  white-space: pre;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .topbar {
    padding: 0.75rem 1rem;
  }

  .topbar-brand-text {
    font-size: 1.1rem;
  }

  .container {
    padding: 0 1rem;
    margin: 1rem auto;
  }

  .login-card {
    padding: 2rem;
  }

  .login-card h1 {
    font-size: 2rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

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

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

  .hierarchy-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .hierarchy-parent {
    width: 100%;
  }

  .hierarchy-parent select {
    flex: 1;
    min-width: 0;
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}
