:root {
  --bg-app: #0f172a;
  --bg-sidebar: #1e293b;
  --border-sidebar: #334155;
  --text-sidebar: #f8fafc;
  --text-sidebar-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-light: rgba(56, 189, 248, 0.15);

  /* Light Reader Theme (Default) */
  --reader-bg: #ffffff;
  --reader-text: #111827;
  --reader-muted: #64748b;
  --reader-border: #e2e8f0;
  --reader-code-bg: #f8fafc;
  --reader-code-border: #e2e8f0;
  --reader-table-th: #f1f5f9;
  --reader-table-hover: #f8fafc;
  --reader-link: #0284c7;

  --max-content-width: 820px;
  --font-size-base: 16px;
}

[data-theme="dark"] {
  --reader-bg: #0f172a;
  --reader-text: #f1f5f9;
  --reader-muted: #94a3b8;
  --reader-border: #334155;
  --reader-code-bg: #1e293b;
  --reader-code-border: #334155;
  --reader-table-th: #1e293b;
  --reader-table-hover: #1e293b88;
  --reader-link: #38bdf8;
}

[data-theme="sepia"] {
  --reader-bg: #fbf0d9;
  --reader-text: #433422;
  --reader-muted: #7d6b53;
  --reader-border: #e4d4b8;
  --reader-code-bg: #f4e5c8;
  --reader-code-border: #dac5a1;
  --reader-table-th: #efe0c4;
  --reader-table-hover: #f7eacf;
  --reader-link: #92400e;
}

[data-width="wide"] {
  --max-content-width: 1100px;
}

[data-width="full"] {
  --max-content-width: 100%;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-sidebar);
}

/* Sidebar */
aside {
  width: 350px;
  min-width: 320px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-sidebar);
  display: flex;
  flex-direction: column;
  height: 100vh;
  z-index: 50;
  transition: transform 0.25s ease-in-out;
}

.brand {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 0.65rem;
  background: var(--accent);
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.brand-info p {
  font-size: 0.78rem;
  color: var(--text-sidebar-muted);
  margin-top: 3px;
}

.search-bar-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-sidebar);
}

.search-box {
  width: 100%;
  background: #0f172a;
  border: 1px solid var(--border-sidebar);
  border-radius: 6px;
  padding: 8px 12px;
  color: #f8fafc;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-box:focus {
  border-color: var(--accent);
}

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

.doc-list::-webkit-scrollbar {
  width: 6px;
}

.doc-list::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

.doc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sidebar);
  margin-bottom: 8px;
  transition: all 0.15s ease-in-out;
  position: relative;
}

.doc-item:hover {
  background: #334155;
}

.doc-item.active {
  background: #0369a1;
  border-color: var(--accent);
}

.doc-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.doc-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-tag {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 500;
  flex-shrink: 0;
}

.doc-desc {
  font-size: 0.78rem;
  color: var(--text-sidebar-muted);
  margin-top: 4px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sidebar-actions {
  padding: 14px 16px;
  border-top: 1px solid var(--border-sidebar);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-accent {
  background: var(--accent);
  color: #0f172a;
}
.btn-accent:hover {
  background: #7dd3fc;
}

.btn-dark {
  background: #334155;
  color: #f8fafc;
}
.btn-dark:hover {
  background: #475569;
}

/* Main Reading Area */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--reader-bg);
  color: var(--reader-text);
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

.topbar {
  height: 56px;
  min-height: 56px;
  background: var(--reader-bg);
  border-bottom: 1px solid var(--reader-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--reader-text);
  font-size: 1.25rem;
  cursor: pointer;
}

.doc-meta-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--reader-text);
}

.doc-meta-stats {
  font-size: 0.78rem;
  color: var(--reader-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  background: var(--reader-code-bg);
  border: 1px solid var(--reader-border);
  color: var(--reader-text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tool-btn:hover {
  border-color: var(--accent);
}

/* Document Container & Typography */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px 80px;
  scroll-behavior: smooth;
}

.content-scroll::-webkit-scrollbar {
  width: 8px;
}

.content-scroll::-webkit-scrollbar-thumb {
  background: var(--reader-border);
  border-radius: 4px;
}

.content-wrapper {
  max-width: var(--max-content-width);
  margin: 0 auto;
  font-size: var(--font-size-base);
  line-height: 1.65;
  transition: max-width 0.2s, font-size 0.15s;
}

/* Typographic Elements */
.content-wrapper h1 {
  font-size: 2.1rem;
  line-height: 1.25;
  font-weight: 800;
  margin: 0 0 16px;
  color: var(--reader-text);
  border-bottom: 2px solid var(--reader-border);
  padding-bottom: 12px;
}

.content-wrapper h2 {
  font-size: 1.45rem;
  line-height: 1.35;
  font-weight: 700;
  margin: 32px 0 12px;
  color: var(--reader-text);
  border-bottom: 1px solid var(--reader-border);
  padding-bottom: 8px;
}

.content-wrapper h3 {
  font-size: 1.15rem;
  line-height: 1.4;
  font-weight: 700;
  margin: 24px 0 8px;
  color: var(--reader-text);
}

.content-wrapper h4 {
  font-size: 1rem;
  font-weight: 700;
  margin: 18px 0 6px;
}

.content-wrapper p {
  margin: 0 0 14px;
}

.content-wrapper a {
  color: var(--reader-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content-wrapper hr.divider {
  border: 0;
  height: 1px;
  background: var(--reader-border);
  margin: 28px 0;
}

/* Tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 20px 0 24px;
  border-radius: 8px;
  border: 1px solid var(--reader-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9em;
}

th {
  background: var(--reader-table-th);
  color: var(--reader-text);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 2px solid var(--reader-border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--reader-border);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--reader-table-hover);
}

/* Code & Pre */
.inline-code {
  font-family: "SF Mono", Menlo, Consolas, Monaco, monospace;
  font-size: 0.88em;
  background: var(--reader-code-bg);
  border: 1px solid var(--reader-code-border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--reader-text);
}

.code-block {
  margin: 18px 0;
  background: var(--reader-code-bg);
  border: 1px solid var(--reader-code-border);
  border-radius: 8px;
  overflow: hidden;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: var(--reader-table-th);
  border-bottom: 1px solid var(--reader-code-border);
  font-size: 0.75rem;
  color: var(--reader-muted);
  font-weight: 600;
}

.copy-btn {
  background: none;
  border: none;
  color: var(--reader-link);
  font-size: 0.75rem;
  cursor: pointer;
  font-weight: 600;
}

.code-block code {
  display: block;
  padding: 12px 16px;
  font-family: "SF Mono", Menlo, Consolas, Monaco, monospace;
  font-size: 0.88em;
  line-height: 1.5;
  overflow-x: auto;
}

/* Callouts / Alerts */
.callout {
  margin: 20px 0;
  padding: 14px 18px;
  border-radius: 8px;
  border-left: 4px solid;
  background: var(--reader-code-bg);
}

.callout-title {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.callout-body {
  font-size: 0.95em;
  line-height: 1.5;
}

.callout-note { border-left-color: #0284c7; }
.callout-note .callout-title { color: #0284c7; }

.callout-tip { border-left-color: #10b981; }
.callout-tip .callout-title { color: #10b981; }

.callout-important { border-left-color: #8b5cf6; }
.callout-important .callout-title { color: #8b5cf6; }

.callout-warning { border-left-color: #f59e0b; }
.callout-warning .callout-title { color: #f59e0b; }

.callout-caution { border-left-color: #ef4444; }
.callout-caution .callout-title { color: #ef4444; }

blockquote {
  margin: 16px 0;
  padding: 8px 16px;
  border-left: 3px solid var(--reader-muted);
  color: var(--reader-muted);
  font-style: italic;
}

/* Status Badges */
.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-done { background: #dcfce7; color: #166534; }
.status-blocked { background: #fee2e2; color: #991b1b; }
.status-needs-you { background: #fef3c7; color: #92400e; }
.status-risk { background: #ffedd5; color: #9a3412; }

/* Lists */
ul, ol {
  margin: 0 0 16px 24px;
}

li {
  margin-bottom: 6px;
}

.task-item {
  list-style-type: none;
  margin-left: -20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Anchor link */
.anchor-link {
  opacity: 0;
  color: var(--reader-muted);
  text-decoration: none;
  font-size: 0.8em;
  margin-left: 6px;
  transition: opacity 0.15s;
}

h1:hover .anchor-link, h2:hover .anchor-link, h3:hover .anchor-link {
  opacity: 1;
}

/* Drag overlay */
#dropOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #f8fafc;
  pointer-events: none;
}

#dropOverlay.active {
  display: flex;
}

#dropOverlay .box {
  border: 3px dashed var(--accent);
  padding: 48px 64px;
  border-radius: 16px;
  text-align: center;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-sidebar);
  width: 90%;
  max-width: 600px;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5);
  color: #f8fafc;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-body textarea, .modal-body input {
  width: 100%;
  background: #0f172a;
  border: 1px solid var(--border-sidebar);
  color: #f8fafc;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
  font-family: inherit;
  font-size: 0.9rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Print Styles */
@media print {
  aside, .topbar, #dropOverlay, .modal-overlay, .copy-btn, .anchor-link {
    display: none !important;
  }
  body, main, .content-scroll {
    background: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .content-wrapper {
    max-width: 100% !important;
    margin: 0 !important;
    font-size: 11pt !important;
    line-height: 1.45 !important;
  }
  .table-wrapper {
    overflow: visible !important;
    border: none !important;
  }
  table {
    border: 1px solid #ccc !important;
  }
  th, td {
    border: 1px solid #ddd !important;
    padding: 6pt 8pt !important;
  }
  h1, h2, h3 {
    break-after: avoid !important;
    page-break-after: avoid !important;
  }
  @page {
    margin: 1in;
    size: A4;
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  aside {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 10px 0 25px rgba(0,0,0,0.5);
  }
  aside.open {
    transform: translateX(0);
  }
  .menu-toggle {
    display: block;
    font-size: 1.35rem;
    padding: 4px 6px;
  }
  .topbar {
    padding: 0 12px;
    height: 52px;
    min-height: 52px;
  }
  .doc-meta-stats {
    display: none;
  }
  .doc-meta-title {
    font-size: 0.88rem;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tool-btn.desktop-only {
    display: none;
  }
  .topbar-right {
    gap: 4px;
  }
  .tool-btn {
    padding: 5px 8px;
    font-size: 0.75rem;
  }
  .content-scroll {
    padding: 20px 16px 60px;
  }
}
