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

body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: Tahoma, Verdana, sans-serif;
  font-size: 11px;
}

/* ==== Quick Access Toolbar ==== */
.qat {
  display: flex;
  align-items: center;
  padding: 1px 4px;
  background: var(--sz-color-active-title);
  gap: 1px;
  flex-shrink: 0;
  min-height: 20px;
}

.qat-btn {
  width: 20px;
  height: 18px;
  border: none;
  background: transparent;
  cursor: default;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  color: var(--sz-color-title-text);
  border-radius: 2px;
  padding: 0;
}

.qat-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.qat-btn:active {
  background: rgba(0, 0, 0, 0.15);
}

/* ==== Ribbon Tab Bar ==== */
.ribbon-tabs {
  flex-shrink: 0;
  background: var(--sz-color-button-face);
  border-bottom: 1px solid var(--sz-color-button-shadow);
}

.ribbon-tab-bar {
  display: flex;
  align-items: flex-end;
  padding: 0 2px;
  gap: 0;
}

.ribbon-file-btn {
  padding: 4px 14px;
  font-size: 11px;
  font-weight: bold;
  border: none;
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  cursor: default;
  border-radius: 3px 3px 0 0;
  margin-right: 2px;
}

.ribbon-file-btn:hover {
  filter: brightness(1.1);
}

.ribbon-tab {
  padding: 4px 12px;
  font-size: 11px;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--sz-color-button-text);
  cursor: default;
  border-radius: 3px 3px 0 0;
  position: relative;
  top: 1px;
}

.ribbon-tab:hover {
  background: var(--sz-color-button-highlight);
  border-color: var(--sz-color-button-shadow);
}

.ribbon-tab.active {
  background: var(--sz-color-window);
  border-color: var(--sz-color-button-shadow);
  color: var(--sz-color-window-text);
  font-weight: bold;
}

/* ==== Backstage (File menu) ==== */
.backstage {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5000;
  background: rgba(0, 0, 0, 0.3);
}

.backstage.visible {
  display: flex;
}

.backstage-sidebar {
  width: 220px;
  background: var(--sz-color-highlight);
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

.backstage-back {
  border: none;
  background: transparent;
  color: var(--sz-color-highlight-text);
  font-size: 18px;
  padding: 8px 16px;
  text-align: left;
  cursor: default;
}

.backstage-back:hover {
  background: rgba(255, 255, 255, 0.15);
}

.backstage-item {
  border: none;
  background: transparent;
  color: var(--sz-color-highlight-text);
  font-size: 12px;
  padding: 8px 24px;
  text-align: left;
  cursor: default;
  width: 100%;
}

.backstage-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.backstage-sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  margin: 4px 12px;
}

.backstage-spacer {
  flex: 1;
}

.backstage-exit {
  margin-top: auto;
}

/* ==== Ribbon Panels ==== */
.ribbon-panel {
  display: none;
  flex-direction: row;
  align-items: stretch;
  padding: 2px 4px 0;
  background: var(--sz-color-window);
  border-bottom: 1px solid var(--sz-color-button-shadow);
  flex-shrink: 0;
  min-height: 82px;
  overflow-x: auto;
  overflow-y: hidden;
  user-select: none;
}

.ribbon-panel.active {
  display: flex;
}

.ribbon-panel::-webkit-scrollbar {
  height: 4px;
}

.ribbon-panel::-webkit-scrollbar-thumb {
  background: var(--sz-color-button-shadow);
  border-radius: 2px;
}

.ribbon-group {
  display: flex;
  flex-direction: column;
  padding: 2px 4px 0;
  min-width: 0;
  flex-shrink: 0;
}

.ribbon-group-content {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
  min-height: 0;
}

.ribbon-group-label {
  text-align: center;
  font-size: 9px;
  color: var(--sz-color-gray-text);
  padding: 1px 4px 2px;
  white-space: nowrap;
  border-top: 1px solid var(--sz-color-button-light, transparent);
}

.ribbon-sep {
  width: 1px;
  background: var(--sz-color-button-shadow);
  margin: 2px 3px;
  align-self: stretch;
  flex-shrink: 0;
  opacity: 0.4;
}

/* ==== Ribbon Buttons ==== */
.rb-btn {
  border: 1px solid transparent;
  background: transparent;
  cursor: default;
  color: var(--sz-color-button-text);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 3px;
  border-radius: 2px;
  white-space: nowrap;
}

.rb-btn:hover {
  background: var(--sz-color-button-highlight);
  border-color: var(--sz-color-button-shadow);
}

.rb-btn:active {
  background: var(--sz-color-button-shadow);
}

.rb-btn.active {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  border-color: var(--sz-color-button-shadow);
}

.rb-btn-lg {
  flex-direction: column;
  padding: 4px 8px;
  min-width: 44px;
  height: 100%;
  gap: 2px;
}

.rb-btn-lg .rb-icon-lg {
  font-size: 20px;
  line-height: 1;
}

.rb-btn-lg .rb-label {
  font-size: 9px;
}

.rb-btn-sm {
  gap: 4px;
  padding: 1px 4px;
  min-height: 20px;
  justify-content: flex-start;
}

.rb-btn-sm .rb-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.rb-btn-sm .rb-label {
  font-size: 10px;
}

.rb-fmt {
  min-width: 22px;
  height: 22px;
  padding: 0 3px;
  font-size: 12px;
  line-height: 22px;
}

.rb-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  justify-content: flex-start;
}

.rb-row {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;
}

.rb-sep-v {
  width: 1px;
  height: 18px;
  background: var(--sz-color-button-shadow);
  margin: 0 2px;
  opacity: 0.3;
  flex-shrink: 0;
}

.rb-select {
  height: 22px;
  padding: 1px 4px;
  font-size: 11px;
  border: 1px solid var(--sz-color-button-shadow);
  background: var(--sz-color-window);
  color: var(--sz-color-window-text);
  cursor: default;
  border-radius: 2px;
}

.rb-check-label,
.rb-radio-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 4px;
  cursor: default;
  white-space: nowrap;
  min-height: 18px;
}

.rb-check-label:hover,
.rb-radio-label:hover {
  background: var(--sz-color-button-highlight);
  border-radius: 2px;
}

.rb-zoom-row {
  align-items: center;
  gap: 4px;
}

.rb-zoom-slider {
  width: 100px;
  height: 14px;
  cursor: default;
}

.rb-zoom-value {
  font-size: 10px;
  min-width: 36px;
  text-align: center;
}

/* ==== Editor container ==== */
.editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  background: var(--sz-color-window, #fff);
}

/* ==== Line numbers ==== */
.line-numbers {
  flex-shrink: 0;
  padding: 4px 0;
  background: var(--sz-color-button-face, #f0f0f0);
  border-right: 1px solid var(--sz-color-button-shadow, #a0a0a0);
  color: var(--sz-color-gray-text, #888);
  font-family: 'Lucida Console', 'Courier New', Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
  text-align: right;
  user-select: none;
  overflow: hidden;
  min-width: 40px;
  cursor: default;
}

.line-numbers.hidden {
  display: none;
}

.line-number {
  padding: 0 8px 0 8px;
  white-space: nowrap;
}

.line-number.current {
  color: var(--sz-color-window-text, #000);
  font-weight: bold;
  background: rgba(0, 0, 0, 0.04);
}

/* ==== Editor wrapper (textarea + highlight overlay) ==== */
.editor-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.editor-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 4px;
  font-family: 'Lucida Console', 'Courier New', Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
  tab-size: 4;
  -moz-tab-size: 4;
  color: transparent;
  caret-color: var(--sz-color-window-text, #000);
  background: transparent;
  z-index: 2;
  overflow: auto;
  white-space: pre;
}

.editor-input::selection {
  background: var(--sz-color-highlight, #0078d7);
  color: transparent;
}

.editor-input::-moz-selection {
  background: var(--sz-color-highlight, #0078d7);
  color: transparent;
}

.editor-input.word-wrap {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.editor-input.no-wrap {
  white-space: pre;
  overflow-x: auto;
}

/* Syntax highlight overlay */
.editor-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 4px;
  border: none;
  font-family: 'Lucida Console', 'Courier New', Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
  tab-size: 4;
  -moz-tab-size: 4;
  color: var(--sz-color-window-text, #000);
  background: var(--sz-color-window, #fff);
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
  white-space: pre;
  word-wrap: normal;
}

.editor-highlight.word-wrap {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.editor-highlight code {
  display: block;
  font: inherit;
  color: inherit;
}

/* Current line highlight */
.current-line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  height: 1.4em;
  background: rgba(0, 0, 0, 0.04);
  pointer-events: none;
  z-index: 0;
}

/* Long line marker */
.long-line-marker {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  border-right: 1px solid rgba(128, 128, 128, 0.4);
  pointer-events: none;
  z-index: 5;
}

.long-line-marker.visible {
  display: block;
}

/* ==== Whitespace rendering ==== */
.ws-space,
.ws-tab {
  position: relative;
}

.ws-space::before {
  content: '\00B7';
  position: absolute;
  left: 0;
  color: rgba(128, 128, 128, 0.5);
  pointer-events: none;
  width: 100%;
  text-align: center;
}

.ws-tab::before {
  content: '\2192';
  position: absolute;
  left: 0;
  color: rgba(128, 128, 128, 0.5);
  pointer-events: none;
}

.ws-cr,
.ws-lf,
.ws-crlf {
  position: relative;
  display: inline;
}

.ws-cr::before {
  content: '\21A9';
  color: rgba(128, 128, 128, 0.4);
  font-size: 0.85em;
}

.ws-lf::before {
  content: '\21B5';
  color: rgba(128, 128, 128, 0.4);
  font-size: 0.85em;
}

.ws-crlf::before {
  content: '\21B5';
  color: rgba(128, 128, 128, 0.4);
  font-size: 0.85em;
}

/* ==== Syntax highlighting tokens ==== */
.sh-keyword { color: #0000ff; }
.sh-string { color: #a31515; }
.sh-comment { color: #008000; font-style: italic; }
.sh-number { color: #098658; }
.sh-operator { color: #000000; }
.sh-punctuation { color: #000000; }
.sh-function { color: #795e26; }
.sh-type { color: #267f99; }
.sh-constant { color: #0070c1; }
.sh-tag { color: #800000; }
.sh-attr-name { color: #ff0000; }
.sh-attr-value { color: #0000ff; }
.sh-entity { color: #267f99; }
.sh-selector { color: #800000; }
.sh-property { color: #ff0000; }
.sh-value { color: #0000ff; }
.sh-variable { color: #001080; }
.sh-regex { color: #811f3f; }
.sh-heading { color: #0000ff; font-weight: bold; }
.sh-bold { font-weight: bold; }
.sh-italic { font-style: italic; }
.sh-link { color: #0070c1; text-decoration: underline; }
.sh-decorator { color: #795e26; }
.sh-preprocessor { color: #808080; }
.sh-bracket-match { background: rgba(0, 120, 215, 0.2); outline: 1px solid rgba(0, 120, 215, 0.5); }
.sh-selection-match { background: rgba(255, 200, 0, 0.3); }

/* ==== Status bar ==== */
.status-bar {
  display: flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--sz-color-button-face);
  border-top: 1px solid var(--sz-color-button-shadow);
  font-size: 11px;
  color: var(--sz-color-button-text);
  flex-shrink: 0;
  user-select: none;
  gap: 4px;
}

.status-section {
  white-space: nowrap;
  padding: 0 6px;
}

.status-section:not(:last-child):not(.status-modified) {
  border-right: 1px solid var(--sz-color-button-shadow);
}

.status-spacer {
  flex: 1;
}

.status-section.clickable {
  cursor: default;
}

.status-section.clickable:hover {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
}

.status-pos { min-width: 100px; }
.status-sel { min-width: 60px; }
.status-modified { color: var(--sz-color-highlight, #c00); font-weight: bold; }

/* ==== Dialogs ==== */
.dialog-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.dialog-overlay.visible {
  display: flex;
}

.dialog {
  background: var(--sz-color-button-face);
  border: 2px outset var(--sz-color-button-shadow);
  min-width: 300px;
  max-width: 450px;
  box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.3);
}

.dialog-title {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  padding: 4px 8px;
  font-weight: bold;
  font-size: 11px;
  user-select: none;
}

.dialog-body {
  padding: 12px;
  font-size: 11px;
}

.dialog-body p {
  margin-bottom: 8px;
}

.dialog-body input[type="text"],
.dialog-body input[type="number"] {
  width: 100%;
  padding: 2px 4px;
  font-size: 11px;
  margin-top: 4px;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px 12px;
}

.dialog-buttons button {
  min-width: 72px;
  padding: 3px 12px;
  font-size: 11px;
  cursor: default;
}

/* ==== Settings rows ==== */
.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
}

.settings-row select {
  padding: 2px 4px;
  font-size: 11px;
}

.settings-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}

/* ==== Font dialog extras ==== */
.font-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.font-row label {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
}

.font-row select,
.font-row input[type="number"] {
  padding: 2px 4px;
  font-size: 11px;
}

.font-row select {
  width: 180px;
}

.font-row input[type="number"] {
  width: 60px;
}

.font-style-checks {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 11px;
}

.font-style-checks label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}

.font-preview {
  border: 1px inset var(--sz-color-button-shadow);
  background: var(--sz-color-window);
  color: var(--sz-color-window-text);
  padding: 8px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  overflow: hidden;
  font-family: 'Lucida Console', 'Courier New', Consolas, monospace;
}

/* ==== Find/Replace panel (non-modal) ==== */
.find-replace-panel {
  display: none;
  position: fixed;
  top: 28px;
  right: 4px;
  z-index: 1500;
  background: var(--sz-color-button-face);
  border: 2px outset var(--sz-color-button-shadow);
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.25);
  min-width: 380px;
  font-size: 11px;
}

.find-replace-panel.visible {
  display: block;
}

.find-replace-title {
  background: var(--sz-color-highlight);
  color: var(--sz-color-highlight-text);
  padding: 3px 8px;
  font-weight: bold;
  font-size: 11px;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.find-replace-title .fr-close {
  cursor: default;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

.find-replace-title .fr-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.find-replace-body {
  padding: 8px;
}

.fr-field {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  gap: 6px;
}

.fr-field label {
  min-width: 60px;
  text-align: right;
}

.fr-field input[type="text"],
.fr-field input[type="number"] {
  flex: 1;
  padding: 2px 4px;
  font-size: 11px;
}

.fr-options {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 10px;
}

.fr-options label {
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: default;
}

.fr-buttons {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 4px;
}

.fr-buttons button {
  min-width: 72px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: default;
}

.fr-status {
  font-size: 10px;
  color: var(--sz-color-gray-text);
  margin-top: 4px;
  min-height: 14px;
}

/* ==== Print styles ==== */
@media print {
  .qat,
  .ribbon-tabs,
  .ribbon-panel,
  .backstage,
  .status-bar,
  .find-replace-panel,
  .dialog-overlay,
  .long-line-marker {
    display: none !important;
  }

  .editor-container {
    overflow: visible !important;
  }

  .editor-input {
    display: none !important;
  }

  .editor-highlight {
    position: static !important;
    overflow: visible !important;
    color: #000 !important;
    background: #fff !important;
  }

  .line-numbers {
    color: #888 !important;
    background: #f8f8f8 !important;
    border-right: 1px solid #ccc !important;
  }
}
