/* ═══════════════════════════════════════════════
   Aegis Pantheon — Private Portal Stylesheet
   Theme: Warm Ivory / Readable
   ═══════════════════════════════════════════════ */

/* ─── Variables ─── */
:root {
  /* Backgrounds - warm ivory tones */
  --bg: #f2ede4;
  --bg-2: #eae4d8;
  --panel: #fcf9f4;
  --panel-2: #f5efe6;

  /* Text - dark warm brown, not pure black */
  --text: #2a2520;
  --muted: #6f675c;

  /* Accent */
  --gold: #b88a2e;
  --line: rgba(42,37,32,0.1);
  --red: #b85450;
  --green: #5b8a5b;
  --blue: #6a7b9c;
  --purple: #9b7eb0;
  --gold-dim: rgba(184,138,46,.1);

  /* Backward compat aliases for inline styles in pages */
  --bg2: var(--bg-2);
  --bg3: var(--panel);
  --bg4: var(--panel-2);
  --fg1: var(--text);
  --fg2: var(--muted);
  --fg3: #8a8275;
  --border: var(--line);
  --accent: var(--gold);
  --accent2: #8a6a1e;
  --accent-bg: var(--gold-dim);

  /* Fonts */
  --font-sans: 'Inter', -apple-system, 'Noto Sans SC', 'PingFang SC', sans-serif;
  --font-serif: 'Playfair Display', 'Noto Serif SC', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --radius: 4px;
  --nav-h: 52px;
}

/* ─── Reset ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }

/* ─── Typography ─── */
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 400; color: var(--text); }
h1 { font-size: 1.8rem; letter-spacing: 0.02em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; font-family: var(--font-sans); font-weight: 500; }
p { color: var(--muted); margin-bottom: .8em; font-size: 0.95rem; line-height: 1.7; }
a { color: var(--gold); text-decoration: none; transition: opacity .2s; }
a:hover { opacity: .7; }
.small { font-size: 0.82rem; color: var(--muted); letter-spacing: 0.03em; }
.gold { color: var(--gold); }
.tag {
  display: inline-block; font-size: 0.75rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--gold);
  border: 1px solid var(--line); padding: 2px 10px; border-radius: var(--radius);
}

/* ─── Portal Nav ─── */
.portal-nav {
  height: var(--nav-h); background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 24px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
.portal-nav .brand {
  font-family: var(--font-serif); font-size: 0.95rem;
  color: var(--text); letter-spacing: 0.06em;
  margin-right: 32px; white-space: nowrap;
}
.portal-nav .brand span { color: var(--gold); }
.portal-nav .nav-links {
  display: flex; gap: 4px; list-style: none; flex: 1;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.portal-nav .nav-links a {
  display: block; padding: 0 14px; height: var(--nav-h);
  line-height: var(--nav-h); font-size: 0.82rem;
  color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; transition: all .2s;
}
.portal-nav .nav-links a:hover { color: var(--text); }
.portal-nav .nav-links a.active {
  color: var(--gold); border-bottom-color: var(--gold);
}
.portal-nav .spacer { flex: 1; }
.portal-nav .logout {
  font-size: 0.9rem; color: var(--muted);
  padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  transition: all .2s;
}
.portal-nav .logout:hover { color: var(--red); border-color: var(--red); }

/* ─── Portal Body ─── */
.portal-body {
  display: flex; height: calc(100vh - var(--nav-h));
  padding-top: var(--nav-h);
}

/* ─── Sidebar ─── */
.portal-sidebar {
  width: 260px; background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto; flex-shrink: 0;
  padding: 16px 0;
}
.portal-sidebar .sidebar-title {
  font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); padding: 8px 16px 12px;
}

/* ─── Main Content ─── */
.portal-main {
  flex: 1; overflow-y: auto; padding: 24px 32px;
}

/* ─── Cards ─── */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  transition: border-color .2s;
}
.card:hover { border-color: var(--gold-dim); }
.card-title { font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.04em; }
.card-value { font-family: var(--font-serif); font-size: 2rem; color: var(--text); }
.card-value.gold { color: var(--gold); }
.card-value.green { color: var(--green); }
.card-value.red { color: var(--red); }

/* ─── Stats Bar ─── */
.stats-bar {
  display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.stat-item {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 24px; min-width: 140px;
}
.stat-num { font-family: var(--font-serif); font-size: 1.8rem; color: var(--gold); line-height: 1.2; }
.stat-label { font-size: 0.78rem; color: var(--muted); margin-top: 2px; letter-spacing: 0.04em; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; font-family: var(--font-sans); font-size: 0.85rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer;
  transition: all .2s; white-space: nowrap;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn-primary { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn-primary:hover { opacity: .85; color: #fff; }
.btn-sm { padding: 4px 12px; font-size: 0.8rem; }
.btn-red { border-color: var(--red); color: var(--red); }
.btn-red:hover { background: var(--red); color: #fff; }
.btn-green { border-color: var(--green); color: var(--green); }
.btn-green:hover { background: var(--green); color: #fff; }

/* ─── Forms ─── */
input, textarea, select {
  font-family: var(--font-sans); font-size: 0.92rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text);
  padding: 10px 14px; outline: none; transition: border-color .2s;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--gold); }
select { cursor: pointer; }
textarea { resize: vertical; min-height: 80px; }
label { font-size: 0.82rem; color: var(--muted); display: block; margin-bottom: 4px; }

/* ─── Tables ─── */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th {
  text-align: left; padding: 10px 12px; font-weight: 500;
  color: var(--muted); font-size: 0.78rem; letter-spacing: 0.04em;
  text-transform: uppercase; border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
tr:hover td { background: var(--gold-dim); }

/* ─── Tree / Member List ─── */
.tree-container { padding: 0; }
.tree-group { margin-bottom: 8px; }
.tree-group-header {
  padding: 6px 16px; font-size: 0.78rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.tree-group-header:hover { color: var(--text); }
.tree-group-children { padding-left: 8px; }
.tree-member {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px; cursor: pointer; border-radius: var(--radius);
  transition: background .15s; margin: 1px 0;
}
.tree-member:hover { background: var(--gold-dim); }
.tree-member.active { background: var(--panel-2); border-left: 2px solid var(--gold); }
.tree-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 600; flex-shrink: 0;
}
.tree-avatar.s { background: var(--gold-dim); color: var(--gold); }
.tree-avatar.a { background: rgba(91,138,91,.15); color: var(--green); }
.tree-avatar.b { background: rgba(155,126,176,.15); color: var(--purple); }
.tree-avatar.will { background: var(--gold); color: #fff; }
.tree-info { flex: 1; min-width: 0; }
.tree-name { font-size: 0.88rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-role { font-size: 0.75rem; color: var(--muted); }
.tree-loyalty { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }

/* ─── Status Dots ─── */
.status-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; }
.status-dot.active { background: var(--green); }
.status-dot.evaluating { background: var(--blue); }
.status-dot.suspend { background: var(--red); }
.status-dot.standby { background: var(--muted); }
.status-dot.pending { background: var(--gold); }
.status-dot.reform { background: var(--purple); }

/* ─── Rank Badges ─── */
.rank-badge {
  display: inline-block; padding: 1px 8px; font-size: 0.75rem;
  font-weight: 600; border-radius: var(--radius);
  letter-spacing: 0.04em;
}
.rank-badge.s { background: var(--gold-dim); color: var(--gold); }
.rank-badge.a-plus { background: rgba(91,138,91,.15); color: var(--green); }
.rank-badge.a { background: rgba(106,123,156,.15); color: var(--blue); }
.rank-badge.b-plus { background: rgba(155,126,176,.15); color: var(--purple); }
.rank-badge.b { background: rgba(184,84,80,.15); color: var(--red); }

/* ─── Score Bars ─── */
.score-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 2px; transition: width .4s; }
.score-fill.s { background: var(--gold); }
.score-fill.a { background: var(--green); }
.score-fill.b { background: var(--blue); }
.score-fill.c { background: var(--purple); }
.score-fill.d { background: var(--red); }
.score-val { font-size: 0.9rem; font-weight: 500; }
.score-val.high { color: var(--gold); }
.score-val.mid { color: var(--green); }
.score-val.low { color: var(--red); }

/* ─── Chat ─── */
.chat-box { display: flex; flex-direction: column; height: 100%; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 75%; padding: 10px 16px; border-radius: var(--radius); font-size: 0.9rem; line-height: 1.6; }
.chat-msg.user { align-self: flex-end; background: var(--gold-dim); color: var(--text); }
.chat-msg.member { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.chat-msg .msg-from { font-size: 0.75rem; color: var(--gold); margin-bottom: 4px; }
.chat-msg .msg-time { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }

/* ─── Group Chat (legacy, kept for compatibility) ─── */
.groupchat-box { display: flex; flex-direction: column; height: 100%; }
.groupchat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.gc-msg { max-width: 80%; padding: 10px 14px; border-radius: var(--radius); font-size: 0.9rem; line-height: 1.6; position: relative; }
.gc-msg.user { align-self: flex-end; background: var(--gold-dim); color: var(--text); }
.gc-msg.goddess { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.gc-msg.system { align-self: center; background: transparent; font-size: 0.78rem; color: var(--muted); padding: 4px 12px; }
.gc-msg .gc-from { font-size: 0.75rem; color: var(--gold); margin-bottom: 2px; }
.gc-msg .gc-time { font-size: 0.68rem; color: var(--muted); margin-top: 4px; }
.gc-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }

/* ─── Gallery / Member Grid ─── */
.member-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.member-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; cursor: pointer;
  transition: all .2s; text-align: center;
}
.member-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.member-card-photo {
  width: 100%; aspect-ratio: 3/4;
  border-radius: var(--radius); object-fit: cover;
  margin: 0 auto 10px; display: block; background: var(--bg-2);
}
.member-card .initial {
  font-size: 2rem; color: var(--muted); opacity: 0.4;
}
.member-card .mcard-divine { font-size: 0.72rem; color: var(--gold); font-family: var(--font-serif); margin-bottom: 2px; }
.member-card .mcard-name { font-size: 0.82rem; font-weight: 500; margin-bottom: 1px; }
.member-card .mcard-role { font-size: 0.7rem; color: var(--muted); margin-bottom: 6px; }
.member-card .mcard-sub { font-size: 0.7rem; color: var(--muted); }

/* ─── Photo Grid ─── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); cursor: pointer; transition: opacity .2s; }
.photo-grid img:hover { opacity: .8; }

/* ─── Task List ─── */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .2s;
}
.task-item:hover { border-color: var(--gold-dim); }
.task-item.pending { border-left: 3px solid var(--gold); }
.task-item.in_progress { border-left: 3px solid var(--blue); }
.task-item.completed { border-left: 3px solid var(--green); opacity: .6; }

/* ─── Panel Sections ─── */
.panel-section { margin-bottom: 24px; }
.panel-section .section-title {
  font-size: 0.82rem; color: var(--muted); margin-bottom: 12px;
  letter-spacing: 0.04em; text-transform: uppercase;
}

/* ─── Tags ─── */
.tag { display: inline-block; font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line); padding: 2px 8px; border-radius: var(--radius); margin: 2px; }

/* ─── Lightbox ─── */
.lightbox {
  display: none; position: fixed; inset: 0; background: rgba(242,237,228,.95);
  z-index: 999; align-items: center; justify-content: center;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: var(--radius); }
.lb-close { position: absolute; top: 20px; right: 24px; font-size: 1.4rem; color: var(--muted); cursor: pointer; }

/* ─── Tabs ─── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab {
  padding: 10px 20px; font-size: 0.85rem; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all .2s; user-select: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Grid Utilities ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

@media (max-width: 900px) {
  .portal-sidebar { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .portal-main { padding: 16px; }
  .portal-nav .nav-links { gap: 0; }
  .portal-nav .nav-links a { padding: 0 10px; font-size: 0.78rem; }
}
@media (max-width: 480px) {
  .stats-bar { gap: 8px; }
  .stat-item { min-width: 100px; padding: 12px 16px; }
  .member-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Empty State ─── */
.empty-state { text-align: center; padding: 48px; color: var(--muted); }
.empty-state .big { font-size: 2rem; margin-bottom: 12px; }

/* ─── Admin ─── */
.admin-layout { display: flex; height: 100%; }
.admin-sidebar { width: 240px; background: var(--bg-2); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 0; flex-shrink: 0; }
.admin-main { flex: 1; padding: 24px; overflow-y: auto; }
.admin-member-item { padding: 8px 16px; cursor: pointer; font-size: 0.88rem; color: var(--muted); transition: all .15s; }
.admin-member-item:hover { color: var(--text); background: var(--panel); }
.admin-member-item.active { color: var(--gold); background: var(--panel-2); border-left: 2px solid var(--gold); }
.editor-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.editor-card h3 { margin-bottom: 12px; }
.field-hint { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.btn-row { display: flex; gap: 8px; margin-top: 16px; }

/* ─── Search / Filter ─── */
.search-box { position: relative; }
.search-box input { padding-left: 32px; }
.search-box::before {
  content: '🔍'; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 0.8rem;
}

/* ─── Login Modal ─── */
.login-overlay {
  position: fixed; inset: 0; background: rgba(242,237,228,.95);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.login-modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 32px; width: 360px; max-width: 90vw;
}
.login-modal .brand {
  font-family: var(--font-serif); font-size: 1rem; text-align: center;
  color: var(--muted); margin-bottom: 24px; letter-spacing: 0.08em;
}
.login-modal .brand span { color: var(--gold); }
.login-modal .login-hint {
  font-size: 0.78rem; color: var(--muted); text-align: center;
  margin-bottom: 16px;
}
.login-modal input { text-align: center; margin-bottom: 12px; }
.login-modal .btn { width: 100%; justify-content: center; }
.login-modal .error { color: var(--red); font-size: 0.82rem; text-align: center; margin-top: 8px; }

/* ─── Checkbox ─── */
input[type="checkbox"] { width: auto; margin-right: 6px; }
