@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
  --bg: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  --accent: #a78bfa;
  --accent-glow: rgba(167, 139, 250, 0.3);
  --accent-gradient: linear-gradient(135deg, #a78bfa, #7c3aed);
  --text: #f1f1f7;
  --text-dim: #9494a6;
  --text-muted: #5c5c6e;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(167, 139, 250, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(124, 58, 237, 0.04) 0%, transparent 50%);
}

.view { display: none; }
.view.active { display: block; }

.inp {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.inp::placeholder { color: var(--text-muted); }
select.inp { cursor: pointer; }
textarea.inp { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(167, 139, 250, 0.2);
}
.btn-ghost:hover { background: rgba(167, 139, 250, 0.08); border-color: rgba(167, 139, 250, 0.35); }
.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.18); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-president { background: linear-gradient(135deg, rgba(234,179,8,0.3), rgba(245,158,11,0.3)); color: #fde68a; border: 1px solid rgba(234,179,8,0.4); }
.badge-r5 { background: rgba(239,68,68,0.2); color: #fca5a5; }
.badge-r4 { background: rgba(167,139,250,0.2); color: #c4b5fd; }
.badge-r3 { background: rgba(34,197,94,0.2); color: #86efac; }
.badge-r2, .badge-r1, .badge-member { background: rgba(92,92,110,0.3); color: var(--text-dim); }
.badge-admin { background: rgba(239,68,68,0.2); color: #fca5a5; }
.badge-approved { background: rgba(34,197,94,0.15); color: #86efac; border: 1px solid rgba(34,197,94,0.3); }
.badge-pending { background: rgba(167,139,250,0.15); color: #c4b5fd; border: 1px solid rgba(167,139,250,0.3); }
.badge-rejected { background: rgba(239,68,68,0.1); color: #fca5a5; border: 1px solid rgba(239,68,68,0.2); }
.badge-none { background: rgba(92,92,110,0.15); color: var(--text-muted); }

/* AUTH */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  backdrop-filter: blur(12px);
}
.auth-logo { font-size: 2.5rem; margin-bottom: 8px; }
.auth-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.auth-sub { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 24px; }
.auth-card .field { text-align: left; }
.auth-foot { margin-top: 16px; font-size: 0.85rem; color: var(--text-dim); }
.auth-foot a { color: var(--accent); }

/* HEADER */
.header {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 0;
  gap: 24px;
}
.header-left { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.header-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}
.header-sub { font-size: 0.75rem; color: var(--text-dim); margin: 0; }
.header-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
.header-tab {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  font-family: inherit;
}
.header-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.header-tab.active { color: var(--accent); background: rgba(167,139,250,0.1); }
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-user { font-size: 0.8rem; color: var(--text-dim); }

/* CONTENT */
.content {
  width: 100%;
  max-width: 1120px;
  margin: 20px auto 40px;
  padding: 0 20px;
}

/* STATS */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
stat:hover { border-color: var(--border-hover); }
.stat-num {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

/* CARD */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  overflow: hidden;
}
.card-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

/* GRID CARDS (alliances) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.card-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(12px);
  transition: all 0.2s;
}
.card-item:hover { border-color: var(--border-hover); }
.card-item-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.card-item-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; }
.card-item-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 0.8rem;
  margin-bottom: 12px;
}
.card-item-ml { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card-item-acts { display: flex; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }

/* TABLE */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 9px 14px; border-bottom: 1px solid rgba(255,255,255,0.04); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.td-name { font-weight: 600; }
.td-empty { text-align: center; padding: 40px 14px !important; color: var(--text-muted); }
.td-mono { font-family: monospace; font-size: 0.85rem; }
.td-acts { white-space: nowrap; }
.td-email { color: var(--text-dim); font-size: 0.8rem; }
.inp-sm { width: auto; padding: 4px 8px; font-size: 0.8rem; }

/* TOOLBAR */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .inp[placeholder*="Search"] { flex: 1; min-width: 160px; }
.toolbar .inp { width: auto; }

/* MODAL */
.modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-secondary);
  margin: 8vh auto;
  padding: 28px 32px;
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: slideUp 0.25s ease;
  max-height: 84vh;
  overflow-y: auto;
}
.modal-content h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 16px; }
.close-button {
  position: absolute;
  top: 16px; right: 20px;
  color: var(--text-muted);
  font-size: 1.5rem;
  font-weight: 300;
  cursor: pointer;
  line-height: 1;
  background: none;
  border: none;
  padding: 4px;
  font-family: inherit;
  transition: all 0.2s;
}
.close-button:hover { color: var(--text); transform: rotate(90deg); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* TOAST */
#toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: auto;
  animation: toastIn 0.3s ease;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}
.toast.success { background: rgba(34,197,94,0.15); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }
.toast.error { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.toast.info { background: rgba(167,139,250,0.15); border: 1px solid rgba(167,139,250,0.3); color: #c4b5fd; }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(24px); } }
.toast.removing { animation: toastOut 0.25s ease forwards; }

/* LOADING */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 768px) {
  .header { flex-wrap: wrap; gap: 12px; padding: 16px 14px 0; }
  .header-tabs { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .header-right { gap: 6px; }
  .header-user { display: none; }
  .content { padding: 0 14px; }
  .stats { grid-template-columns: repeat(2,1fr); gap: 8px; }
  .stat { padding: 14px; }
  .stat-num { font-size: 1.4rem; }
  .card-grid { grid-template-columns: 1fr; }
  .modal-content { padding: 20px 18px; margin: 2vh auto; max-height: 92vh; }

  .tw { overflow-x: visible; }
  .tw table, .tw thead, .tw tbody, .tw tr, .tw th, .tw td { display: block; }
  .tw thead { display: none; }
  .tw tr {
    padding: 12px;
    border-bottom: 1px solid var(--border);
  }
  .tw tr:last-child { border-bottom: none; }
  .tw td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border: none;
  }
  .tw td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    margin-right: 12px;
  }
  .tw td:empty::before,
  .tw td[data-label=""]::before { content: none; }
  .tw .td-acts {
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
  }
  .tw .td-name { font-size: 0.9rem; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .header { padding: 12px 10px 0; }
  .header-title { font-size: 1.1rem; }
  .header-tab { font-size: 0.8rem; padding: 6px 10px; }
  .content { padding: 0 10px; }
  .modal-content { padding: 16px 14px; margin: 1vh auto; width: 96%; border-radius: 12px; }

  .btn { padding: 10px 16px; font-size: 0.85rem; min-height: 40px; }
  .btn-sm { padding: 7px 12px; font-size: 0.8rem; min-height: 36px; }
  .inp { padding: 11px 12px; font-size: 16px; }
  select.inp { font-size: 16px; }
  .auth-card { padding: 24px 20px; }
  .tw tr { padding: 10px; }
  .tw td { padding: 4px 0; font-size: 0.82rem; }
  .tw .td-acts { gap: 4px; }
  .tw .td-acts .btn { font-size: 0.75rem; padding: 6px 10px; min-height: 32px; }
}
