* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  height: 100vh;
  overflow: hidden;
}

.layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background: #f0f0f0;
  padding: 16px;
  border-right: 1px solid #ddd;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar h2 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #444;
}

#doc-list {
  flex: 1;
}

.doc-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin: 4px 0;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.doc-btn:hover {
  background: #e8e8e8;
}

.doc-btn.active {
  background: #0066cc;
  color: white;
  border-color: #0066cc;
}

.sidebar-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-direction: column;
}

.sidebar-actions button {
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #bbb;
  background: white;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.sidebar-actions button:hover:not(:disabled) {
  background: #e0e8f4;
  border-color: #0066cc;
  color: #0066cc;
}

.sidebar-actions button:disabled {
  color: #aaa;
  border-color: #ddd;
  cursor: not-allowed;
  background: #f8f8f8;
}

/* Preview area */
.preview-area {
  padding: 24px;
  overflow-y: auto;
  background: white;
  position: relative;
  height: 100%;
}

.preview-area.loading::before {
  content: "Generating document...";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #666;
  font-style: italic;
  font-size: 1rem;
}

.preview-area.loading #preview-content {
  opacity: 0.3;
  pointer-events: none;
}

#preview-content {
  max-width: 800px;
  margin: 0 auto;
  transition: opacity 0.2s;
}

.placeholder-text {
  color: #999;
  font-style: italic;
}

/* Preview document styles */
#preview-content h1 {
  font-size: 1.8rem;
  margin: 1.5rem 0 0.75rem 0;
  color: #111;
  border-bottom: 2px solid #ddd;
  padding-bottom: 0.3rem;
}

#preview-content h2 {
  font-size: 1.4rem;
  margin: 1.2rem 0 0.6rem 0;
  color: #222;
}

#preview-content h3 {
  font-size: 1.15rem;
  margin: 1rem 0 0.5rem 0;
  color: #333;
}

#preview-content p {
  line-height: 1.6;
  margin: 0.5rem 0;
  color: #333;
}

#preview-content ul,
#preview-content ol {
  margin: 0.5rem 0 0.5rem 1.5rem;
  padding: 0;
}

#preview-content li {
  margin: 0.25rem 0;
  line-height: 1.5;
}

#preview-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 0.9rem;
}

#preview-content th,
#preview-content td {
  border: 1px solid #ccc;
  padding: 8px 10px;
  text-align: left;
}

#preview-content th {
  background: #f5f5f5;
  font-weight: bold;
  color: #222;
}

#preview-content tr:nth-child(even) td {
  background: #fafafa;
}

#preview-content img {
  max-width: 100%;
  display: block;
  margin: 1rem auto;
}

#preview-content code {
  font-family: "Courier New", monospace;
  background: #f4f4f4;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.9em;
}

#preview-content strong {
  font-weight: 600;
}

#preview-content em {
  color: #555;
}

/* Phase 2 additions */

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.main-area .preview-area {
  flex: 1;
  overflow-y: auto;
}

/* Auth section */
.auth-section {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ddd;
}

.auth-error {
  font-size: 0.85rem;
  color: #cc0000;
  margin: 0;
}

.sign-in-btn {
  display: block;
  padding: 8px 12px;
  background: #0066cc;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.85rem;
  text-align: center;
}

.sign-in-btn:hover {
  background: #0052a3;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-name {
  font-size: 0.85rem;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sign-out-link {
  font-size: 0.8rem;
  color: #0066cc;
  text-decoration: none;
}

.sign-out-link:hover {
  text-decoration: underline;
}

/* Status dots */
.status-dot {
  font-size: 0.7rem;
}

.status-dot.green {
  color: #22a355;
}

.status-dot.grey {
  color: #aaa;
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #ddd;
  border-top-color: #0066cc;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  color: #555;
  font-style: italic;
  margin: 0;
}

/* Validate Changes diff view */
.diff-section {
  border: 1px solid #ddd;
  border-radius: 6px;
  margin-bottom: 24px;
  overflow: hidden;
}

.diff-header {
  background: #f5f5f5;
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid #ddd;
}

.diff-source {
  font-size: 0.8rem;
  color: #888;
}

.diff-columns {
  display: flex;
  gap: 0;
}

.diff-col {
  flex: 1;
  min-width: 0;
  border-right: 1px solid #ddd;
}

.diff-col:last-child {
  border-right: none;
}

.diff-col-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 12px;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}

.diff-col-body {
  padding: 12px 16px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.diff-col-body p {
  margin: 0.4rem 0;
}

.diff-empty {
  color: #aaa;
  font-style: italic;
}

.diff-change {
  background-color: #cce5ff;
  border-radius: 2px;
  font-weight: 600;
  white-space: pre-wrap;
}


.diff-tbl {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  margin: 8px 0;
}

.diff-tbl th,
.diff-tbl td {
  border: 1px solid #ccc;
  padding: 5px 8px;
  text-align: left;
}

.diff-tbl th {
  background: #f0f0f0;
  font-weight: 600;
}

.diff-tbl td.diff-change {
  background-color: #cce5ff;
}

#preview-content.diff-mode {
  max-width: 100%;
}

.diff-context {
  color: #999;
  font-style: italic;
  margin: 0.2rem 0;
}

.diff-ws {
  color: #b0b0b0;
  font-style: normal;
}

.diff-actions {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  border-top: 1px solid #ddd;
  background: #fafafa;
}

.accept-btn {
  padding: 6px 16px;
  background: #22a355;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.accept-btn:hover {
  background: #1a7a40;
}

.reject-btn {
  padding: 6px 16px;
  background: white;
  color: #cc0000;
  border: 1px solid #cc0000;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.reject-btn:hover {
  background: #fff0f0;
}

.new-btn {
  padding: 6px 16px;
  background: #1565c0;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.new-btn:hover {
  background: #0d47a1;
}

.version-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: not-allowed;
  border: 1px solid #ddd;
  background: #f0f0f0;
  color: #aaa;
  font-size: 0.9rem;
  text-align: left;
}

/* Help / Console side pane */
#help-pane {
  width: 480px;
  min-width: 480px;
  background: #fafafa;
  border-left: 1px solid #ddd;
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  overflow: hidden;
  transition: min-width 0.25s ease, width 0.25s ease;
  position: relative;
  z-index: 1002; /* stay above modal overlays (1000, 1001) so rail tabs remain clickable */
}

#help-pane.collapsed {
  width: 28px;
  min-width: 28px;
}

/* Rail: the 28px vertical strip holding the two tab buttons */
.side-rail {
  width: 28px;
  min-width: 28px;
  display: flex;
  flex-direction: column;
  background: #f0f0f0;
  border-right: 1px solid #ddd;
  flex-shrink: 0;
}

.rail-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-bottom: 1px solid #ddd;
  cursor: pointer;
  writing-mode: vertical-rl;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #666;
  padding: 12px 0;
  transition: background 0.15s, color 0.15s;
}

.rail-btn:last-child {
  border-bottom: none;
}

.rail-btn:hover {
  background: #e0e8f4;
  color: #0066cc;
}

.rail-btn.active {
  background: #ddeeff;
  color: #0066cc;
}

#help-body {
  overflow-y: auto;
  padding: 16px;
  flex: 1;
  min-width: 0;
}

/* Help topic switcher — the three process documents */
#help-topics {
  display: flex;
  gap: 4px;
  margin: -4px 0 14px;
  border-bottom: 1px solid #dde3e9;
  padding-bottom: 8px;
}

#help-topics a {
  font-size: 0.85em;
  padding: 4px 10px;
  border-radius: 4px;
  color: #55606b;
  text-decoration: none;
  white-space: nowrap;
}

#help-topics a:hover {
  background: #eef2f6;
  color: #0066cc;
}

#help-topics a.active {
  background: #ddeeff;
  color: #0066cc;
  font-weight: 600;
}

#help-pane.collapsed #help-body,
#help-pane.collapsed #console-body {
  display: none;
}

/* Help content typography */
#help-body h1 { font-size: 1.1rem; margin: 0 0 0.75rem 0; color: #111; border-bottom: 1px solid #ddd; padding-bottom: 0.3rem; }
#help-body h2 { font-size: 1rem; margin: 1rem 0 0.4rem 0; color: #222; }
#help-body h3 { font-size: 0.9rem; margin: 0.8rem 0 0.3rem 0; color: #333; }
#help-body p  { font-size: 0.85rem; line-height: 1.5; margin: 0.4rem 0; color: #333; }
#help-body ul, #help-body ol { font-size: 0.85rem; margin: 0.4rem 0 0.4rem 1.2rem; padding: 0; }
#help-body li { margin: 0.2rem 0; line-height: 1.4; }
#help-body code {
  font-family: "Courier New", monospace;
  background: #f0f0f0;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.82em;
}
#help-body pre {
  background: #f0f0f0;
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.82em;
  line-height: 1.4;
}
#help-body pre code { background: none; padding: 0; }
#help-body table { border-collapse: collapse; width: 100%; font-size: 0.82rem; margin: 0.5rem 0; }
#help-body th, #help-body td { border: 1px solid #ccc; padding: 4px 8px; text-align: left; }
#help-body th { background: #f0f0f0; font-weight: 600; }

/* Console body */
#console-body {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: #1e1e1e;
  overflow-y: auto;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 6px 0 6px 0;
}

.console-clear-btn {
  align-self: flex-end;
  margin: 4px 8px 4px auto;
  padding: 2px 10px;
  font-size: 0.75rem;
  background: #333;
  color: #aaa;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
}

.console-clear-btn:hover {
  background: #444;
  color: #ddd;
}

.log-line {
  padding: 1px 10px;
  line-height: 1.45;
  color: #ddd;
}

.log-error    { color: #ff6b6b; }
.log-critical { color: #ff6b6b; font-weight: bold; }
.log-warning  { color: #ffd166; }
.log-info     { color: #a8d8ff; }
.log-debug    { color: #888; }

#help-resize-handle {
  width: 5px;
  min-width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  transition: background 0.15s;
}

#help-resize-handle:hover,
#help-resize-handle.dragging {
  background: #0066cc33;
}

/* Configuration-error overlay — shown when Microsoft 365 credentials are absent.
   Full-viewport block: the UI shell renders behind it but cannot be used. */
.config-error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 33, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.config-error-box {
  max-width: 460px;
  margin: 0 24px;
  padding: 32px 36px;
  background: #fff;
  border-radius: 8px;
  border-top: 4px solid #c0392b;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.config-error-box h2 {
  margin: 0 0 12px;
  color: #c0392b;
}

.config-error-box p {
  margin: 0 0 10px;
  color: #444;
  line-height: 1.5;
}

.config-error-box p:last-child {
  margin-bottom: 0;
}

.config-error-box code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

/* Full-screen sign-in screen. Opaque backdrop (not translucent) so the app
   chrome — sidebar, disabled buttons — is fully hidden until authenticated,
   rather than greyed-but-visible behind it. */
.app-overlay {
  position: fixed;
  inset: 0;
  background: #eef1f5;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-box {
  max-width: 380px;
  margin: 0 24px;
  padding: 32px 36px;
  background: #fff;
  border-radius: 8px;
  border-top: 4px solid #0066cc;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.auth-box h2 {
  margin: 0 0 12px;
  color: #1a1a1a;
}

.auth-box p {
  margin: 0 0 16px;
  color: #444;
  line-height: 1.5;
}

/* Role-tiered visibility. Body gets role-viewer | role-editor | role-admin.
   Admin sees everything; Editor hides .admin-only; Viewer hides both .admin-only
   and .editor-only (read-only: view + download only). */
.role-editor .admin-only,
.role-viewer .admin-only,
.role-viewer .editor-only {
  display: none !important;
}

/* Source repository status (sidebar footer) — deliberately small and subtle */
.source-status {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid #ededed;
  font-size: 0.62rem;
  color: #9a9a9a;
  line-height: 1.4;
  word-break: break-word;
}
.source-status strong { font-weight: 600; color: #8a8a8a; }
.source-status .src-when { color: #b0b0b0; }
.source-status .src-detail { color: #c0392b; }
.src-dot { font-size: 1.4em; vertical-align: -0.12em; margin-right: 3px; }
.src-ok { color: #18a957; }
.src-bad { color: #e01b1b; }
.src-unknown { color: #bdbdbd; }

/* Which build is running, at the foot of the sidebar. Deliberately quiet: it is
   for answering "what is this instance running", not for reading every day. */
.app-version {
  margin-top: auto;
  padding-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  opacity: 0.55;
  word-break: break-all;
}
