/* ==========================================================================
   TermaType — Application Shell
   Premium Tibetan Word Processor
   Design System: Warm editorial, sacred aesthetics, zero distraction
   ========================================================================== */

/* ── DESIGN TOKENS ─────────────────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --c-bg:           #F2EDE6;   /* warm parchment app bg */
  --c-page:         #FDFBF8;   /* near-white writing surface */
  --c-toolbar:      #FAF7F3;
  --c-titlebar:     #1C1916;   /* ebony dark */
  --c-panel:        #FAFAF8;   /* dictionary panel */
  --c-panel-header: #F2EDE6;
  --c-statusbar:    #EDEAE4;

  /* Accents */
  --c-accent:       #C97A1E;   /* saffron fire */
  --c-accent-dark:  #A36418;
  --c-accent-light: #E8A94B;
  --c-accent-pale:  #FBF0DC;   /* very pale saffron for active states */
  --c-crimson:      #8B1A1A;   /* traditional Tibetan red */

  /* Typography */
  --c-text:         #1A1714;   /* near-black, warm tint */
  --c-text-2:       #4A4540;   /* secondary */
  --c-text-3:       #8A837B;   /* muted / placeholder */
  --c-text-inv:     #F7F4F0;   /* inverted (on dark bg) */

  /* Borders */
  --c-border:       #E0D9D0;   /* light border */
  --c-border-2:     #CBC3B8;   /* medium border */
  --c-border-toolbar: #ECEAE6;

  /* Shadows */
  --shadow-page:    0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.08), 0 16px 40px rgba(0,0,0,0.06);
  --shadow-popup:   0 8px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);

  /* Radii */
  --r-sm:   4px;
  --r-md:   6px;
  --r-lg:   10px;
  --r-page: 3px;

  /* Motion */
  --t-fast: 120ms ease;
  --t-base: 200ms ease;
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --h-titlebar:  42px;
  --h-toolbar:   50px;
  --h-statusbar: 26px;
  --w-panel:     300px;
  --w-page-max:  860px;
  --h-page-min:  1216px;  /* A4 portrait aspect ratio */
  --page-pad:    80px;

  /* Font stacks */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', Consolas, monospace;
}

/* ── GLOBAL RESET ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Force all form controls to use UI font — browsers override otherwise */
input, button, select, textarea, optgroup, option {
  font-family: var(--font-ui);
  font-size: inherit;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* ── APP LAYOUT ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── TITLE BAR ──────────────────────────────────────────────────────────────── */
#title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--h-titlebar);
  background: var(--c-titlebar);
  padding: 0 4px 0 12px;
  flex-shrink: 0;
  -webkit-app-region: drag;
}

.tb-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-wordmark {
  display: flex;
  align-items: center;
  gap: 7px;
}

.app-wordmark-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: contain;
}

.app-wordmark-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-inv);
  letter-spacing: -0.2px;
  opacity: 0.92;
}

.tb-divider-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
}

#doc-title-display {
  font-size: 12.5px;
  color: rgba(255,255,255,0.6);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast), color var(--t-fast);
  -webkit-app-region: no-drag;
}

#doc-title-display:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
}

.tb-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  -webkit-app-region: no-drag;
}

.save-badge.saved   { color: rgba(255,255,255,0.38); }
.save-badge.saving  { color: var(--c-accent-light); }
.save-badge.unsaved { color: #E07070; }

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  transition: opacity var(--t-base), background var(--t-base);
}
/* Hide dot when cleanly saved — only show on unsaved/saving state */
.save-badge.saved .save-dot { opacity: 0; }

/* Window control buttons (Tauri desktop) */
.win-controls {
  display: flex;
  gap: 1px;
  margin-left: 6px;
}

.win-btn {
  width: 32px;
  height: var(--h-titlebar);
  border: none;
  background: none;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  -webkit-app-region: no-drag;
}

.win-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}

.win-btn.win-close:hover {
  background: #C42B1C;
  color: white;
}

/* ── CONTENT AREA ────────────────────────────────────────────────────────────── */
#content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── EDITOR REGION ───────────────────────────────────────────────────────────── */
#editor-region {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── DICTIONARY PANEL ────────────────────────────────────────────────────────── */
#dictionary-panel {
  width: var(--w-panel);
  min-width: var(--w-panel);
  background: var(--c-panel);
  border-left: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  will-change: width;
  transition: width var(--t-slow), min-width var(--t-slow),
              opacity var(--t-slow), border-width var(--t-slow);
}

#dictionary-panel.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  border-left-width: 0;
  pointer-events: none;
}

/* ── MODAL OVERLAY ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--c-toolbar);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-popup);
  padding: 28px;
  min-width: 380px;
  max-width: 480px;
  width: 100%;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 16px;
}

.modal-body {
  font-size: 13px;
  color: var(--c-text-2);
  line-height: 1.6;
  margin-bottom: 20px;
}

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

.btn {
  padding: 7px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-toolbar);
  color: var(--c-text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
}

.btn:hover { background: var(--c-panel-header); }

.btn-primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: white;
}
.btn-primary:hover { background: var(--c-accent-dark); border-color: var(--c-accent-dark); }

.btn-danger {
  background: var(--c-crimson);
  border-color: var(--c-crimson);
  color: white;
}

/* ── POPUPS ──────────────────────────────────────────────────────────────────── */
.popup {
  position: fixed;
  background: var(--c-toolbar);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-popup);
  z-index: 500;
  overflow: hidden;
}

.popup.hidden { display: none; }

/* ── SCROLLBAR STYLING ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-text-3); }

/* ── PRINT STYLES ────────────────────────────────────────────────────────────── */
@media print {
  #title-bar,
  #toolbar,
  #status-bar,
  #dictionary-panel { display: none !important; }

  #editor-scroll {
    overflow: visible !important;
    background: white !important;
  }

  #editor-page {
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    border-radius: 0 !important;
  }

  #editor {
    padding: 0 !important;
  }
}

@media (max-width: 768px) {
  :root { --page-pad: 40px; }
}
@media (max-width: 480px) {
  :root { --page-pad: 16px; }
}

/* ── DRAG/DROP HIGHLIGHT ─────────────────────────────────────────────────────── */
#editor.drag-over {
  outline: 2px dashed var(--c-accent);
  outline-offset: -8px;
}

/* ── FOCUS MODE — Full immersive ────────────────────────────────────────── */
body.focus-mode #title-bar,
body.focus-mode #toolbar,
body.focus-mode #status-bar,
body.focus-mode #dictionary-panel {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

body.focus-mode #status-bar {
  transform: translateY(10px);
}

body.focus-mode #editor-scroll {
  padding-top: 60px;
  padding-bottom: 60px;
}

body.focus-mode #content-area {
  position: relative;
}

body.focus-mode #editor-page {
  box-shadow: none;
  border-radius: 0;
  max-width: 760px;
}

/* ── FOCUS CIRCLE (escape hatch — only visible in focus mode) ─────────────── */
.fm-circle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--c-titlebar);
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: background 0.2s ease, color 0.2s ease,
              box-shadow 0.3s ease, opacity 0.25s ease;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

/* Show only in focus mode (toolbar is hidden, circle is the exit button) */
body.focus-mode .fm-circle {
  opacity: 1;
  pointer-events: all;
}
body.focus-mode .fm-circle:hover {
  background: var(--c-accent);
  color: white;
  box-shadow: 0 2px 16px rgba(201,122,30,0.35);
}

/* ── IME HINT TOOLTIP ────────────────────────────────────────────────────── */
.imeh-hint {
  position: fixed;
  bottom: 48px;
  right: 20px;
  z-index: 850;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.imeh-hint.imeh-visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.imeh-hint-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--c-titlebar);
  color: var(--c-text-inv);
  padding: 14px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  max-width: 300px;
}

.imeh-hint-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.imeh-hint-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255,255,255,0.7);
}

.imeh-hint-text strong {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
}

.imeh-hint-text kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--c-accent-light);
}

.imeh-hint-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.3);
  padding: 2px;
  flex-shrink: 0;
  transition: color 0.12s;
}
.imeh-hint-close:hover { color: rgba(255,255,255,0.8); }

/* ── IME TOGGLE TOAST ────────────────────────────────────────────────────── */
.imeh-toast {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--c-titlebar);
  color: var(--c-text-inv);
  font-family: var(--font-ui);
  font-size: 12px;
  padding: 8px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  white-space: nowrap;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.imeh-toast.imeh-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── DOCUMENT SETTINGS MODAL ─────────────────────────────────────────────── */
.ds-modal {
  min-width: 420px;
}

.ds-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.ds-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ds-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--c-text-2);
  letter-spacing: 0.2px;
}

.ds-select, .ds-input {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-page);
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--c-text);
  outline: none;
  transition: border-color 0.15s;
}

.ds-select:focus, .ds-input:focus {
  border-color: var(--c-accent);
}

@media (max-width: 480px) {
  .ds-grid { grid-template-columns: 1fr; }
  .ds-modal { min-width: 0; }
}

/* ==========================================================================
   MODAL DIALOG — Shared (Save As, Typing Tips)
   ========================================================================== */
.modal-dialog {
  background: var(--c-page);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 48px rgba(0,0,0,0.22), 0 4px 12px rgba(0,0,0,0.10);
  max-height: 85vh;
  overflow-y: auto;
  width: 100%;
}

.modal-dialog .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--c-border);
}

.modal-dialog .modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 0;
}

.modal-dialog .modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--c-text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-dialog .modal-close:hover {
  background: var(--c-bg);
  color: var(--c-text);
}

.modal-dialog .modal-body {
  padding: 8px 8px;
  margin-bottom: 0;
}

/* ── FILE PANEL — Slide-in from left ───────────────────────────────────── */
.file-panel {
  position: fixed;
  top: calc(var(--h-titlebar) + var(--h-toolbar));
  left: 0;
  bottom: var(--h-statusbar);
  width: 220px;
  background: var(--c-panel);
  border-right: 1px solid var(--c-border);
  z-index: 450;
  display: flex;
  flex-direction: column;
  transition: transform var(--t-slow), opacity var(--t-base);
  box-shadow: 2px 0 12px rgba(0,0,0,0.06);
}

.file-panel.collapsed {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.file-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--c-border);
}

.file-panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
}

.file-panel-body {
  padding: 6px 8px;
  flex: 1;
  overflow-y: auto;
}

.file-panel-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--c-text);
  text-align: left;
  white-space: nowrap;
  transition: background var(--t-fast);
}
.file-panel-action:hover {
  background: var(--c-bg);
}

.file-panel-action kbd {
  margin-left: auto;
  font-family: var(--font-ui);
  font-size: 10.5px;
  color: var(--c-text-3);
  padding-left: 12px;
}

.fp-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fp-section-label {
  display: block;
  padding: 8px 10px 3px;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: default;
}

.file-panel-sep {
  height: 1px;
  background: var(--c-border);
  margin: 4px 10px;
}

/* ── SAVE AS DIALOG ─────────────────────────────────────────────────────── */
.saveas-dialog {
  max-width: 340px;
}

.saveas-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast);
}
.saveas-option:hover {
  background: var(--c-accent-pale);
}

.saveas-ext {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-accent-dark);
  background: var(--c-accent-pale);
  padding: 3px 8px;
  border-radius: var(--r-sm);
  min-width: 56px;
  text-align: center;
  flex-shrink: 0;
}

.saveas-desc {
  font-size: 12.5px;
  color: var(--c-text-2);
  font-family: var(--font-ui);
  line-height: 1.4;
}

/* ── TYPING TIPS — Right Side Panel ─────────────────────────────────────── */
.tips-panel {
  position: fixed;
  top: calc(var(--h-titlebar) + var(--h-toolbar));
  right: 0;
  bottom: var(--h-statusbar);
  width: 240px;
  background: var(--c-panel);
  border-left: 1px solid var(--c-border);
  z-index: 400;
  display: flex;
  flex-direction: column;
  transition: transform var(--t-slow), opacity var(--t-base);
  box-shadow: -2px 0 12px rgba(0,0,0,0.06);
}

.tips-panel.collapsed {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

.tips-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.tips-header-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
}

.tips-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px;
}

.tips-section {
  margin-bottom: 14px;
}
.tips-section:last-child { margin-bottom: 0; }

.tips-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--c-accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.tips-hint {
  font-size: 11px;
  color: var(--c-text-3);
  line-height: 1.5;
  margin-bottom: 6px;
}

.tips-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 11.5px;
  color: var(--c-text-2);
}

.tips-item kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  background: var(--c-toolbar);
  border: 1px solid var(--c-border);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--c-text);
  box-shadow: 0 1px 0 var(--c-border-2);
  white-space: nowrap;
  flex-shrink: 0;
}

.tips-item .tb, .tips-grid-compact .tb, .tips-example .tb {
  font-family: 'Jomolhari', 'Noto Sans Tibetan', serif;
  font-size: 15px;
  color: var(--c-text);
}

.tips-item .tb.lg, .tips-example .tb.lg {
  font-size: 18px;
}

.tips-example {
  padding: 4px 0 2px;
  font-size: 11px;
  color: var(--c-text-3);
  font-style: italic;
}

.tips-grid-compact {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 2px;
}

.tips-grid-compact > span {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 0;
  font-size: 11px;
}

.tips-grid-compact kbd {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  background: var(--c-toolbar);
  border: 1px solid var(--c-border);
  border-radius: 2px;
  padding: 0 3px;
  color: var(--c-text);
  box-shadow: 0 1px 0 var(--c-border-2);
}

/* Tips panel scrollbar */
.tips-scroll::-webkit-scrollbar { width: 3px; }
.tips-scroll::-webkit-scrollbar-thumb { background: var(--c-border-2); border-radius: 2px; }

@media (max-width: 560px) {
  .tips-panel { width: 200px; }
}
