/* ===== OpenDocs Styles ===== */
:root {
  --primary: #1a73e8;
  --primary-light: #d3e3fd;
  --primary-bg: rgba(26,115,232,0.1);
  --border: #d4d4d4;
  --border-light: #e0e0e0;
  --header-bg: #f8f9fa;
  --toolbar-bg: #f3f3f3;
  --text: #202124;
  --text-sec: #5f6368;
  --surface: #fff;
  --danger: #d93025;
  --radius: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.18);
  --page-bg: #e8eaed;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* ===== Menu Bar (same as OpenSheets) ===== */
.menu-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 32px;
  padding: 0 4px;
  user-select: none;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.menu-item { position: relative; }

.menu-label {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background .1s;
}
.menu-label:hover { background: rgba(0,0,0,.06); }
.menu-item.open .menu-label { background: rgba(0,0,0,.1); }

.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px 0;
  z-index: 1000;
}
.menu-item.open .menu-dropdown { display: block; }

.menu-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 16px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background .1s;
}
.menu-action:hover { background: var(--primary-bg); }

.menu-shortcut {
  font-size: 11px;
  color: var(--text-sec);
  margin-left: 24px;
}

.menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

/* ===== Toolbar (same design as OpenSheets) ===== */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px 8px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
  user-select: none;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  border-right: 1px solid var(--border-light);
}
.toolbar-group:last-child { border-right: none; }

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  transition: background .1s;
}
.toolbar-btn:hover { background: rgba(0,0,0,.08); }
.toolbar-btn:active, .toolbar-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.toolbar-select {
  height: 28px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  max-width: 140px;
}
.toolbar-select-sm { width: 55px; }

.toolbar-color {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  padding: 2px 4px;
  border-radius: var(--radius);
}
.toolbar-color:hover { background: rgba(0,0,0,.08); }
.toolbar-color input[type="color"] {
  width: 16px;
  height: 16px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: none;
}

/* ===== Ruler ===== */
.doc-ruler {
  height: 24px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.doc-ruler.hidden { display: none; }
.doc-ruler-inner {
  position: relative;
  height: 100%;
}
.doc-ruler-mark {
  position: absolute;
  bottom: 0;
  font-size: 8px;
  color: var(--text-sec);
  transform: translateX(-50%);
}
.doc-ruler-tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

/* ===== Editor Container ===== */
.doc-editor-container {
  flex: 1;
  overflow: auto;
  background: var(--page-bg);
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

/* ===== Page ===== */
.doc-page {
  width: 794px; /* A4: 210mm at ~96dpi */
  min-height: 1123px; /* A4: 297mm at ~96dpi */
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
  position: relative;
  margin: 0 auto 20px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

/* ===== Header & Footer ===== */
.doc-header-footer {
  padding: 12px 96px;
  font-size: 10px;
  color: var(--text-sec);
  min-height: 30px;
  outline: none;
  border: 1px dashed transparent;
  transition: border-color .2s;
}
.doc-header-footer:focus {
  border-color: var(--border-light);
}
.doc-header {
  border-bottom: 1px solid transparent;
}
.doc-header:focus {
  border-bottom-color: var(--border-light);
}
.doc-footer {
  border-top: 1px solid transparent;
  margin-top: auto;
}
.doc-footer:focus {
  border-top-color: var(--border-light);
}

/* ===== Editor ===== */
.doc-editor {
  flex: 1;
  padding: 25px 96px;
  outline: none;
  font-family: Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.5;
  color: var(--text);
  min-height: 800px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-editor:focus { outline: none; }

/* Editor content styles */
.doc-editor h1 { font-size: 24pt; font-weight: 700; margin: 16px 0 8px; line-height: 1.3; }
.doc-editor h2 { font-size: 18pt; font-weight: 600; margin: 14px 0 6px; line-height: 1.3; }
.doc-editor h3 { font-size: 14pt; font-weight: 600; margin: 12px 0 6px; line-height: 1.3; }
.doc-editor h4 { font-size: 12pt; font-weight: 600; margin: 10px 0 4px; line-height: 1.4; }
.doc-editor h5 { font-size: 11pt; font-weight: 600; margin: 8px 0 4px; line-height: 1.4; }
.doc-editor h6 { font-size: 10pt; font-weight: 600; margin: 8px 0 4px; line-height: 1.4; color: var(--text-sec); }

.doc-editor p { margin: 0 0 8px; }
.doc-editor ul, .doc-editor ol { margin: 0 0 8px; padding-left: 24px; }
.doc-editor li { margin: 2px 0; }

.doc-editor blockquote {
  border-left: 3px solid var(--primary);
  padding: 8px 16px;
  margin: 8px 0;
  background: var(--primary-bg);
  color: var(--text-sec);
  font-style: italic;
}

.doc-editor a { color: var(--primary); text-decoration: underline; }
.doc-editor a:hover { color: #174ea6; }

.doc-editor img {
  max-width: 100%;
  height: auto;
  margin: 8px 0;
  border-radius: var(--radius);
  cursor: default;
}
.doc-editor img.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.doc-editor hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Page break indicator */
.doc-editor .page-break {
  display: block;
  border: none;
  border-top: 2px dashed var(--border);
  margin: 24px 0;
  position: relative;
  height: 0;
  page-break-after: always;
}
.doc-editor .page-break::after {
  content: 'Page Break';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--page-bg);
  padding: 0 8px;
  font-size: 10px;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Table of Contents */
.doc-editor .doc-toc {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 0;
  background: var(--header-bg);
}
.doc-editor .doc-toc-title {
  font-size: 14pt;
  font-weight: 600;
  margin-bottom: 8px;
}
.doc-editor .doc-toc a {
  display: block;
  padding: 2px 0;
  color: var(--primary);
  text-decoration: none;
  font-size: 11pt;
}
.doc-editor .doc-toc a:hover { text-decoration: underline; }
.doc-editor .doc-toc .toc-h2 { padding-left: 16px; }
.doc-editor .doc-toc .toc-h3 { padding-left: 32px; font-size: 10pt; }

/* Tables */
.doc-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: inherit;
}
.doc-editor table td,
.doc-editor table th {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  min-width: 40px;
}
.doc-editor table th {
  background: var(--header-bg);
  font-weight: 600;
}
.doc-editor table tr:hover td {
  background: rgba(0,0,0,.02);
}
.doc-editor table.selected {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  padding: 0 12px;
  background: var(--toolbar-bg);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-sec);
  user-select: none;
  flex-shrink: 0;
}
.status-sep {
  margin: 0 8px;
  color: var(--border);
}

/* ===== Dialogs ===== */
.dialog {
  position: fixed;
  z-index: 900;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 90vw;
}
.find-dialog {
  top: 60px; right: 20px;
}
.center-dialog {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 14px;
}
.dialog-close {
  width: 24px; height: 24px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-sec);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog-close:hover { background: rgba(0,0,0,.08); }

.dialog-body { padding: 16px; }
.dialog-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.dialog-row label { font-size: 12px; min-width: 60px; color: var(--text-sec); }

.dialog-input {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}
.dialog-input:focus { border-color: var(--primary); outline: none; }

.dialog-options { gap: 16px; }
.dialog-options label { min-width: auto; display: flex; align-items: center; gap: 4px; cursor: pointer; }

.dialog-actions { gap: 8px; justify-content: flex-end; }

.dialog-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  transition: background .1s;
}
.dialog-btn:hover { background: rgba(0,0,0,.06); }

.dialog-btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.dialog-btn-primary:hover { background: #1765cc; }

.find-status { font-size: 11px; color: var(--text-sec); margin-left: 8px; }

/* ===== Special Characters Grid ===== */
.chars-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
}
.char-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-light);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .1s;
}
.char-btn:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
}

/* ===== Help Panel ===== */
.help-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 800;
  display: flex;
  flex-direction: column;
}
.help-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.shortcuts-panel { width: 440px; }
.shortcuts-body { padding: 16px; }

.shortcut-category {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin: 16px 0 8px;
}
.shortcut-category:first-child { margin-top: 0; }

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border-light);
}
.shortcut-keys {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  background: var(--header-bg);
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-weight: 500;
}
.shortcut-desc { color: var(--text-sec); }

/* ===== Save Notification ===== */
.save-notification {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: #323232;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.save-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Dark Theme ===== */
body.dark-theme {
  --primary: #8ab4f8;
  --primary-light: #2d3a4a;
  --primary-bg: rgba(138,180,248,0.15);
  --border: #555;
  --border-light: #444;
  --header-bg: #2a2a2a;
  --toolbar-bg: #2d2d2d;
  --text: #e8eaed;
  --text-sec: #9aa0a6;
  --surface: #1e1e1e;
  --page-bg: #333;
}
body.dark-theme .doc-page {
  background: #292929;
}
body.dark-theme .doc-editor table th {
  background: #333;
}
body.dark-theme .doc-editor .page-break::after {
  background: #333;
}
body.dark-theme .save-notification {
  background: #555;
}

/* ===== Print ===== */
@media print {
  .menu-bar, .toolbar, .doc-ruler, .status-bar,
  .dialog, .help-panel, .save-notification { display: none !important; }

  body { background: white !important; overflow: visible !important; }
  #app { height: auto !important; }

  .doc-editor-container {
    overflow: visible !important;
    background: white !important;
    padding: 0 !important;
  }
  .doc-page {
    box-shadow: none !important;
    margin: 0 !important;
    width: 100% !important;
    min-height: auto !important;
  }
  .doc-editor {
    padding: 0 !important;
  }
  .doc-editor .page-break {
    border: none;
    margin: 0;
    page-break-after: always;
  }
  .doc-editor .page-break::after { display: none; }
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .toolbar {
    padding: 2px 4px;
    gap: 1px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .toolbar-group { padding: 0 2px; border-right: none; }
  .toolbar-select { max-width: 80px; font-size: 11px; }
  .doc-page { width: 100% !important; min-height: auto !important; }
  .doc-editor { padding: 16px !important; font-size: 14px; }
  .doc-header-footer { padding: 8px 16px; }
  .help-panel, .shortcuts-panel { width: 100vw; }
  .dialog { max-width: 95vw; }
  .doc-ruler { display: none; }
}
