* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0f1724;
  --bg-light: #1a2332;
  --bg-card: #1e2a3a;
  --bg-hover: #243447;
  --text: #e8edf3;
  --text-dim: #8899aa;
  --accent: #d4a843;
  --accent-hover: #e6bc5a;
  --accent-dark: #b08930;
  --border: #2a3a4a;
  --danger: #e05555;
  --success: #4caf50;
  --blue: #4a9eff;
  --sidebar-w: 240px;
  --topbar-h: 50px;
  --panel-w: 400px;
  --radius: 8px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Screens */
.screen { display: none; } .screen.active { display: flex; height: 100vh; }
#login-screen { justify-content: center; align-items: center; background: linear-gradient(135deg, #0f1724 0%, #1a2332 50%, #0f1724 100%); }
.login-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 48px; width: 400px; text-align: center; }
.login-logo { font-size: 64px; margin-bottom: 8px; }
.login-title { font-size: 32px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.login-subtitle { color: var(--text-dim); margin-bottom: 32px; font-size: 14px; }
.login-link { display: block; margin-top: 16px; font-size: 13px; }

/* Forms */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="file"], textarea, select {
  width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; margin-bottom: 12px; outline: none; transition: border-color .2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.form-control { margin-bottom: 12px; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }
label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; margin-top: 8px; }

/* Buttons */
.btn { padding: 8px 16px; border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px; font-weight: 500; transition: all .2s; background: var(--bg-hover); color: var(--text); }
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); color: #111; } .btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; } .btn-danger:hover { background: #c04040; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }

/* Sidebar */
#sidebar { width: var(--sidebar-w); background: var(--bg-light); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; z-index: 100; }
.sidebar-header { padding: 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar-logo { font-size: 28px; }
.sidebar-title { font-size: 20px; font-weight: 700; color: var(--accent); }
.nav-list { list-style: none; padding: 8px; flex: 1; }
.nav-item { padding: 10px 14px; border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-dim); transition: all .15s; margin-bottom: 2px; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-hover); color: var(--accent); }
.nav-icon { font-size: 16px; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: auto; }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); font-size: 13px; }
.user-info { display: flex; justify-content: space-between; align-items: center; }

/* Topbar */
#topbar { height: var(--topbar-h); background: var(--bg-light); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; }
#topbar h2 { font-size: 16px; font-weight: 600; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }

/* Content */
#main-screen { flex-direction: row; }
#content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#content > header { flex-shrink: 0; }
.view { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.view.active { display: block; }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.view-header h2 { font-size: 22px; font-weight: 600; }
.help-text { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* Card Grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tree-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; cursor: pointer; transition: all .2s; }
.tree-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tree-card h3 { color: var(--accent); margin-bottom: 8px; }
.tree-card p { color: var(--text-dim); font-size: 13px; }
.tree-card .tree-meta { margin-top: 12px; font-size: 12px; color: var(--text-dim); display: flex; gap: 16px; }

/* Canvas */
#view-canvas { padding: 0; display: none; flex-direction: column; }
#view-canvas.active { display: flex; }
.canvas-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-light); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.toolbar-title { font-weight: 600; color: var(--accent); }
.toolbar-spacer { flex: 1; }
.toolbar-group { display: flex; gap: 4px; }
#tree-search { width: 180px; margin-bottom: 0; padding: 5px 10px; font-size: 12px; }
#canvas-container { flex: 1; position: relative; overflow: hidden; background: var(--bg); cursor: grab; }
#canvas-container.dragging { cursor: grabbing; }
#tree-svg { width: 100%; height: 100%; }

/* Minimap */
#minimap { position: absolute; bottom: 16px; right: 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; opacity: 0.85; }
#minimap:hover { opacity: 1; }

/* Person Panel */
.panel { position: fixed; right: -440px; top: 0; width: var(--panel-w); height: 100vh; background: var(--bg-light); border-left: 1px solid var(--border); z-index: 200; transition: right .3s ease; display: flex; flex-direction: column; }
.panel.open { right: 0; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-header h3 { font-size: 16px; color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.btn-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.btn-close:hover { color: var(--text); }

.field-group { margin-bottom: 16px; }
.field-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 2px; }
.field-value { font-size: 14px; padding: 6px 0; min-height: 28px; }
.field-value:empty::after { content: '—'; color: var(--text-dim); }
.inline-edit { background: var(--bg); border: 1px solid transparent; border-radius: 4px; padding: 4px 8px; color: var(--text); width: 100%; font-size: 14px; }
.inline-edit:hover { border-color: var(--border); }
.inline-edit:focus { border-color: var(--accent); outline: none; }

.photo-gallery { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.photo-thumb { width: 60px; height: 60px; border-radius: 6px; object-fit: cover; cursor: pointer; border: 2px solid transparent; }
.photo-thumb.profile { border-color: var(--accent); }

.rel-list { list-style: none; }
.rel-item { padding: 8px; background: var(--bg); border-radius: 6px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.rel-item a { color: var(--blue); cursor: pointer; }
.rel-type { color: var(--text-dim); font-size: 11px; text-transform: uppercase; }

.panel-section { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: none; }
.panel-section h4 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab { padding: 8px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; color: var(--text-dim); font-size: 13px; }
.tab.active { background: var(--accent); color: #111; border-color: var(--accent); }
.import-tab { display: none; } .import-tab.active { display: block; }

/* Search */
.search-form { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.search-form input { flex: 1; min-width: 150px; margin-bottom: 0; }
.search-form .btn { margin-bottom: 0; }

/* Settings */
.settings-section { max-width: 500px; background: var(--bg-card); padding: 24px; border-radius: 12px; border: 1px solid var(--border); }
.settings-section h3 { color: var(--accent); margin-bottom: 12px; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300; }
.modal-overlay.open { display: block; }
.modal { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; z-index: 301; min-width: 400px; max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal.open { display: block; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; color: var(--accent); }
.modal-body { padding: 20px; }

/* Context Menu */
.context-menu { position: fixed; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); z-index: 400; min-width: 180px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.ctx-item { padding: 8px 14px; cursor: pointer; font-size: 13px; border-radius: 4px; }
.ctx-item:hover { background: var(--bg-hover); }
.ctx-danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* Pending */
.pending-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
.pending-card h4 { color: var(--accent); margin-bottom: 8px; }
.pending-card .pending-meta { color: var(--text-dim); font-size: 12px; margin-bottom: 12px; }
.pending-actions { display: flex; gap: 8px; }

/* Table */
.preview-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13px; }
.preview-table th, .preview-table td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; }
.preview-table th { background: var(--bg-hover); color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 11px; }
.preview-table tr:hover { background: var(--bg-hover); }

/* SVG Tree Nodes */
.tree-node { cursor: pointer; }
.tree-node rect { fill: var(--bg-card); stroke: var(--border); stroke-width: 1.5; rx: 8; transition: all .15s; }
.tree-node:hover rect { stroke: var(--accent); fill: var(--bg-hover); }
.tree-node.selected rect { stroke: var(--accent); stroke-width: 2.5; }
.tree-node.drag-over rect { stroke: var(--success); stroke-width: 2.5; stroke-dasharray: 5,3; }
.tree-node text { fill: var(--text); font-family: inherit; }
.tree-node .node-name { font-size: 13px; font-weight: 600; }
.tree-node .node-dates { font-size: 10px; fill: var(--text-dim); }
.tree-node .node-photo { clip-path: circle(14px at 18px 25px); }
.tree-link { stroke: var(--border); stroke-width: 1.5; fill: none; }
.tree-link.spouse { stroke: var(--accent); stroke-dasharray: 4,3; }
.node-add-btn { cursor: pointer; opacity: 0; transition: opacity .2s; }
.tree-node:hover .node-add-btn { opacity: 1; }
.node-add-btn circle { fill: var(--accent); }
.node-add-btn text { fill: #111; font-size: 14px; font-weight: bold; }
.collapse-btn { cursor: pointer; }
.collapse-btn circle { fill: var(--bg-hover); stroke: var(--border); }
.collapse-btn text { fill: var(--text-dim); font-size: 12px; }

/* Generation colors */
.gen-0 rect { fill: #1a2a3a; } .gen-1 rect { fill: #1a2a35; } .gen-2 rect { fill: #1a3535; } .gen-3 rect { fill: #2a2a35; } .gen-4 rect { fill: #2a1a35; }
.gen-0 .node-accent { fill: var(--accent); } .gen-1 .node-accent { fill: #5ba3cf; } .gen-2 .node-accent { fill: #5bcf8a; } .gen-3 .node-accent { fill: #cf8a5b; } .gen-4 .node-accent { fill: #cf5b8a; }

/* Responsive */
@media (max-width: 768px) {
  .hamburger { display: block; }
  #main-screen { flex-direction: column; }
  #sidebar { position: fixed; left: -260px; width: 260px; height: 100vh; z-index: 200; transition: left .3s; }
  #sidebar.open { left: 0; }
  #content { width: 100vw; }
  .panel { width: 100vw; right: -100vw; }
  .panel.open { right: 0; }
  .modal { min-width: 90vw; }
  #topbar { flex-wrap: wrap; gap: 4px; }
  #topbar .topbar-title { font-size: 14px; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #minimap { display: none !important; }
  .trees-grid { padding: 12px; }
  .tree-card { margin: 0; }
  .view-content { padding: 12px; }
}

.tree-card { position: relative; }
.btn-delete-tree {
  position: absolute; top: 12px; right: 12px;
  background: rgba(220,53,69,0.15); border: 1px solid rgba(220,53,69,0.3);
  color: #dc3545; width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: 16px; line-height: 1; display: flex;
  align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-delete-tree:hover { background: #dc3545; color: white; }

/* ==================== MOBILE OPTIMIZATION ==================== */

/* Prevent zoom on input focus (iOS) */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px !important; }
}

/* Touch-friendly sizing */
@media (max-width: 768px) {
  /* Login */
  .login-container { width: 90vw; padding: 32px 24px; }
  .login-title { font-size: 28px; }
  
  /* Sidebar */
  .nav-item { padding: 14px 20px; font-size: 15px; }
  .sidebar-header { padding: 16px; }
  
  /* Tree cards */
  .tree-card { padding: 16px; }
  .trees-grid { grid-template-columns: 1fr; gap: 12px; padding: 16px; }
  
  /* Top bar */
  #topbar { padding: 8px 12px; }
  .topbar-actions .btn { padding: 6px 10px; font-size: 12px; }
  
  /* Canvas toolbar */
  .canvas-toolbar { padding: 6px 8px; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .canvas-toolbar .btn { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
  
  /* Person panel - full screen on mobile */
  .panel { width: 100vw; right: -100vw; }
  .panel.open { right: 0; }
  .panel-header { padding: 12px 16px; }
  .panel-body { padding: 16px; }
  .field-group { margin-bottom: 10px; }
  .field-group label { font-size: 12px; margin-bottom: 3px; }
  .inline-edit { padding: 10px; font-size: 15px; }
  
  /* Buttons - larger tap targets */
  .btn { min-height: 44px; min-width: 44px; }
  .btn-sm { min-height: 36px; min-width: 36px; padding: 8px 12px; }
  
  /* Modal */
  .modal { min-width: 92vw; max-height: 85vh; overflow-y: auto; }
  .modal input, .modal select, .modal textarea { padding: 12px; }
  .modal .btn { padding: 12px; }
  
  /* Node add buttons - bigger on mobile */
  .node-add-btn circle { r: 12; }
  .node-add-btn text { font-size: 16px; }
  
  /* Context menu */
  #context-menu { min-width: 180px; }
  #context-menu div { padding: 14px 16px; font-size: 15px; }
  
  /* Search */
  .search-bar { flex-direction: column; }
  .search-bar input { width: 100%; }
  
  /* Import */
  .import-textarea { min-height: 200px; font-size: 14px; }
  
  /* View header */
  .view-header { flex-direction: column; gap: 8px; align-items: flex-start; }
  
  /* Photo gallery */
  .photo-gallery { gap: 6px; }
  .photo-thumb { width: 60px; height: 60px; }
  
  /* Overlay for sidebar on mobile */
  .sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 199; }
  .sidebar-overlay.active { display: block; }
}

/* Small phones */
@media (max-width: 380px) {
  .login-container { padding: 24px 16px; }
  .panel-body { padding: 12px; }
  .canvas-toolbar { flex-wrap: nowrap; }
}

/* Landscape phone */
@media (max-height: 500px) and (max-width: 900px) {
  .panel { width: 60vw; right: -60vw; }
  .panel.open { right: 0; }
  #sidebar { width: 200px; }
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  #topbar { padding-top: env(safe-area-inset-top); }
  #sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .panel { padding-top: env(safe-area-inset-top); }
}

/* Smooth scrolling everywhere */
* { -webkit-overflow-scrolling: touch; }

/* Disable text selection on interactive elements */
.node-group, .node-add-btn, .collapse-btn, .minimap { 
  -webkit-user-select: none; user-select: none; 
  -webkit-touch-callout: none;
}

/* SVG canvas touch */
#tree-svg { touch-action: none; }

/* Always show add buttons on touch devices */
@media (hover: none), (pointer: coarse) {
  .node-add-btn { opacity: 0.7 !important; }
  .node-add-btn:active { opacity: 1 !important; transform: scale(1.2); }
}

/* ==================== LIGHT MODE ==================== */
body.light-mode {
  --bg: #f5f5f0;
  --bg-light: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0eeea;
  --text: #1a1a1a;
  --text-dim: #666666;
  --border: #d4d0c8;
  --accent: #5a7c65;
  --accent-hover: #4a6955;
  --danger: #c0392b;
  --node-bg: #ffffff;
  --node-border: #b8c4b8;
  --node-selected: #5a7c65;
}
body.light-mode #login-screen {
  background: linear-gradient(135deg, #f5f5f0 0%, #e8e4dc 50%, #f5f5f0 100%);
}
body.light-mode .login-container {
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
body.light-mode .btn-primary {
  background: var(--accent);
  color: #fff;
}
body.light-mode .btn-primary:hover {
  background: var(--accent-hover);
}
body.light-mode .node-rect { fill: var(--node-bg); stroke: var(--node-border); }
body.light-mode .node-group.selected .node-rect { stroke: var(--node-selected); stroke-width: 3; }
body.light-mode .inline-edit {
  background: #f8f7f5;
  border-color: #d4d0c8;
  color: #1a1a1a;
}
body.light-mode .canvas-toolbar {
  background: #ffffff;
  border-color: #d4d0c8;
}
body.light-mode #context-menu {
  background: #ffffff;
  border-color: #d4d0c8;
}
body.light-mode #context-menu div:hover {
  background: #f0eeea;
}
body.light-mode .tree-card {
  background: #ffffff;
  border-color: #d4d0c8;
}
body.light-mode .tree-card:hover {
  border-color: var(--accent);
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }

/* Fix mobile toolbar and canvas */
@media (max-width: 768px) {
  #view-canvas { overflow: hidden; }
  .canvas-toolbar {
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 8px;
    min-height: auto;
  }
  .canvas-toolbar .toolbar-spacer { display: none; }
  .canvas-toolbar input[type="text"] { 
    width: 100%; order: 10; 
    margin: 4px 0 0; padding: 8px;
  }
  .toolbar-group { 
    display: flex; gap: 2px; 
  }
  .toolbar-group .btn { 
    padding: 4px 8px; min-height: 34px; min-width: 34px; font-size: 14px; 
  }
  .canvas-toolbar .btn-sm { 
    padding: 4px 8px; min-height: 34px; font-size: 12px; 
  }
  #canvas-container { 
    flex: 1; 
    min-height: 0;
  }
  /* Ensure SVG has padding so nodes at top arent clipped */
  #tree-svg { padding-top: 30px; }
}

/* Light mode - override generation node colors */
body.light-mode .gen-0 rect { fill: #f8f6f0; stroke: #c8c0b0; }
body.light-mode .gen-1 rect { fill: #f0f4f8; stroke: #b0c0d0; }
body.light-mode .gen-2 rect { fill: #f0f8f4; stroke: #b0d0c0; }
body.light-mode .gen-3 rect { fill: #f8f4f0; stroke: #d0c0b0; }
body.light-mode .gen-4 rect { fill: #f8f0f4; stroke: #d0b0c0; }
body.light-mode .gen-0 .node-accent { fill: #5a7c65; }
body.light-mode .gen-1 .node-accent { fill: #4a7a9a; }
body.light-mode .gen-2 .node-accent { fill: #4a9a6a; }
body.light-mode .gen-3 .node-accent { fill: #9a7a4a; }
body.light-mode .gen-4 .node-accent { fill: #9a4a7a; }

/* Light mode node text */
body.light-mode .node-name { fill: #1a1a1a; }
body.light-mode .node-dates { fill: #555555; }
body.light-mode .node-group text { fill: #1a1a1a; }
body.light-mode .node-group .node-dates { fill: #666666; }

/* Light mode lines */
body.light-mode .tree-line { stroke: #999; }
body.light-mode .spouse-line { stroke: #b88; }

/* Light mode add buttons */
body.light-mode .node-add-btn circle { fill: #5a7c65; }
body.light-mode .node-add-btn text { fill: #fff; }

/* Light mode toolbar */
body.light-mode .canvas-toolbar .btn { background: #e8e4dc; color: #333; border-color: #d0ccc4; }
body.light-mode .canvas-toolbar .btn:hover { background: #d8d4cc; }

/* Light mode sidebar */
body.light-mode #sidebar { background: #fafaf8; border-color: #d4d0c8; }
body.light-mode .nav-item:hover { background: #f0eeea; }
body.light-mode .nav-item.active { background: #e8e4dc; color: #5a7c65; }

/* Light mode topbar */
body.light-mode #topbar { background: #ffffff; border-color: #d4d0c8; }
body.light-mode .hamburger { color: #333; }

/* Light mode search */
body.light-mode input, body.light-mode select, body.light-mode textarea {
  background: #ffffff; border-color: #d4d0c8; color: #1a1a1a;
}

/* Light mode panel */
body.light-mode .panel { background: #fafaf8; border-color: #d4d0c8; }
body.light-mode .panel-section { border-color: #e8e4dc; }

/* Sidebar overlay */
#sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}
#sidebar-overlay.active { display: block; }

/* ==================== CONTRIBUTIONS PANEL ==================== */
.contributions-panel {
  position: fixed;
  right: -380px;
  top: 0;
  width: 350px;
  height: 100vh;
  background: var(--bg-light);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right .3s ease;
  display: flex;
  flex-direction: column;
}
.contributions-panel.open { right: 0; }

.contributions-toolbar {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.contributions-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.contrib-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 14px;
  line-height: 1.6;
}

/* Entry */
.contrib-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color .2s;
}
.contrib-entry:hover { border-color: var(--accent); }

.contrib-text-dump { border-left: 3px solid var(--blue); }
.contrib-changelog { border-left: 3px solid var(--border); }

.contrib-header {
  padding: 10px 12px;
  cursor: pointer;
}

.contrib-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.contrib-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-blue { background: rgba(74,158,255,0.2); color: var(--blue); }
.badge-green { background: rgba(76,175,80,0.2); color: var(--success); }
.badge-yellow { background: rgba(255,193,7,0.2); color: #ffc107; }
.badge-red { background: rgba(224,85,85,0.2); color: var(--danger); }

.contrib-user {
  font-size: 12px;
  color: var(--text-dim);
}

.contrib-date {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}

.contrib-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.contrib-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.contrib-expand-icon {
  font-size: 12px;
  color: var(--text-dim);
  transition: transform .2s;
}
.contrib-entry.expanded .contrib-expand-icon { transform: rotate(90deg); }

.contrib-affected {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.contrib-person-link {
  color: var(--blue);
  cursor: pointer;
}
.contrib-person-link:hover { text-decoration: underline; }

/* Body - hidden by default */
.contrib-body {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
}
.contrib-entry.expanded .contrib-body { display: block; padding-top: 10px; }

.contrib-content {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.contrib-text-dump .contrib-content {
  background: var(--bg);
  padding: 10px;
  border-radius: 6px;
  font-family: 'Georgia', serif;
  max-height: 400px;
}

.contrib-fields {
  font-size: 12px;
  color: var(--text-dim);
}

.contrib-field {
  display: block;
  font-size: 12px;
  padding: 2px 0;
}

.contrib-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Mobile */
@media (max-width: 768px) {
  .contributions-panel {
    width: 100vw;
    right: -100vw;
  }
  .contributions-panel.open { right: 0; }
  .contrib-header { padding: 14px 16px; }
  .contrib-actions .btn { min-height: 44px; }
}
