:root {
  --bg: #0f1724;
  --card: #0b1220;
  --muted: #9aa4b2;
  --accent: #5865F2;
  --glass: rgba(255, 255, 255, 0.03);
  --radius: 12px;
  --gap: 16px;
  --text: #e6eef6;
  --max-width: 1400px;
  --danger: #e74c3c;
  --danger-dark: #c0392b;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

* {
  box-sizing: border-box;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
}

body {
  background: linear-gradient(180deg, #071025 0%, #071827 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

/* common flex layouts */
.topbar, .brand, .server-meta, .server-actions, .auth {
  display: flex;
}

.topbar, .brand {
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
}

.brand {
  gap: 12px;
}

/* common spacing utilities */
.app .topbar, .auth .auth-card {
  max-width: var(--max-width);
  margin: 20px auto;
  padding: 12px 18px;
}

.footer, .app .topbar {
  max-width: var(--max-width);
  margin: 18px auto;
  padding: 12px 18px;
}

.container {
  max-width: var(--max-width);
  margin: 18px auto;
  padding: 0 18px;
  display: flex;
  justify-content: center;
  gap: 18px;
}

/* card styles */
.card, .auth-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
}

.card {
  padding: 18px;
}

.auth-card {
  padding: 28px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.6);
  text-align: center;
}

.server-info {
  width: 100%;
  max-width: 900px;
}

/* typography */
.card-title {
  margin: 0 0 12px 0;
  font-size: 1rem;
  color: var(--muted);
}

.card-subtitle {
  margin: 16px 0 12px 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 16px;
}

.title {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 600;
}

.detail-title {
  margin: 0;
  font-size: 1.5rem;
  flex: 1;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* sizes (size matters) */
.logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.icon {
  width: 18px;
  height: 18px;
}

/* grid layouts */
.stat-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat {
  flex: 1;
  min-width: 140px;
  padding: 12px;
  background: var(--glass);
  border-radius: 10px;
  transition: all 0.3s ease;
  cursor: default;
}

.stat:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
  transform: translateY(-2px);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 6px;
}

.servers-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.settings-accordion {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: transform 0.12s;
}

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

.btn-primary {
  background: linear-gradient(90deg, var(--accent), #4756f0);
  border: none;
  color: white;
}

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--muted);
}

.btn-delete-item {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-delete-item:hover {
  background: var(--danger);
}

.actions .btn {
  min-width: 140px;
  justify-content: center;
}

.actions-row {
  display: none;
}

/* server cards */
.server-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.server-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  flex: 0 0 44px;
  object-fit: cover;
  background: linear-gradient(90deg, #0b1220, #071827);
}

.server-meta {
  flex-direction: column;
}

.server-name {
  font-weight: 600;
}

.server-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.server-actions {
  margin-left: auto;
  gap: 8px;
}

.server-invite, .server-manage {
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
  display: inline-block;
  transition: all 0.12s;
}

.server-invite {
  background: linear-gradient(90deg, #2ecc71, #27ae60);
}

.server-manage {
  background: linear-gradient(90deg, var(--accent), #4756f0);
}

.server-invite:hover, .server-manage:hover {
  transform: translateY(-2px);
  filter: brightness(1.03);
}

/* settings */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setting-item {
  padding: 12px;
  background: var(--glass);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.setting-label {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.setting-value {
  color: var(--text);
  font-size: 0.85rem;
  word-break: break-word;
}

.setting-value pre {
  margin: 0;
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.75rem;
  line-height: 1.3;
}

#settings-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.setting-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
  text-align: left;
}

.setting-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent);
}

.setting-button-content {
  flex: 1;
}

.setting-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.setting-summary {
  font-size: 0.85rem;
  color: var(--muted);
}

.setting-arrow {
  margin-left: 12px;
  font-size: 1.2rem;
  opacity: 0.6;
  transition: all 0.2s;
}

.setting-button:hover .setting-arrow {
  opacity: 1;
  transform: translateX(2px);
}

/* detail items */
.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-label {
  font-weight: 600;
  color: var(--muted);
}

.detail-value {
  color: var(--text);
  text-align: right;
}

.server-info-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  transition: opacity 0.3s ease;
}

.server-info-header:hover {
  opacity: 0.9;
}

.server-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.server-name-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.server-name-title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text);
}

.guild-id-small {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.success {
  color: #2ecc71;
}

/* lists */
.nested-list {
  margin: 8px 0 8px 16px;
  padding-left: 0;
  list-style: none;
}

.nested-list li {
  padding: 4px 0;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
}

.nested-list li::before {
  content: "• ";
  color: var(--accent);
  margin-right: 6px;
  font-weight: 600;
}

.nested-key {
  color: var(--accent);
  font-weight: 600;
}

/* Accordion */
.accordion-item {
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  padding: 12px;
  background: var(--glass);
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s;
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.06);
}

.accordion-title {
  color: var(--accent);
  font-weight: 600;
}

.accordion-icon {
  display: inline-block;
  transition: transform 0.2s;
  color: var(--accent);
}

.accordion-content {
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.accordion-body {
  padding: 12px;
  color: var(--text);
  font-size: 0.85rem;
}

.setting-description {
  background: rgba(88, 101, 242, 0.1);
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

/* setting detail view */
.setting-detail-view {
  margin-top: 20px;
  padding: 20px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--glass);
}

.setting-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--glass);
}

.setting-detail-header button {
  padding: 6px 12px;
  font-size: 0.9rem;
}

.setting-detail-content {
  margin-bottom: 20px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  min-height: 200px;
}

.setting-detail-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.setting-detail-actions button {
  padding: 10px 20px;
  font-size: 0.95rem;
}

#detail-cancel-btn {
  transition: opacity 0.2s, cursor 0.2s;
}

#detail-cancel-btn:hover:not(.btn-disabled) {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.3);
  color: white;
}

#detail-cancel-btn.btn-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* toggle switch */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.toggle-input {
  appearance: none;
  width: 50px;
  height: 28px;
  background: var(--danger);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.3s;
  position: relative;
  border: none;
}

.toggle-input:checked {
  background: #2ecc71;
}

.toggle-input::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: left 0.3s;
}

.toggle-input:checked::after {
  left: 24px;
}

/* role selector */
.role-selector {
  display: grid;
  gap: 10px;
  overflow-y: auto;
}

.role-selector::-webkit-scrollbar,
.dict-role-selector::-webkit-scrollbar {
  width: 8px;
}

.role-selector::-webkit-scrollbar-track,
.dict-role-selector::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.role-selector::-webkit-scrollbar-thumb,
.dict-role-selector::-webkit-scrollbar-thumb {
  background: rgba(88, 101, 242, 0.4);
  border-radius: 4px;
}

.role-selector::-webkit-scrollbar-thumb:hover,
.dict-role-selector::-webkit-scrollbar-thumb:hover {
  background: rgba(88, 101, 242, 0.6);
}

.dict-role-selector {
  margin-top: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass);
  border-radius: 4px;
  max-height: 250px;
  overflow-y: auto;
}

.role-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.role-checkbox:hover {
  background: rgba(255, 255, 255, 0.08);
}

.role-checkbox input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.role-checkbox label {
  flex: 1;
  cursor: pointer;
  margin: 0;
}

/* array list editor */
.array-list-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.array-items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 600px;
  overflow-y: auto;
  padding: 4px;
}

.array-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass);
  border-radius: 6px;
  gap: 12px;
}

.array-item-content {
  flex: 1;
}

/* dictionary item styling */
.dict-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dict-item.collapsible-item {
  padding: 0;
  max-height: 500px;
}

.dict-item-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--glass);
  transition: background 0.2s;
  user-select: none;
}

.dict-item-header:hover {
  background: rgba(255, 255, 255, 0.08);
}

.collapse-icon {
  font-size: 0.9rem;
  min-width: 16px;
  text-align: center;
  transition: transform 0.3s ease;
  display: inline-block;
}

.dict-item-title {
  flex: 1;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.dict-item-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  max-height: 400px;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
  opacity: 1;
}

.dict-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.dict-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.dict-field-input {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid var(--glass) !important;
}

.dict-field-input:focus {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: var(--accent) !important;
}

.dict-item-fields.collapsed {
  max-height: 0;
  padding: 0 12px;
  overflow: hidden;
  opacity: 0;
}

/* modals */
.modal-overlay, .alert-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.alert-modal-overlay {
  z-index: 1001;
}

.modal-content, .alert-modal {
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid var(--glass);
  border-radius: var(--radius);
  padding: 20px;
  width: 90%;
}

.modal-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.alert-modal {
  max-width: 400px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.2s ease-out;
}

.modal-content h3 {
  margin: 0 0 16px 0;
  color: var(--text);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.alert-modal-icon {
  font-size: 1.8rem;
  flex: 0 0 auto;
}

.alert-modal-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.alert-modal-message {
  color: var(--text);
  margin-bottom: 20px;
  line-height: 1.5;
  font-size: 0.95rem;
}

.alert-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.alert-modal-btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
}

/* alert type styling */
.alert-modal.info {
  border-color: rgba(88, 101, 242, 0.3);
}

.alert-modal.info .alert-modal-icon {
  color: var(--accent);
}

.alert-modal.info .alert-modal-btn {
  background: var(--accent);
  color: white;
}

.alert-modal.info .alert-modal-btn:hover {
  background: #4756f0;
  transform: translateY(-2px);
}

.alert-modal.warn {
  border-color: rgba(241, 196, 15, 0.3);
}

.alert-modal.warn .alert-modal-icon {
  color: #f1c40f;
}

.alert-modal.warn .alert-modal-btn {
  background: #f1c40f;
  color: #000;
}

.alert-modal.warn .alert-modal-btn:hover {
  background: #f39c12;
  transform: translateY(-2px);
}

.alert-modal.warn .cancel-btn {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.alert-modal.warn .cancel-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.alert-modal.warn .confirm-btn {
  background: var(--danger);
  color: white;
}

.alert-modal.warn .confirm-btn:hover {
  background: var(--danger-dark);
}

.alert-modal.error {
  border-color: rgba(231, 76, 60, 0.3);
}

.alert-modal.error .alert-modal-icon {
  color: var(--danger);
}

.alert-modal.error .alert-modal-btn {
  background: var(--danger);
  color: white;
}

.alert-modal.error .alert-modal-btn:hover {
  background: var(--danger-dark);
  transform: translateY(-2px);
}

.alert-modal.success {
  border-color: rgba(46, 204, 113, 0.3);
}

.alert-modal.success .alert-modal-icon {
  color: #2ecc71;
}

.alert-modal.success .alert-modal-btn {
  background: #2ecc71;
  color: white;
}

.alert-modal.success .alert-modal-btn:hover {
  background: #27ae60;
  transform: translateY(-2px);
}

.btn-role-add {
  transition: all 0.2s;
}

.btn-role-add:hover {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: var(--accent) !important;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.auth {
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
}

/* responsive design stuff */
@media (max-width: 880px) {
  :root {
    --max-width: 720px;
  }

  .app .topbar,
  .auth .auth-card,
  .footer {
    margin: 12px auto;
    padding: 10px 14px;
  }

  .container {
    padding: 0 14px;
    gap: 14px;
  }

  .server-card {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .server-icon {
    order: 1;
  }

  .server-meta {
    order: 2;
    width: calc(100% - 56px);
  }

  .server-actions {
    order: 3;
    width: 100%;
    margin-left: 0;
    margin-top: 8px;
    justify-content: flex-end;
  }

  .server-join {
    display: inline-block;
    width: 100%;
    text-align: center;
    padding: 10px 12px;
    box-sizing: border-box;
  }

  .server-actions > * + * {
    margin-left: 8px;
  }
}

@media (max-width: 640px) {
  :root {
    --max-width: 640px;
  }

  .title {
    font-size: 1rem;
  }

  .logo {
    width: 36px;
    height: 36px;
  }

  .card {
    padding: 14px;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .btn {
    padding: 9px 12px;
    gap: 6px;
  }

  .actions .btn {
    min-width: 120px;
  }

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

  .server-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
  }

  .server-card {
    padding: 10px;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  :root {
    --max-width: 420px;
    --gap: 12px;
  }

  .container {
    padding: 0 12px;
  }

  .topbar {
    gap: 8px;
    align-items: flex-start;
  }

  .brand {
    gap: 8px;
  }

  .logo {
    width: 32px;
    height: 32px;
  }

  .title {
    font-size: 0.95rem;
    line-height: 1.1;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  .stat {
    min-width: 120px;
    padding: 10px;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .btn {
    padding: 8px 10px;
    font-size: 0.95rem;
  }

  .actions .btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .servers-list {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .server-card {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
  }

  .server-meta {
    width: calc(100% - 56px);
  }

  .server-actions {
    width: 100%;
    margin-left: 0;
    margin-top: 6px;
  }

  .server-join {
    padding: 8px 12px;
    border-radius: 10px;
    font-weight: 600;
  }

  .footer {
    padding: 10px 12px;
    font-size: 0.85rem;
  }
}
