@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Noto+Sans+Devanagari:wght@400;700&display=swap');

:root {
  --bg-color: #f3f2f1;
  --ribbon-bg: #ffffff;
  --primary-blue: #0078D4;
  --text-main: #323130;
  --border-color: #e1dfdd;
  --paper-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* RIBBON & TOOLBAR */
header {
  background-color: var(--ribbon-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.row-1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doc-title {
  font-size: 16px;
  font-weight: 500;
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: 4px;
  outline: none;
  text-align: center;
  min-width: 200px;
}

.doc-title:hover, .doc-title:focus {
  background-color: #f3f2f1;
  border-color: #c8c6c4;
}

.btn {
  background: #f3f2f1;
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
  transition: background 0.2s;
}

.btn:hover {
  background: #e1dfdd;
}

.btn-primary {
  background: var(--primary-blue);
  color: white;
  border: none;
}
.btn-primary:hover {
  background: #005a9e;
}

.row-2 {
  display: flex;
  gap: 16px;
  align-items: center;
}

.tool-group {
  display: flex;
  gap: 4px;
  border-right: 1px solid var(--border-color);
  padding-right: 16px;
  align-items: center;
}

.tool-group:last-child {
  border-right: none;
}

.toggle-group {
  display: flex;
  background: #f3f2f1;
  border-radius: 6px;
  padding: 2px;
}

.toggle-btn {
  border: none;
  background: transparent;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.toggle-btn.active {
  background: white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  font-weight: 500;
}
.toggle-btn:hover:not(.active) {
  background: #e1dfdd;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-main);
  transition: background 0.1s;
}

.icon-btn:hover {
  background: #e1dfdd;
}

.icon-btn.active-format {
  background: #c8c6c4;
  color: var(--primary-blue);
}
/* MAIN WORKSPACE */
.workspace {
  flex-grow: 1;
  overflow-y: auto;
  padding: 32px 0 64px 0;
  display: flex;
  justify-content: center;
}

.page {
  background: white;
  width: 794px; /* A4 width roughly at 96 PPI */
  min-height: 1123px;
  box-shadow: var(--paper-shadow);
  padding: 96px;
  position: relative;
}

#editor {
  outline: none;
  font-family: 'Noto Sans Devanagari', sans-serif;
  font-size: 16pt;
  line-height: 1.8;
  min-height: 100%;
}

#editor h1, #editor h2, #editor h3 {
  font-weight: 700;
  margin-top: 1em;
  margin-bottom: 0.5em;
  line-height: 1.4;
}

#editor h1 { font-size: 2.2em; }
#editor h2 { font-size: 1.8em; }
#editor p { margin-bottom: 1em; }

[contenteditable=true]:empty:before {
  content: attr(placeholder);
  color: #a19f9d;
  pointer-events: none;
}

/* SUGGESTION BOX */
.suggestion-box {
  position: absolute;
  background: white;
  border: 1px solid #c8c6c4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  border-radius: 6px;
  display: none;
  z-index: 100;
  font-family: 'Noto Sans Devanagari', sans-serif;
  overflow: hidden;
}

.suggestion-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14pt;
}

.suggestion-item:hover, .suggestion-item.active {
  background: #f3f2f1;
}

/* STATUS BAR */
footer {
  background: var(--primary-blue);
  color: white;
  padding: 4px 16px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  z-index: 10;
}

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: #323130;
  color: white;
  padding: 8px 16px;
  border-radius: 24px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 1000;
}

.toast-container.show {
  opacity: 1;
}

/* RESPONSIVE */
@media (max-width: 850px) {
  .page {
    width: 95%;
    padding: 40px;
  }
}

/* PRINT MEDIA */
@media print {
  body {
    background: white;
    height: auto;
    overflow: visible;
  }
  header, footer, .suggestion-box, .toast-container {
    display: none !important;
  }
  .workspace {
    padding: 0;
    margin: 0;
    overflow: visible;
    display: block; /* Removed flex center causing issues in print */
  }
  .page {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  @page {
    size: A4;
    margin: 20mm;
  }
}

/* --- MINIMALIST FEATURES --- */

/* Dark Mode */
body.dark-mode {
  --bg-color: #202020;
  --ribbon-bg: #2d2d2d;
  --primary-blue: #2b88d8;
  --text-main: #e1dfdd;
  --border-color: #3e3e42;
  --paper-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
}
body.dark-mode .page {
  background: #2d2d2d;
}
body.dark-mode .btn,
body.dark-mode .toggle-group,
body.dark-mode .suggestion-box,
body.dark-mode .find-replace-panel,
body.dark-mode .floating-menu {
  background: #3e3e42;
  color: #fff;
}
body.dark-mode .doc-title:hover, 
body.dark-mode .doc-title:focus {
  background-color: #3e3e42;
  border-color: #505050;
  color: white;
}
body.dark-mode input.doc-title {
  color: var(--text-main);
}
body.dark-mode .btn:hover, 
body.dark-mode .toggle-btn:hover:not(.active), 
body.dark-mode .icon-btn:hover {
  background: #505050;
}
body.dark-mode .icon-btn.active-format {
  background: #505050;
  color: #6eb5f0;
}
body.dark-mode .toggle-btn.active {
  background: #202020;
  color: #fff;
  box-shadow: none;
}
body.dark-mode .fr-row input {
  background: #202020;
  color: white;
}

/* Zen Mode */
body.zen-mode header {
  display: none;
}
body.zen-mode footer {
  display: none;
}
body.zen-mode .workspace {
  padding-top: 0;
}
body.zen-mode .page {
  box-shadow: none;
  width: 100%;
  max-width: 900px;
}
.exit-zen-btn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  z-index: 200;
}
body.zen-mode .exit-zen-btn {
  display: block;
}
.exit-zen-btn:hover {
  background: rgba(0,0,0,0.8);
}

/* Find and Replace */
.find-replace-panel {
  position: absolute;
  top: 60px;
  right: 20px;
  background: white;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-radius: 6px;
  padding: 12px;
  display: none;
  z-index: 150;
  flex-direction: column;
  gap: 8px;
  width: 320px;
}
.fr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.fr-row input {
  flex-grow: 1;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  outline: none;
}
#find-count {
  font-size: 13px;
  color: #888;
}
.find-highlight {
  background-color: #fffb00;
  color: black;
}
.find-highlight.active-match {
  background-color: #ff9900;
}
body.dark-mode .find-highlight {
  background-color: #6a6a00;
  color: white;
}
body.dark-mode .find-highlight.active-match {
  background-color: #9c5c00;
}
.fr-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* Floating Formatting Menu */
.floating-menu {
  position: absolute;
  background: white;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  border-radius: 6px;
  display: none;
  z-index: 150;
  padding: 4px;
  flex-direction: row;
  align-items: center;
  gap: 2px;
}

/* --- OVERHAUL UI STYLES --- */
/* Color Pickers */
.color-picker {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: 1px solid var(--border-color); border-radius: 4px; }

body.dark-mode .color-picker::-webkit-color-swatch { border-color: #505050; }

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--border-color);
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  z-index: 500;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
}
.sidebar.open { left: 0; }
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.doc-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 8px;
}
.doc-card {
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.doc-card:hover { background: #f3f2f1; }
.doc-card.active { background: #eef5fb; border-color: #c8e0f6; }
.doc-title-text { font-weight: 500; margin-bottom: 4px; font-size: 14px; }
.doc-date { font-size: 11px; color: #888; }
.doc-actions { display:none; }
.doc-card:hover .doc-actions { display:flex; gap: 4px; margin-top: 8px; justify-content: flex-end; }
.doc-actions .icon-btn { width: 24px; height: 24px; font-size: 14px; }

/* Modals */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: none; justify-content: center; align-items: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  width: 450px; border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex; flex-direction: column;
}
.modal-header { padding: 16px; border-bottom: 1px solid var(--border-color); display:flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; max-height: 400px; overflow-y: auto; }

/* Visual Page Breaks */
.page {
  background-color: transparent !important;
  box-shadow: none !important;
}

/* Tooltip Prediction */
.predict-tooltip {
  position: absolute;
  background: #323130;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  display: none;
  z-index: 150;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.dict-item {
  display: flex; justify-content: space-between; padding: 8px; border-bottom: 1px solid var(--border-color);
}
.dict-item:last-child { border-bottom: none; }

/* Editor Images */
#editor img {
  max-width: 100%;
  object-fit: contain;
  border-radius: 4px;
  margin: 16px 0;
}

/* Table Styles */
#editor table { border-collapse: collapse; width: 100%; margin-bottom: 1em; table-layout: fixed; word-wrap: break-word; }
#editor table, #editor th, #editor td { border: 1px solid var(--border-color); }
#editor th, #editor td { padding: 8px; text-align: left; }
.table-grid-menu {
  position: absolute; top: 100%; left: 0; background: white;
  border: 1px solid var(--border-color); padding: 8px;
  display: grid; grid-template-columns: repeat(5, 16px); gap: 2px;
  z-index: 200; box-shadow: 0 4px 10px rgba(0,0,0,0.1); border-radius: 4px;
}
.grid-cell { width: 16px; height: 16px; border: 1px solid #ccc; cursor: pointer; }
.grid-cell.highlight { background: var(--primary-blue); border-color: var(--primary-blue); }

/* Virtual Keyboard */
.virtual-keyboard {
  position: fixed; bottom: -400px; left: 0; right: 0; height: 350px;
  background: #e1dfdd; border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1); z-index: 1000;
  transition: bottom 0.3s ease; display: flex; flex-direction: column;
}
.virtual-keyboard.open { bottom: 0; }
.vk-header { display: flex; justify-content: space-between; padding: 12px 20px; background: #f3f2f1; font-weight: bold; border-bottom: 1px solid #ccc; align-items:center; }
.vk-header span { font-size: 14px; }
.vk-keys { display: flex; flex-wrap: wrap; gap: 8px; padding: 20px; justify-content: center; overflow-y: auto; align-content: flex-start;}
.vk-key { padding: 10px 14px; background: white; border: 1px solid #ccc; border-radius: 6px; box-shadow: 0 2px 0 #ccc; cursor: pointer; font-family: 'Noto Sans Devanagari'; font-size: 18px; min-width: 44px; text-align: center; }
.vk-key:active { transform: translateY(2px); box-shadow: none; }
.btn-vk-toggle { position: fixed; bottom: 20px; right: 20px; z-index: 900; box-shadow: 0 4px 10px rgba(0,0,0,0.2); border-radius: 50px; padding: 12px 24px; display: flex; gap: 8px; align-items: center;}

/* Definition Tooltip */
.definition-tooltip {
  position: absolute; background: #323130; color: white; padding: 8px 12px;
  border-radius: 6px; font-size: 14px; z-index: 1000; display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); max-width: 250px; line-height: 1.4;
}
.definition-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border-width: 6px; border-style: solid; border-color: #323130 transparent transparent transparent;
}

/* Dark Mode Overrides */
body.dark-mode .sidebar, body.dark-mode .modal { background: #2d2d2d; color: white; }
body.dark-mode .doc-card:hover { background: #3e3e42; }
body.dark-mode .doc-card.active { background: #004578; border-color: #005a9e; }
body.dark-mode .page { background-color: transparent !important; }
body.dark-mode .physical-paper { background: #2d2d2d !important; }
body.dark-mode .predict-tooltip { background: #e1dfdd; color: #323130; }
body.dark-mode .virtual-keyboard { background: #2d2d2d; border-color: #444; }
body.dark-mode .vk-header { background: #1e1e1e; border-color: #444; color: white; }
body.dark-mode .vk-key { background: #3e3e42; border-color: #2d2d2d; color: white; box-shadow: 0 2px 0 #1e1e1e;}
body.dark-mode .table-grid-menu { background: #2d2d2d; border-color: #444; }

/* Print Settings for PDF Generation */
@media print {
  @page {
    size: A4;
    margin: 96px; /* Native hardware margins replace Javascript formatting logic exactly */
  }
  body, html { background: white !important; }
  header, footer, .virtual-keyboard, .floating-menu, .modal-overlay, .toast-container, .table-grid-menu, .predict-tooltip, .sidebar, .btn-vk-toggle, #paper-layer {
    display: none !important;
  }
  .workspace { padding: 0 !important; }
  .page {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    filter: none !important;
    width: 100% !important;
    min-height: 0 !important;
  }
  #editor {
    padding: 0 !important;
    margin: 0 !important;
  }
  #editor > * {
    margin-top: 0 !important; /* Resets JS margin logic for pure printer handling */
  }
}
