:root {
  --amzn-orange: #ff9900;
  --amzn-dark: #232f3e;
  --amzn-light: #f5f7fa;
  --sidebar-width: 360px;
  --highlight-yellow: rgba(255, 235, 59, 0.35);
  --highlight-blue: rgba(33, 150, 243, 0.2);
  --highlight-red: rgba(244, 67, 54, 0.2);
  --highlight-green: rgba(76, 175, 80, 0.2);
  --highlight-purple: rgba(156, 39, 176, 0.2);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--amzn-light); color: #1a1a1a; }

/* ── Header ── */
.header { background: var(--amzn-dark); color: #fff; padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; }
.header h1 { font-size: 17px; font-weight: 600; }
.header h1 span { color: var(--amzn-orange); }
.hdr-actions { display: flex; gap: 8px; align-items: center; }
.hdr-actions select, .hdr-actions button { padding: 5px 12px; border-radius: 4px; border: 1px solid #555; background: #37475a; color: #fff; font-size: 13px; cursor: pointer; }
.hdr-actions button:hover { background: var(--amzn-orange); border-color: var(--amzn-orange); color: var(--amzn-dark); }

/* ── Stepper ── */
.stepper { display: flex; justify-content: center; gap: 4px; padding: 12px 16px; background: #fff; border-bottom: 1px solid #e0e0e0; flex-wrap: wrap; }
.stp { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 18px; font-size: 12px; font-weight: 500; cursor: pointer; background: #e9ecef; color: #666; transition: .2s; }
.stp.active { background: var(--amzn-orange); color: #fff; }
.stp.done { background: #28a745; color: #fff; }
.stp-n { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; background: rgba(255,255,255,.3); }
.stp-arrow { color: #ccc; font-size: 16px; }

/* ── Layout ── */
.layout { display: flex; height: calc(100vh - 100px); }
.doc-area { flex: 1; overflow-y: auto; background: #fff; position: relative; }
.sidebar { width: var(--sidebar-width); min-width: var(--sidebar-width); border-left: 1px solid #e0e0e0; display: flex; flex-direction: column; background: #fafbfc; }
.sidebar.hidden { display: none; }

/* ── Upload ── */
.upload-zone { max-width: 560px; margin: 60px auto; border: 2px dashed #ccc; border-radius: 10px; padding: 48px 32px; text-align: center; cursor: pointer; transition: .2s; }
.upload-zone:hover, .upload-zone.over { border-color: var(--amzn-orange); background: #fff8ee; }
.upload-zone h3 { margin-bottom: 6px; }
.upload-zone p { color: #888; font-size: 14px; }
.upload-zone input[type=file] { display: none; }

/* ── Rendered Document (Quip-like) ── */
.doc-render {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 48px 80px;
  font-size: 15px;
  line-height: 1.75;
  color: #1a1a1a;
}
.doc-render h1 { font-size: 26px; margin: 28px 0 12px; border-bottom: 2px solid #eee; padding-bottom: 6px; }
.doc-render h2 { font-size: 21px; margin: 24px 0 10px; }
.doc-render h3 { font-size: 17px; margin: 18px 0 8px; }
.doc-render p { margin: 8px 0; }
.doc-render ul, .doc-render ol { margin: 8px 0 8px 24px; }
.doc-render li { margin: 4px 0; }
.doc-render strong { font-weight: 700; }
.doc-render em { font-style: italic; }
.doc-render code { background: #f1f3f5; padding: 1px 5px; border-radius: 3px; font-size: 13px; }
.doc-render pre { background: #f8f9fa; padding: 14px; border-radius: 6px; overflow-x: auto; font-size: 13px; margin: 10px 0; }
.doc-render pre code { background: none; padding: 0; }
.doc-render blockquote { border-left: 3px solid var(--amzn-orange); padding-left: 14px; color: #555; margin: 10px 0; }
.doc-render table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
.doc-render th, .doc-render td { border: 1px solid #ddd; padding: 8px 10px; text-align: left; }
.doc-render th { background: #f5f7fa; font-weight: 600; }
.doc-render hr { border: none; border-top: 1px solid #e0e0e0; margin: 20px 0; }
/* Word/docx specific styles */
.doc-render .doc-title { font-size: 28px; color: var(--amzn-dark); border-bottom: 3px solid var(--amzn-orange); }
.doc-render img { max-width: 100%; height: auto; margin: 12px 0; }
.doc-render sup { font-size: 0.75em; vertical-align: super; }
.doc-render sub { font-size: 0.75em; vertical-align: sub; }
/* Preserve Word spacing and indentation */
.doc-render p + p { margin-top: 10px; }
.doc-render ul ul, .doc-render ol ol { margin-top: 2px; margin-bottom: 2px; }
.doc-render li > p { margin: 2px 0; }

/* ── Inline comment highlights ── */
.cm-highlight {
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.cm-highlight:hover { filter: brightness(.95); }
.cm-highlight[data-tag="highlight"] { background: var(--highlight-yellow); border-color: #fbc02d; }
.cm-highlight[data-tag="question"] { background: var(--highlight-blue); border-color: #1976d2; }
.cm-highlight[data-tag="issue"] { background: var(--highlight-red); border-color: #d32f2f; }
.cm-highlight[data-tag="approved"] { background: var(--highlight-green); border-color: #388e3c; }
.cm-highlight[data-tag="revision"] { background: var(--highlight-purple); border-color: #7b1fa2; }
.cm-highlight.active { outline: 2px solid var(--amzn-orange); outline-offset: 1px; }
/* Comment icon badge */
.cm-highlight::after {
  content: attr(data-count);
  position: absolute;
  top: -8px; right: -8px;
  background: var(--amzn-orange);
  color: #fff;
  font-size: 9px; font-weight: 700;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.cm-highlight[data-count="1"]::after { content: "💬"; background: none; font-size: 12px; width: auto; height: auto; }

/* ── Inline Comment Popup ── */
.comment-popup {
  display: none;
  position: absolute;
  z-index: 100;
  width: 320px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.15);
  padding: 12px;
}
.comment-popup.show { display: block; }
.cp-tags { display: flex; gap: 5px; margin-bottom: 8px; flex-wrap: wrap; }
.cp-tag {
  padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600;
  cursor: pointer; border: 2px solid transparent; transition: .15s;
}
.cp-tag:hover, .cp-tag.sel { border-color: var(--amzn-dark); transform: scale(1.05); }
.cp-tag.t-hl { background: var(--highlight-yellow); color: #856404; }
.cp-tag.t-qu { background: var(--highlight-blue); color: #004085; }
.cp-tag.t-is { background: var(--highlight-red); color: #721c24; }
.cp-tag.t-ap { background: var(--highlight-green); color: #155724; }
.cp-tag.t-rv { background: var(--highlight-purple); color: #4a235a; }
.cp-input { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 13px; resize: vertical; min-height: 56px; margin-bottom: 8px; }
.cp-btns { display: flex; justify-content: flex-end; gap: 6px; }
.cp-btns button { padding: 5px 14px; border-radius: 4px; font-size: 12px; cursor: pointer; border: 1px solid #ddd; }
.cp-btns .save { background: var(--amzn-orange); color: #fff; border-color: var(--amzn-orange); font-weight: 600; }

/* ── Sidebar ── */
.sb-head {
  padding: 10px 14px; border-bottom: 1px solid #e0e0e0; font-weight: 600; font-size: 14px;
  display: flex; justify-content: space-between; align-items: center; background: #fff; position: sticky; top: 0; z-index: 2;
}
.sb-head button { padding: 4px 10px; font-size: 11px; border-radius: 4px; border: 1px solid #ddd; background: #fff; cursor: pointer; }
.sb-head button:hover { background: var(--amzn-orange); color: #fff; border-color: var(--amzn-orange); }
.sb-filters { display: flex; gap: 4px; padding: 8px 10px; border-bottom: 1px solid #e0e0e0; flex-wrap: wrap; background: #fff; }
.sb-f { padding: 2px 8px; border-radius: 10px; font-size: 10px; border: 1px solid #ddd; background: #fff; cursor: pointer; }
.sb-f.on { background: var(--amzn-dark); color: #fff; border-color: var(--amzn-dark); }
.sb-list { flex: 1; overflow-y: auto; padding: 8px; }

/* ── Comment Card ── */
.cc {
  background: #fff; border: 1px solid #e0e0e0; border-radius: 6px; padding: 10px 12px;
  margin-bottom: 8px; font-size: 13px; cursor: pointer; transition: box-shadow .15s;
}
.cc:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.cc.resolved { opacity: .45; }
.cc.active { border-color: var(--amzn-orange); box-shadow: 0 0 0 2px rgba(255,153,0,.25); }
.cc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.cc-tag { padding: 1px 7px; border-radius: 8px; font-size: 10px; font-weight: 600; }
.cc-meta { font-size: 11px; color: #888; }
.cc-text { margin: 4px 0; word-break: break-word; }
.cc-quote { font-size: 12px; color: #666; background: #f8f9fa; padding: 4px 8px; border-radius: 3px; margin-bottom: 6px; border-left: 3px solid #ddd; max-height: 40px; overflow: hidden; }
.cc-replies { margin-top: 6px; padding-left: 10px; border-left: 2px solid #eee; }
.cc-reply { font-size: 12px; margin-bottom: 4px; }
.cc-reply b { color: #555; }
.cc-reply-box { display: flex; gap: 4px; margin-top: 6px; }
.cc-reply-box input { flex: 1; padding: 4px 8px; font-size: 12px; border: 1px solid #ddd; border-radius: 3px; }
.cc-reply-box button { padding: 4px 8px; font-size: 11px; border: none; background: var(--amzn-dark); color: #fff; border-radius: 3px; cursor: pointer; }
.cc-actions { display: flex; gap: 6px; margin-top: 6px; }
.cc-actions button { padding: 2px 8px; font-size: 11px; border: 1px solid #ddd; border-radius: 3px; background: #fff; cursor: pointer; }
.cc-actions button:hover { background: #f0f0f0; }

/* ── AI Summary ── */
.ai-box { background: #fff; border: 1px solid #e0e0e0; border-radius: 8px; padding: 14px; margin: 16px; }
.ai-box h3 { font-size: 14px; margin-bottom: 8px; }
.ai-box pre { white-space: pre-wrap; font-size: 13px; line-height: 1.6; background: #f8f9fa; padding: 12px; border-radius: 4px; }
.ai-loading { display: flex; align-items: center; gap: 8px; color: #666; font-size: 13px; padding: 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid #ddd; border-top-color: var(--amzn-orange); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Rich Editor Toolbar ── */
.rich-toolbar {
  display: flex; gap: 4px; padding: 8px 12px; background: #fff; border-bottom: 1px solid #e0e0e0;
  flex-wrap: wrap; align-items: center; position: sticky; top: 0; z-index: 10;
  max-width: 820px; margin: 0 auto;
}
.rich-toolbar button {
  padding: 4px 8px; border: 1px solid #ddd; border-radius: 3px; background: #fff;
  font-size: 13px; cursor: pointer; min-width: 28px; text-align: center;
}
.rich-toolbar button:hover { background: #f0f0f0; }
.rich-toolbar button.on { background: var(--amzn-dark); color: #fff; border-color: var(--amzn-dark); }
.rich-toolbar select { padding: 4px 6px; border: 1px solid #ddd; border-radius: 3px; font-size: 12px; cursor: pointer; }
.rich-toolbar .sep { width: 1px; height: 20px; background: #ddd; margin: 0 4px; }

/* ── Editable doc area ── */
.doc-render[contenteditable="true"] {
  outline: none;
  min-height: 500px;
  border: 1px solid transparent;
  cursor: text;
}
.doc-render[contenteditable="true"]:focus { border-color: #e0e0e0; }
.doc-render[contenteditable="true"] s, .doc-render[contenteditable="true"] strike { text-decoration: line-through; color: #999; }
/* Links always look clickable */
.doc-render a { color: #0073bb; text-decoration: underline; cursor: pointer; }
.doc-render a:hover { color: #ff9900; }
.doc-render[contenteditable="true"] a::after { content: ' ↗'; font-size: 10px; color: #999; }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 8px; padding: 10px 48px; border-bottom: 1px solid #eee; flex-wrap: wrap; max-width: 820px; margin: 0 auto; }
.toolbar button { padding: 5px 14px; border: 1px solid #ddd; border-radius: 4px; background: #fff; font-size: 13px; cursor: pointer; }
.toolbar button:hover { background: var(--amzn-orange); color: #fff; border-color: var(--amzn-orange); }

/* ── Modal ── */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; align-items: center; justify-content: center; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 8px; padding: 24px; width: 400px; max-width: 90vw; }
.modal h2 { margin-bottom: 14px; font-size: 16px; }
.modal-opt { display: block; width: 100%; padding: 10px; margin-bottom: 8px; border: 1px solid #ddd; border-radius: 6px; background: #fff; font-size: 14px; cursor: pointer; text-align: left; }
.modal-opt:hover { background: #f0f4ff; border-color: var(--amzn-orange); }
.modal-opt small { color: #888; display: block; font-size: 12px; }
.modal-close { margin-top: 10px; padding: 6px 14px; border: none; background: #eee; border-radius: 4px; cursor: pointer; float: right; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 100%; height: 280px; }
  .doc-render { padding: 20px 16px 40px; }
}

/* ── Save toast ── */
.save-toast {
  position: fixed; bottom: 20px; right: 20px; background: #232f3e; color: #fff;
  padding: 8px 16px; border-radius: 20px; font-size: 13px; z-index: 250;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.save-toast.show { opacity: 1; }

/* ── Step badges ── */
.stp .step-badge {
  background: #dc3545; color: #fff; font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 8px; margin-left: 4px;
}
.stp .step-badge.clean { background: #28a745; }

/* ── Header status bar ── */
.hdr-status {
  display: flex; gap: 10px; font-size: 12px; align-items: center;
}
.hdr-status span { padding: 2px 8px; border-radius: 10px; font-weight: 600; }

/* ── Viewers indicator ── */
.viewers { display: flex; gap: -4px; align-items: center; }
.viewer-dot {
  width: 24px; height: 24px; border-radius: 50%; background: #37475a; color: #fff;
  font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; margin-left: -6px;
}
.viewer-dot:first-child { margin-left: 0; }

/* ── Collapsible ── */
.collapsible-toggle { cursor: pointer; user-select: none; }
.collapsible-toggle::before { content: '▼ '; font-size: 10px; }
.collapsible-toggle.collapsed::before { content: '▶ '; }

/* ── Dark mode ── */
body.dark { background: #1a1a2e !important; color: #e0e0e0 !important; }
body.dark .header { background: #16213e !important; }
body.dark .doc-area { background: #1a1a2e !important; }
body.dark .doc-render { background: #1a1a2e !important; color: #e0e0e0 !important; }
body.dark .doc-render h1, body.dark .doc-render h2, body.dark .doc-render h3 { color: #ff9900 !important; }
body.dark .doc-render th { background: #232f3e !important; color: #e0e0e0 !important; }
body.dark .doc-render td, body.dark .doc-render th { border-color: #444 !important; }
body.dark .doc-render a { color: #4fc3f7 !important; }
body.dark .sidebar { background: #16213e !important; }
body.dark .cc { background: #1a1a2e !important; border-color: #333 !important; color: #e0e0e0 !important; }
body.dark .cc-quote { background: #232f3e !important; color: #aaa !important; }
body.dark .sb-head { background: #16213e !important; border-color: #333 !important; color: #e0e0e0 !important; }
body.dark .sb-filters { background: #16213e !important; }
body.dark .rich-toolbar { background: #16213e !important; }
body.dark .rich-toolbar button { background: #232f3e !important; color: #e0e0e0 !important; border-color: #444 !important; }
body.dark .rich-toolbar select { background: #232f3e !important; color: #e0e0e0 !important; }
body.dark .stepper { background: #16213e !important; border-color: #333 !important; }
body.dark .stp { background: #232f3e !important; color: #aaa !important; }
body.dark .stp.active { background: #ff9900 !important; color: #fff !important; }
body.dark .stp.done { background: #28a745 !important; color: #fff !important; }
body.dark .upload-zone { border-color: #444 !important; background: #1a1a2e !important; color: #e0e0e0 !important; }
body.dark .comment-popup { background: #232f3e !important; border-color: #444 !important; color: #e0e0e0 !important; }
body.dark .cp-input { background: #1a1a2e !important; color: #e0e0e0 !important; border-color: #444 !important; }
body.dark .cc-reply-box input { background: #1a1a2e !important; color: #e0e0e0 !important; }
body.dark .toolbar { border-color: #333 !important; }
body.dark .ai-box { background: #1a1a2e !important; border-color: #333 !important; color: #e0e0e0 !important; }
body.dark .ai-box pre { background: #232f3e !important; color: #e0e0e0 !important; }
body.dark .modal { background: #232f3e !important; color: #e0e0e0 !important; }
body.dark .modal-opt { background: #1a1a2e !important; color: #e0e0e0 !important; border-color: #444 !important; }
body.dark #customDialog > div { background: #232f3e !important; color: #e0e0e0 !important; }
body.dark #customDialog pre { background: #1a1a2e !important; color: #e0e0e0 !important; }
body.dark .hdr-actions button { background: #232f3e !important; }
