:root {
  --ribbon-bg: #2b579a;
  --ribbon-tab-active: #ffffff;
  --ribbon-tab-inactive: rgba(255,255,255,0.7);
  --ribbon-panel-bg: #f3f3f3;
  --ribbon-border: #d1d1d1;
  --accent: #2b579a;
  --accent-light: #4472c4;
  --accent-lighter: #d6e4f0;
  --text: #333;
  --text-muted: #666;
  --bg: #e8e8e8;
  --paper: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ─── App Container ─── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ─── Title Bar ─── */
.title-bar {
  background: var(--ribbon-bg);
  color: white;
  display: flex;
  align-items: center;
  padding: 4px 12px;
  font-size: 12px;
  gap: 8px;
  min-height: 32px;
  user-select: none;
}

.title-bar-icon {
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #4472c4, #2b579a);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
}

.title-bar-text {
  flex: 1;
  text-align: center;
  font-size: 12px;
  opacity: 0.95;
}

.title-bar-buttons {
  display: flex;
  gap: 0;
}

.title-bar-btn {
  width: 46px;
  height: 28px;
  border: none;
  background: transparent;
  color: white;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-bar-btn:hover { background: rgba(255,255,255,0.1); }
.title-bar-btn.close:hover { background: #e81123; }

/* ─── Ribbon Tabs ─── */
.ribbon-tabs {
  background: var(--ribbon-bg);
  display: flex;
  padding: 0 8px;
  gap: 0;
}

.ribbon-tab {
  padding: 6px 16px;
  color: var(--ribbon-tab-inactive);
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: none;
  position: relative;
  transition: color 0.15s;
  user-select: none;
  font-family: inherit;
}

.ribbon-tab:hover { color: white; }

.ribbon-tab.active {
  color: var(--accent);
  background: var(--ribbon-panel-bg);
  border-radius: 3px 3px 0 0;
  font-weight: 600;
}

.ribbon-tab.file-tab {
  background: #1a3a6c;
  color: white;
  font-weight: 600;
  border-radius: 3px 3px 0 0;
  margin-right: 4px;
}
.ribbon-tab.file-tab:hover { background: #0f2a52; }

/* ─── Ribbon Panel ─── */
.ribbon-panel {
  background: var(--ribbon-panel-bg);
  border-bottom: 1px solid var(--ribbon-border);
  min-height: 80px;
  display: flex;
  align-items: stretch;
  padding: 4px 8px;
  gap: 0;
}

.ribbon-group {
  display: flex;
  flex-direction: column;
  padding: 4px 16px;
  border-right: 1px solid var(--ribbon-border);
  position: relative;
}

.ribbon-group:last-child { border-right: none; }

.ribbon-group-label {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  margin-top: auto;
  padding-top: 4px;
}

.ribbon-group-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.ribbon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  min-width: 56px;
  font-size: 11px;
  color: var(--text);
  font-family: inherit;
}

.ribbon-btn:hover {
  background: rgba(0,0,0,0.05);
  border-color: var(--ribbon-border);
}

.ribbon-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ribbon-btn-icon {
  font-size: 22px;
  line-height: 1;
}

.ribbon-btn-sm {
  flex-direction: row;
  min-width: auto;
  padding: 3px 8px;
  gap: 6px;
  font-size: 12px;
}

.ribbon-btn-sm .ribbon-btn-icon { font-size: 14px; }

.upload-btn {
  cursor: pointer;
}

.file-info {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.file-name {
  font-weight: 600;
  font-size: 12px;
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
}

.file-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.ribbon-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Example Dropdown ─── */
.example-select {
  padding: 4px 8px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  background: white;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  min-width: 140px;
}

.example-select:hover {
  border-color: var(--accent-light);
}

.ribbon-separator {
  width: 1px;
  align-self: stretch;
  background: var(--ribbon-border);
  margin: 2px 8px;
}

.loaded-file-indicator {
  gap: 4px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--accent-lighter);
  border: 1px solid var(--accent-light);
}

.loaded-file-indicator .loaded-file-icon {
  font-size: 14px;
}

.loaded-file-indicator .file-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
}

.loaded-file-indicator .file-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* ─── Multi-File Panel ─── */
.file-list-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 320px;
}

.file-list-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.file-list-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.main-file-select {
  padding: 2px 6px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  background: white;
  font-size: 11px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  min-width: 120px;
}

.main-file-select:hover {
  border-color: var(--accent-light);
}

.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 3px;
  background: white;
  border: 1px solid var(--ribbon-border);
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s;
}

.file-chip:hover {
  border-color: var(--accent-light);
}

.file-chip-main {
  background: var(--accent-lighter);
  border-color: var(--accent-light);
  font-weight: 600;
  color: var(--accent);
}

.file-chip-icon {
  font-size: 10px;
}

.file-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 9px;
  color: var(--text-muted);
  padding: 0 2px;
  line-height: 1;
  border-radius: 2px;
}

.file-chip-remove:hover {
  background: rgba(0,0,0,0.08);
  color: #c62828;
}

.example-btn-group {
  position: relative;
}

.example-add-btn {
  min-width: 64px;
}

.example-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  background: white;
  border: 1px solid var(--ribbon-border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 160px;
  padding: 4px 0;
  margin-top: 2px;
}

.example-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: none;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.example-menu-item:hover:not(.disabled) {
  background: var(--accent-lighter);
}

.example-menu-item.disabled {
  color: var(--text-muted);
  cursor: default;
}

.example-menu-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
}

.example-menu-divider {
  height: 1px;
  background: var(--ribbon-border);
  margin: 4px 0;
}

.example-menu-all {
  font-weight: 600;
}

.file-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

/* ─── Quick Access Toolbar ─── */
.quick-access {
  display: flex;
  align-items: center;
  gap: 2px;
}

.qa-btn {
  width: 22px;
  height: 20px;
  border: none;
  background: none;
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qa-btn:hover { background: rgba(255,255,255,0.15); color: white; }

/* ─── Font Preview (docs ribbon) ─── */
.font-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  background: white;
  font-size: 12px;
  min-width: 140px;
}

.font-size-box {
  width: 40px;
  padding: 3px 6px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  background: white;
  font-size: 12px;
  text-align: center;
}

.format-buttons {
  display: flex;
  gap: 1px;
}

.fmt-btn {
  width: 28px;
  height: 26px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  border-radius: 2px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-family: inherit;
}

.fmt-btn:hover { background: rgba(0,0,0,0.06); border-color: var(--ribbon-border); }

/* ─── Ruler ─── */
.ruler {
  background: #f0f0f0;
  border-bottom: 1px solid var(--ribbon-border);
  height: 22px;
  display: flex;
  align-items: flex-end;
  padding: 0 260px;
  overflow: hidden;
}

.ruler-marks {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: flex-end;
  padding: 0 40px;
}

.ruler-mark {
  flex: 1;
  text-align: center;
  font-size: 9px;
  color: var(--text-muted);
  border-left: 1px solid #ccc;
  padding-bottom: 2px;
}

/* ─── Main Area ─── */
.main-area {
  flex: 1;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Compiler Pages (side-by-side documents) ─── */
.compiler-pages {
  display: flex;
  height: 100%;
  gap: 24px;
  padding: 24px 32px;
  justify-content: center;
  align-items: stretch;
  overflow: auto;
}

.compiler-page {
  background: var(--paper);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
  /* US Letter aspect ratio (8.5 x 11), sized by available height */
  height: calc(100% - 48px);
  aspect-ratio: 8.5 / 11;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.page-title {
  padding: 20px 40px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #eee;
}

.page-title-disclaimer {
  text-transform: none;
  font-weight: 400;
  text-decoration: underline dotted;
  cursor: help;
}

.page-code {
  flex: 1;
  padding: 16px 40px 40px;
  margin: 0;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: auto;
  background: var(--paper);
}

.page-console {
  flex: 1;
  padding: 16px 40px 40px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow: auto;
}

.page-console pre {
  margin: 0;
  white-space: pre-wrap;
  color: var(--text);
}

.page-console .output {
  color: #2e7d32;
}

.page-console .error {
  color: #c62828;
}

.page-console .compiling {
  color: var(--text-muted);
  font-style: italic;
}

.page-console.has-error {
  /* subtle red tint at top */
}

.page-console .stdin-echo {
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 4px 0;
  white-space: pre-wrap;
}

.console-stdin {
  border-top: 1px solid #eee;
  padding: 8px 40px 12px;
}

.stdin-box {
  width: 100%;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  padding: 6px 8px;
  resize: vertical;
  min-height: 28px;
}

.stdin-box:focus {
  outline: none;
  border-color: var(--accent-light);
}

/* ─── Document Preview ─── */
.page-preview {
  flex: 1;
  padding: 24px 40px 40px;
  overflow: auto;
}

.page-preview .docx-preview-content {
  font-size: 13px;
}

.preview-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  padding-top: 8px;
}

/* ─── Docs Frame ─── */
.docs-frame {
  width: 100%;
  height: 100%;
  border: none;
}

/* ─── Status Bar ─── */
.status-bar {
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 12px;
  font-size: 11px;
  min-height: 24px;
  user-select: none;
}

.status-left,
.status-right-area {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-right-area {
  opacity: 0.7;
}

.status-separator::before {
  content: "|";
  margin: 0 6px;
  opacity: 0.5;
}

/* ─── Loading / Error UI ─── */
.loading-progress {
  position: relative;
  display: block;
  width: 8rem;
  height: 8rem;
  margin: 20vh auto 1rem auto;
}

.loading-progress circle {
  fill: none;
  stroke: #e0e0e0;
  stroke-width: 0.6rem;
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
}

.loading-progress circle:last-child {
  stroke: var(--accent);
  stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
  transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
  position: absolute;
  text-align: center;
  font-weight: bold;
  inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
  content: var(--blazor-load-percentage-text, "Loading");
}

#blazor-error-ui {
  background: lightyellow;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}
