/* Variables */
:root {
  --primary: #5865F2;
  --primary-dark: #4752C4;
  --primary-light: #eef0ff;
  --success: #3ba55c;
  --danger: #ed4245;
  --warning: #faa61a;
  --sidebar-bg: #2f3136;
  --sidebar-text: #b9bbbe;
  --sidebar-active: #5865F2;
  --bg: #f2f3f5;
  --surface: #ffffff;
  --border: #e3e5e8;
  --text: #2e3338;
  --text-muted: #72767d;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --sidebar-w: 220px;
  --topbar-h: 60px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, button, textarea { font-family: inherit; font-size: inherit; }

/* Auth Page */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2f3136 0%, #36393f 100%);
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.auth-card__header { text-align: center; margin-bottom: 28px; }
.auth-card__header h2 { font-size: 22px; color: var(--text); margin-bottom: 6px; }
.auth-card__header p { color: var(--text-muted); font-size: 15px; }
.auth-card__footer { text-align: center; margin-top: 20px; color: var(--text-muted); font-size: 13px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}
.sidebar__brand {
  padding: 20px 16px 12px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.guild-switcher {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: rgba(255,255,255,0.08);
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #dcddde;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.guild-switcher:focus { background: rgba(255,255,255,0.12); }
.guild-switcher option { background: #2f3136; color: #dcddde; }
.sidebar__guild {
  padding: 12px 16px;
  font-size: 11px;
  color: #72767d;
  word-break: break-all;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar__nav { padding: 8px 0; flex: 1; }
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  font-size: 14px;
  border-radius: 4px;
  margin: 2px 8px;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.sidebar__link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar__link--active { background: var(--primary); color: #fff; }
.sidebar__icon { font-size: 16px; width: 20px; text-align: center; }

.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__title { font-size: 18px; font-weight: 600; }
.topbar__user { display: flex; align-items: center; gap: 10px; }
.topbar__username { font-weight: 500; }

.content { padding: 24px; flex: 1; }

/* Section */
.section { margin-top: 24px; }
.section__title { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--text); }

/* Summary */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.summary-card__value { font-size: 36px; font-weight: 700; color: var(--primary); }
.summary-card__label { margin-top: 6px; color: var(--text-muted); font-size: 13px; }

/* Quick Links */
.quick-links { display: flex; gap: 12px; flex-wrap: wrap; }
.quick-link {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
}
.quick-link:hover { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); text-decoration: none; }

/* Page Actions */
.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  font-size: 13px;
}
.table thead { background: #f8f9fa; }
.table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafafa; }
.table__actions { display: flex; gap: 6px; white-space: nowrap; }
.table__filename { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table--info th { text-transform: none; font-size: 13px; width: 140px; }

/* Form */
.form { display: flex; flex-direction: column; gap: 14px; }
.form--inline { max-width: 600px; }
.form__group { display: flex; flex-direction: column; gap: 4px; }
.form__label { font-size: 13px; font-weight: 500; color: var(--text); }
.form__input, .form__select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  width: 100%;
}
.form__input:focus, .form__select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form__input--sm, .form__select--sm { width: auto; min-width: 160px; }
.form__select[multiple] { padding: 4px; }
.form__error { color: var(--danger); font-size: 13px; padding: 8px 12px; background: #fff0f0; border-radius: 6px; border: 1px solid #fecaca; }
.form__hint { color: var(--text-muted); font-size: 12px; }
.form__note { color: var(--text-muted); font-size: 13px; padding: 6px 0; }
.required { color: var(--danger); }
.btn--full { width: 100%; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
  font-size: 14px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn--secondary { background: var(--border); color: var(--text); }
.btn--secondary:hover:not(:disabled) { background: #d0d3d8; }
.btn--ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--bg); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { background: #c0392b; }
.btn--warning { background: var(--warning); color: #fff; }
.btn--warning:hover:not(:disabled) { background: #e0901a; }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover:not(:disabled) { background: #2d8a4e; }
.btn--sm { padding: 5px 12px; font-size: 12px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge--admin { background: #ffecd2; color: #c05f00; }
.badge--user { background: #e8f4fd; color: #2176ae; }
.badge--success { background: #d4edda; color: #155724; }
.badge--error { background: #f8d7da; color: #721c24; }
.badge--disabled { background: #e9ecef; color: #6c757d; }
.badge--mode { background: #e8eaf6; color: #3949ab; }
.badge--used { background: #e9ecef; color: #495057; }
.badge--unused { background: #d1f2eb; color: #0d6832; }

/* Tag chip */
.tag-chip {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal__title { font-size: 16px; font-weight: 600; }
.modal__close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal__close:hover { background: var(--bg); }
.modal__body { padding: 20px; overflow-y: auto; overflow-x: hidden; }
.modal__footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal__message { color: var(--text); line-height: 1.6; }

/* Toast */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: var(--shadow);
  max-width: 320px;
}
.toast--visible { opacity: 1; transform: translateX(0); }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--info { background: var(--primary); }

/* Upload file list */
.upload-file-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  max-height: 180px;
  overflow-y: auto;
}
.upload-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.upload-file-item:last-child { border-bottom: none; }
.upload-file-icon { flex-shrink: 0; }
.upload-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-size { color: var(--text-muted); flex-shrink: 0; font-size: 11px; }

/* Bulk action bar */
.bulk-action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--primary-light);
  border: 1px solid #c5caff;
  border-radius: var(--radius);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.bulk-action-bar span {
  font-weight: 500;
  color: var(--primary);
  flex: 1;
  min-width: 80px;
}

/* Checkbox column */
.col-cb { width: 36px; text-align: center; padding: 8px 6px !important; }
.col-cb input[type="checkbox"] { cursor: pointer; width: 15px; height: 15px; }

/* Table scroll wrapper */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Preview modal */
.preview-img-wrap { text-align: center; }
.preview-img { max-width: 100%; max-height: 60vh; object-fit: contain; display: block; margin: 0 auto; border-radius: 4px; }

/* Invite result */
.invite-result {
  margin-top: 14px;
  background: var(--primary-light);
  border: 1px solid #c5caff;
  border-radius: var(--radius);
  padding: 14px 16px;
}
.invite-url-box { display: flex; gap: 8px; margin-top: 10px; }
.invite-url-box .form__input { flex: 1; font-size: 12px; }

/* Misc */
.loading { color: var(--text-muted); padding: 20px 0; }
.text-muted { color: var(--text-muted); padding: 16px 0; }
.text-error { color: var(--danger); padding: 16px 0; }
.link { color: var(--primary); }
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 12px; }

/* Hamburger Button */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
.hamburger:hover { background: var(--bg); }
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay--show { display: block; }

/* Topbar left group */
.topbar__left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__title { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===================== Responsive ===================== */

/* Tablet (≤ 900px): narrow sidebar */
@media (max-width: 900px) {
  :root { --sidebar-w: 190px; }
  .topbar__username { display: none; }
}

/* Mobile (≤ 680px): off-canvas sidebar */
@media (max-width: 680px) {
  /* Sidebar: hidden off-screen */
  .sidebar {
    position: fixed;
    left: calc(var(--sidebar-w) * -1);
    top: 0; bottom: 0;
    z-index: 100;
    transition: left 0.25s ease;
    box-shadow: none;
  }
  .sidebar--open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }

  /* Main wrapper takes full width */
  .main-wrapper { margin-left: 0; }

  /* Show hamburger button */
  .hamburger { display: flex; }

  /* Topbar adjustments */
  .topbar { padding: 0 14px; }
  .topbar__title { font-size: 16px; }
  .topbar__user { gap: 6px; }
  .topbar__username { display: none; }

  /* Content padding */
  .content { padding: 16px 14px; }

  /* Page actions: wrap */
  .page-actions { flex-wrap: wrap; }
  .page-actions .btn { flex: 0 0 auto; }
  .form__input--sm, .form__select--sm { width: 100%; min-width: unset; }

  /* Summary grid: 1 column on small screens */
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { padding: 16px 12px; }
  .summary-card__value { font-size: 28px; }

  /* Quick links: stack */
  .quick-links { flex-direction: column; }
  .quick-link { text-align: center; }

  /* Tables */
  .table { font-size: 12px; }
  .table th, .table td { padding: 8px 8px; }
  .table__actions { gap: 4px; }

  /* Hide non-essential columns on mobile */
  .hide-mobile { display: none; }

  /* Modal: full width bottom sheet */
  .modal-overlay { align-items: flex-end; padding: 0 0 56px 0; }
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 85vh;
  }
  .modal__body { padding: 16px; }
  .modal__footer { padding: 12px 16px; }
  .modal__header { padding: 14px 16px; }

  /* Auth card */
  .auth-card { padding: 28px 20px; margin: 16px; }

  /* Form */
  .form--inline { max-width: 100%; }

  /* Section title */
  .section__title { font-size: 15px; }

  /* Toast position */
  #toast-container { left: 12px; right: 12px; top: auto; bottom: 20px; }
  .toast { max-width: 100%; }

  /* Invite result */
  .invite-url-box { flex-direction: column; }
}

/* Extra small (≤ 400px) */
@media (max-width: 400px) {
  .summary-grid { grid-template-columns: 1fr; }
  .topbar__title { font-size: 14px; }
  .badge { display: none; }
}
