* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: #fafafa;
  color: #222;
  line-height: 1.6;
}

.container {
  max-width: 96rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header */
.site-header {
  background: #1a1a2e;
  color: white;
  border-bottom: 2px solid #0f3460;
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner { display: flex; justify-content: space-between; align-items: center; }
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: white;
  font-weight: 700;
}
.brand .badge {
  background: #e94560;
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 800;
}
.brand .name { font-size: 1.2rem; }
.main-nav a {
  color: #e0e0e0;
  text-decoration: none;
  margin-left: 1rem;
  font-size: 0.9rem;
  transition: color 0.2s;
}
.main-nav a:hover { color: white; }
.main-nav .btn {
  margin-left: 1rem;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}
.admin-link { color: #e94560 !important; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  font-size: 0.9rem;
}
.btn-primary {
  background: #0f3460;
  color: white;
}
.btn-primary:hover { background: #0d2a52; transform: translateY(-1px); }
.btn-secondary {
  background: #e0e0e0;
  color: #333;
}
.btn-secondary:hover { background: #c8c8c8; }
.btn-block { display: block; width: 100%; }
.btn-mini { padding: 0.2rem 0.5rem; font-size: 0.75rem; }

/* Auth pages */
.auth-page { max-width: 32rem; margin: 2rem auto; }
.auth-card {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.auth-card .subtitle { color: #666; margin-bottom: 1.5rem; }
.auth-card .auth-link {
  text-align: center;
  margin-top: 1.5rem;
}
.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: inherit;
}
.form-group input:focus {
  outline: none;
  border-color: #0f3460;
  box-shadow: 0 0 0 2px rgba(15,52,96,0.1);
}
.help-text {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.35rem;
}
.help-text strong { color: #e94560; }
.alert {
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}
.alert-error {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}
.key-input-wrapper {
  position: relative;
}
.key-input-wrapper input { padding-right: 6rem; }
.key-input-wrapper .btn {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
}
.key-explainer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #eee;
}
.key-explainer h3 { margin-bottom: 0.5rem; }
.key-explainer ol { padding-left: 1.25rem; }
.key-explainer li { margin-bottom: 0.3rem; font-size: 0.85rem; }
.warning-box {
  background: #fff3cd;
  border: 1px solid #ffe69c;
  border-radius: 4px;
  padding: 0.5rem;
  margin-top: 1rem;
}

/* Dashboard */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.dashboard-header h1 { font-size: 1.75rem; }
.greeting { color: #666; }
.documents-section { margin-top: 2rem; }
.documents-section h2 { font-size: 1.25rem; margin-bottom: 1rem; }
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.doc-card {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}
.doc-card:hover { transform: translateY(-2px); }
.doc-meta { display: flex; justify-content: space-between; align-items: flex-start; }
.doc-meta h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.doc-meta h3 a { text-decoration: none; color: #1a1a2e; }
.doc-meta h3 a:hover { text-decoration: underline; }
.doc-status {
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
}
.doc-status.draft { background: #e3f2fd; color: #1565c0; }
.doc-status.published { background: #e8f5e9; color: #2e7d32; }
.doc-status.fork { background: #f3e5f5; color: #6a1b9a; }
.doc-status.submitted { background: #fff3e0; color: #e65100; }
.doc-summary { margin: 0.5rem 0; font-size: 0.85rem; color: #555; }
.doc-footer { display: flex; justify-content: space-between; font-size: 0.75rem; color: #888; }
.fork-badge { background: #f3e5f5; color: #6a1b9a; padding: 0.1rem 0.3rem; border-radius: 2px; }
.stat-card {
  background: white;
  padding: 1rem;
  border-radius: 6px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.stat-card .stat-value { display: block; font-size: 1.75rem; font-weight: 700; color: #0f3460; }
.stat-card .stat-label { font-size: 0.8rem; color: #666; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #888;
}

/* Editor */
.editor-container { margin-bottom: 2rem; }
.editor-header h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.editor-info { display: flex; gap: 1rem; font-size: 0.85rem; color: #666; }
.community-badge { background: #e94560; color: white; padding: 0.15rem 0.4rem; border-radius: 3px; }
.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: #f8f9fa;
  border: 1px solid #eaeaea;
  border-radius: 6px;
}
.editor-content {
  min-height: 400px;
  padding: 1.5rem;
  border: 1px solid #eaeaea;
  border-radius: 6px;
  background: white;
  font-size: 1.05rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}
.editor-content:focus {
  border-color: #0f3460;
  box-shadow: 0 0 0 2px rgba(15,52,96,0.1);
}
.selection-feedback {
  padding: 0.5rem 1rem;
  background: #e8f4fd;
  border-radius: 4px;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.editor-threads { margin-top: 2rem; }
.threads-list { display: flex; flex-direction: column; gap: 0.75rem; }
.thread-item {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem;
  background: white;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.thread-author { font-weight: 500; }
.thread-closes { font-size: 0.8rem; color: #888; }
.status-consensus { color: #2e7d32; font-weight: 600; }
.status-open { color: #e65100; font-weight: 600; }

/* Community */
.community-header { margin-bottom: 2rem; }
.community-desc { color: #666; font-size: 1.1rem; }
.community-charter { margin: 1.5rem 0; }
.charter-content {
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 3px solid #0f3460;
}
.community-actions { margin: 1rem 0; }
.member-badge {
  background: #e8f5e9;
  color: #2e7d32;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  font-weight: 600;
}
.community-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #eaeaea;
}
.tab-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { border-color: #0f3460; color: #0f3460; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.member-card {
  background: white;
  padding: 1rem;
  border-radius: 6px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.member-avatar {
  width: 48px;
  height: 48px;
  background: #0f3460;
  color: white;
  border-radius: 50%;
  margin: 0 auto 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}

/* Referrals */
.referrals-header h1 { margin-bottom: 0.5rem; }
.invite-input {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}
.invite-input input { flex: 1; }
.referrals-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.referrals-table th, .referrals-table td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

/* Admin */
.admin-page .auth-card { max-width: none; }
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.admin-section { margin-bottom: 2rem; }
.admin-section h2 { margin-bottom: 1rem; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}
.admin-table th { background: #f8f9fa; }

/* --- Homepage Tree View --- */
.home-hero {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: white;
  padding: 3rem 1.5rem;
  text-align: center;
}
.hero-title { font-size: 2.5rem; margin-bottom: 0.5rem; }
.hero-subtitle { font-size: 1.1rem; color: #c0c0d0; margin-bottom: 2rem; max-width: 600px; margin-left: auto; margin-right: auto; }
.hero-actions { display: flex; gap: 1rem; justify-content: center; }

.home-tree h2 { font-size: 1.5rem; margin-bottom: 1rem; color: #1a1a2e; }
.tree-explanation { color: #666; margin-bottom: 2rem; text-align: center; }
.tree-container {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.tree-node { position: relative; }
.central-node { 
  text-align: center;
  padding: 1rem;
}
.central-node .node-badge {
  display: inline-block;
  background: #e94560;
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.75rem;
  margin-bottom: 1rem;
}
.central-node .node-card h3 { font-size: 1.3rem; color: #1a1a2e; margin-bottom: 0.3rem; }
.central-node .node-link { display: inline-block; background: #0f3460; color: white; padding: 0.4rem 0.8rem; border-radius: 4px; text-decoration: none; font-weight: 500; }

.branch-line { height: 3px; background: #ccc; margin: -1rem 0 1rem 0; position: relative; }
.branch-line::before { content: ''; position: absolute; top: 50%; left: 0; width: 20px; height: 3px; background: #0f3460; border-radius: 2px; transform: translateY(-50%); }
.branch-documents { margin-left: 30px; }

.community-node .node-badge.community {
  display: inline-block;
  background: #0f3460;
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.75rem;
}
.community-node .node-card h3 { font-size: 1.1rem; color: #1a1a2e; }
.doc-node .node-badge.doc {
  display: inline-block;
  background: #e8f5e9;
  color: #2e7d32;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.7rem;
}
.doc-node .node-card.small h4 { font-size: 0.9rem; color: #555; }

/* Home Features Grid */
.home-features h2 { font-size: 1.5rem; margin-bottom: 1rem; color: #1a1a2e; }
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}
.feature-card {
  background: white;
  padding: 1.5rem;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  text-align: center;
}
.feature-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.feature-card h3 { font-size: 1rem; margin-bottom: 0.5rem; color: #1a1a2e; }
.feature-card p { font-size: 0.85rem; color: #555; }

/* --- Community Directory --- */
.directory-header h1 { font-size: 1.5rem; }
.directory-header p { color: #666; }
.communities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.community-card {
  background: white;
  border-radius: 6px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.community-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.community-card-header h3 { font-size: 1rem; color: #1a1a2e; margin-bottom: 0.3rem; }
.community-card-desc { font-size: 0.85rem; color: #666; margin-bottom: 0.5rem; }
.community-card-meta { display: flex; gap: 1rem; font-size: 0.8rem; color: #888; margin-bottom: 0.5rem; }

/* --- Account Page --- */
.account-container { padding: 1rem 1.5rem; max-width: 96rem; margin: 0 auto; }
.account-header { display: flex; gap: 1.5rem; align-items: center; margin-bottom: 2rem; }
.account-avatar {
  width: 64px; height: 64px;
  background: #0f3460; color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700;
}
.account-info h1 { font-size: 1.5rem; margin-bottom: 0.3rem; }
.bio { font-size: 0.9rem; color: #666; margin-bottom: 0.3rem; }
.user-role {
  display: inline-block; background: #e3f2fd; color: #1565c0;
  padding: 0.2rem 0.6rem; border-radius: 3px; font-size: 0.75rem;
  text-transform: uppercase; font-weight: 600;
}
.account-stats h2, .account-sections h2 { font-size: 1.2rem; margin-bottom: 1rem; color: #1a1a2e; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.communities-list { display: flex; flex-direction: column; gap: 0.5rem; }
.community-item {
  display: flex; align-items: center; justify-content: space-between;
  background: white; padding: 0.75rem 1rem; border-radius: 6px;
}
.role-badge {
  padding: 0.15rem 0.5rem; border-radius: 3px; font-size: 0.75rem;
  font-weight: 600; text-transform: uppercase;
}
.role-badge.owner { background: #ffebee; color: #c62828; }
.role-badge.member { background: #e3f2fd; color: #1565c0; }
.joined-date { font-size: 0.75rem; color: #888; }
.invite-code-card {
  background: #f8f9fa; padding: 1rem; border-radius: 6px; margin: 1rem 0;
}
.invite-link { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.invite-link input { flex: 1; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-family: monospace; }
.activity-feed { display: flex; flex-direction: column; gap: 0.5rem; }
.activity-item {
  display: flex; gap: 0.5rem; align-items: center;
  background: white; padding: 0.75rem 1rem; border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.activity-type {
  background: #e8f4fd; color: #1976d2; padding: 0.15rem 0.5rem;
  border-radius: 3px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
}
.activity-time { font-size: 0.75rem; color: #888; margin-left: auto; }

/* --- Referrals Codes --- */
.my-invite-codes { margin: 2rem 0; }
.invite-code-item {
  background: white; padding: 1rem; border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 0.5rem;
}
.code-container { display: flex; align-items: center; gap: 0.5rem; }
.code-container code {
  font-family: 'Courier New', monospace; font-size: 0.8rem;
  background: #f5f5f5; padding: 0.3rem 0.6rem; border-radius: 4px;
}
.copy-code { font-family: inherit; font-size: 0.8rem; }
.code-info { display: flex; gap: 1rem; margin-top: 0.3rem; font-size: 0.8rem; color: #666; }
.generate-invite { margin: 2rem 0; text-align: center; }
.generate-invite .help-text { margin-top: 0.5rem; }
.referrals-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }

/* Key Guide */
.key-guide .auth-card { max-width: none; }
.key-sections .section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #eee;
}
.key-sections h2 { color: #0f3460; margin-bottom: 0.5rem; }
.key-explainer-footer {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #eee;
  color: #666;
}

/* Footer */
.site-footer {
  background: #1a1a2e;
  color: #aaa;
  text-align: center;
  padding: 1rem 0;
  margin-top: 2rem;
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; gap: 0.5rem; }
  .main-nav a { margin: 0 0.3rem; }
  .doc-grid { grid-template-columns: 1fr; }
  .admin-header { flex-direction: column; gap: 1rem; }
}
