:root {
  --bg: #050505;
  --panel: #0d0d0d;
  --panel-2: #161616;
  --border: #2a1414;
  --text: #e6e6e6;
  --muted: #888888;
  --accent: #e63946;
  --accent-2: #ff5566;
  --warn: #ffb648;
  --bad: #ff4444;
  --row-alt: #0f0f0f;
  --hover: #1f1010;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  height: 100%;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header h1 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.2px; }
.meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.meta span { margin-right: 12px; }

.controls { display: flex; gap: 8px; align-items: center; }
#search {
  width: 280px; padding: 6px 10px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; outline: none;
}
#search:focus { border-color: var(--accent); }
button {
  padding: 6px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer;
  font-size: 12px;
}
button:hover { background: var(--hover); }

nav#tabs {
  display: flex; flex-wrap: wrap; gap: 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0 6px;
}
.tab {
  padding: 8px 14px; cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--muted); font-size: 12px; user-select: none;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { color: var(--muted); font-size: 10px; margin-left: 6px; }

main { padding: 0; }

#sheet-header {
  padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
#sheet-header strong { color: var(--text); font-size: 13px; }

#grid-host {
  overflow: auto;
}

table.grid {
  border-collapse: collapse; width: 100%; font-size: 12px;
}
table.grid td {
  border: 1px solid var(--border);
  padding: 4px 8px; vertical-align: top;
  max-width: 480px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
table.grid tr:nth-child(even) td { background: var(--row-alt); }
table.grid tr.header-row td {
  background: var(--panel-2); font-weight: 600; color: var(--text);
  position: sticky; top: 0;
}
table.grid tr.section-row td {
  background: #1a0606; color: var(--accent); font-weight: 600;
}
table.grid td.empty { color: transparent; }
table.grid td.row-num {
  background: var(--panel); color: var(--muted); font-size: 10px;
  text-align: right; user-select: none; min-width: 36px;
}
table.grid td.cell-flag {
  background: var(--panel); width: 24px; text-align: center;
  user-select: none; cursor: pointer; color: var(--muted);
}
table.grid td.cell-flag:hover { color: var(--accent); }

.file-link {
  color: var(--accent-2);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-2);
  cursor: pointer;
}
.file-link:hover { color: var(--accent-2); }

mark {
  background: var(--warn); color: #000; padding: 0 2px; border-radius: 2px;
}

.hidden { display: none !important; }

aside {
  position: fixed; right: 0; top: 0; bottom: 0; width: 380px;
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 10;
  box-shadow: -4px 0 16px rgba(0,0,0,0.4);
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.drawer-head button {
  background: none; border: none; color: var(--muted); font-size: 18px; padding: 0 4px;
}
.drawer-body { padding: 14px; overflow-y: auto; flex: 1; }

#comment-target {
  padding: 8px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; margin-bottom: 10px; font-size: 11px; color: var(--muted);
  word-break: break-word;
}
#comment-target strong { color: var(--text); }
#comment-text {
  width: 100%; min-height: 140px; padding: 8px; resize: vertical;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; font-family: inherit; font-size: 12px;
}
#comment-author {
  width: 100%; padding: 6px 8px; margin-top: 8px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px;
}
#comment-submit { margin-top: 10px; width: 100%; }
#comment-status { margin-top: 8px; font-size: 11px; color: var(--accent-2); min-height: 14px; }

#feedback-list .fb-item {
  padding: 10px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; margin-bottom: 8px; font-size: 11px;
}
.fb-item .fb-meta { color: var(--muted); margin-bottom: 4px; }
.fb-item .fb-comment { white-space: pre-wrap; }

/* File modal */
#file-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  width: 92vw; height: 92vh; background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 8px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal-head #modal-filename { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head #modal-meta { color: var(--muted); font-size: 11px; }
.modal-head a, .modal-head button {
  font-size: 12px; padding: 4px 10px;
  color: var(--text); text-decoration: none;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--panel); cursor: pointer;
}
.modal-head a:hover, .modal-head button:hover { background: var(--hover); }

#modal-body {
  flex: 1; min-height: 0; display: flex; position: relative;
}
#modal-body > * {
  flex: 1; min-height: 0; width: 100%;
}
#modal-frame {
  border: none; background: white;
}
#modal-render {
  overflow: auto; background: #fafafa; color: #111; padding: 0;
}
#modal-text {
  overflow: auto; background: #050505; padding: 14px;
}
.text-preview {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: "Consolas", "Cascadia Mono", "SFMono-Regular", monospace;
  font-size: 12px; color: var(--text);
}
.text-truncated {
  background: var(--warn); color: #000; padding: 6px 10px; margin-bottom: 10px;
  border-radius: 4px; font-size: 11px;
}

#modal-loading {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px;
}

#modal-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 40px; text-align: center;
}
#modal-fallback-msg { color: var(--muted); max-width: 480px; line-height: 1.5; }
.big-dl {
  display: inline-block; padding: 10px 22px;
  background: var(--accent); color: #fff !important; font-weight: 600;
  border-radius: 4px; text-decoration: none;
}
.big-dl:hover { background: var(--accent-2); }

/* XLSX renderer */
.xlsx-tabs {
  position: sticky; top: 0; display: flex; gap: 0; flex-wrap: wrap;
  background: #e8e8e8; border-bottom: 1px solid #c0c0c0; z-index: 2;
}
.xlsx-tab {
  padding: 6px 14px; cursor: pointer; font-size: 12px;
  border-right: 1px solid #c0c0c0; user-select: none; color: #333;
}
.xlsx-tab:hover { background: #ddd; }
.xlsx-tab.active { background: white; color: #000; font-weight: 600; }
.xlsx-pane {
  padding: 12px;
}
.xlsx-pane table {
  border-collapse: collapse; font-size: 12px; color: #111;
}
.xlsx-pane td, .xlsx-pane th {
  border: 1px solid #ccc; padding: 4px 8px; vertical-align: top;
  max-width: 320px; word-wrap: break-word;
}
.xlsx-pane th { background: #f0f0f0; }

/* DOCX preview */
.docx-preview {
  padding: 24px;
  background: white;
  color: #111;
  font-family: "Calibri", "Segoe UI", system-ui, sans-serif;
}
.docx-preview .docx-wrapper {
  background: white;
  padding: 0;
}
.docx-preview section.docx {
  background: white !important;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Cesium pane */
#modal-cesium {
  position: relative; background: #000;
}
#cesium-container {
  width: 100%; height: 100%;
}
.cesium-overlay {
  position: absolute; top: 14px; left: 14px; max-width: 360px;
  background: rgba(15,18,24,0.92); color: var(--text);
  padding: 10px 14px; border-radius: 4px; border: 1px solid var(--border);
  font-size: 12px; line-height: 1.5; z-index: 50;
}
.cesium-overlay strong { color: var(--accent); display: block; margin-bottom: 6px; }
.cesium-overlay p { margin: 4px 0; }
.cesium-overlay .hint { color: var(--muted); font-size: 11px; }
.cesium-overlay.error { color: var(--bad); }

/* Modal tabs */
.modal-tabs {
  display: flex; gap: 0; flex: 1; justify-content: center;
}
.modal-tab {
  padding: 4px 14px; background: var(--panel);
  color: var(--muted); border: 1px solid var(--border); border-radius: 0;
  cursor: pointer; font-size: 12px;
}
.modal-tab:first-child { border-radius: 4px 0 0 4px; }
.modal-tab:last-child { border-radius: 0 4px 4px 0; }
.modal-tab + .modal-tab { border-left: none; }
.modal-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-tab:hover:not(.active) { background: var(--hover); color: var(--text); }

/* Bundle dialog */
#bundle-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 30;
  display: flex; align-items: center; justify-content: center;
}
.dialog-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  width: 520px; max-width: 92vw; padding: 24px;
}
.dialog-card h3 { margin: 0 0 12px 0; }
.dialog-card p { color: var(--muted); margin: 0 0 16px 0; line-height: 1.5; }
.bundle-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.bundle-opt {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px 12px; align-items: center;
  padding: 12px 14px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer;
}
.bundle-opt:has(input:checked) { border-color: var(--accent); }
.bundle-opt input { margin: 0; grid-row: span 2; }
.bundle-opt strong { font-size: 13px; }
.bundle-opt small { grid-column: 2 / 4; color: var(--muted); font-size: 11px; }
.size-pill {
  background: var(--panel); padding: 2px 10px; border-radius: 999px;
  font-size: 11px; color: var(--accent); border: 1px solid var(--border);
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.dialog-actions .primary:hover { background: var(--accent-2); }
