/* ============================================================
   Document editor — self-contained styles (no external fonts/CDN)
   Dark, tablet-friendly, works standalone or inside an iframe.
   ============================================================ */

:root {
  --bg:        #0f1116;
  --bg-2:      #161922;
  --bg-3:      #1d2130;
  --panel:     #191d28;
  --line:      #2a2f3d;
  --line-2:    #363c4d;
  --text:      #e7e9ee;
  --text-dim:  #9aa2b1;
  --text-mute: #6b7280;
  --accent:    #4c8dff;
  --accent-2:  #3a6fd8;
  --danger:    #ff5c5c;
  --danger-bg: #3a1f24;
  --good:      #43c187;
  --radius:    10px;
  --page:      #1a1e29;
  --shadow:    0 10px 40px rgba(0,0,0,.45);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:      "SFMono-Regular", ui-monospace, Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  justify-content: center;
}
.btn:hover { background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn .ic { font-size: 17px; line-height: 1; }

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ============================================================
   AUTH
   ============================================================ */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 50% -20%, rgba(76,141,255,.14), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff;
}
.auth-brand h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: .2px; }
.auth-tagline { margin: 4px 0 0; color: var(--text-dim); font-size: 14px; }

.auth-tabs {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.auth-tab.active { background: var(--bg-3); color: var(--text); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76,141,255,.18); }

.auth-error {
  margin: 0 0 14px;
  padding: 9px 11px;
  background: var(--danger-bg);
  border: 1px solid #5a2b32;
  border-radius: 8px;
  color: #ffb4b4;
  font-size: 13px;
}
.auth-hint { text-align: center; color: var(--text-dim); font-size: 13.5px; margin: 16px 0 0; }
.auth-hint a { color: var(--accent); text-decoration: none; }
.auth-hint a:hover { text-decoration: underline; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app { display: flex; height: 100%; }

.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 14px 14px 10px; }
.sidebar-search { padding: 0 14px 10px; }
.sidebar-search input {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }

.doc-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.doc-item {
  padding: 10px 11px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
}
.doc-item:hover { background: var(--bg-3); }
.doc-item.active { background: var(--bg-3); border-color: var(--line-2); }
.doc-item .di-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item .di-meta { font-size: 11.5px; color: var(--text-mute); margin-top: 2px; }
.doc-empty { padding: 22px 14px; text-align: center; color: var(--text-mute); font-size: 13px; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.who { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Editor pane ---------- */
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
#toggle-sidebar { display: none; }
.doc-title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  outline: none;
}
.doc-title:hover { background: var(--bg-3); }
.doc-title:focus { background: var(--bg-3); border-color: var(--line-2); }

.save-status {
  font-size: 12.5px;
  color: var(--text-mute);
  white-space: nowrap;
  min-width: 62px;
  text-align: right;
}
.save-status.saving { color: var(--text-dim); }
.save-status.saved { color: var(--good); }
.save-status.error { color: var(--danger); }
.topbar-actions { display: flex; gap: 2px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.tb-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 6px;
  margin-right: 4px;
  border-right: 1px solid var(--line);
}
.tb-group:last-child { border-right: 0; }
.tb-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tb-btn:hover { background: var(--bg-3); color: var(--text); }
.tb-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-select {
  height: 32px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 7px;
  padding: 0 8px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.tb-color {
  position: relative;
  height: 32px;
  min-width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 700;
}
.tb-color:hover { background: var(--bg-3); color: var(--text); }
.tb-color span { pointer-events: none; }
.tb-color.hl span { color: #ffd54a; }
.tb-color input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  border: 0;
  cursor: pointer;
}

/* ---------- Page / editor surface ---------- */
.page-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 24px 20px 8px;
  background: var(--bg);
}
.page {
  max-width: 820px;
  margin: 0 auto;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 46px 56px;
  min-height: 60vh;
}
.editor {
  outline: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  min-height: 50vh;
  word-wrap: break-word;
}
.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-mute);
  pointer-events: none;
}
.editor h1 { font-size: 28px; margin: .5em 0 .3em; font-weight: 650; }
.editor h2 { font-size: 23px; margin: .5em 0 .3em; font-weight: 640; }
.editor h3 { font-size: 19px; margin: .5em 0 .3em; font-weight: 620; }
.editor p { margin: 0 0 .7em; }
.editor ul, .editor ol { margin: 0 0 .7em; padding-left: 1.6em; }
.editor li { margin: .15em 0; }
.editor a { color: var(--accent); }
.editor blockquote {
  margin: 0 0 .7em;
  padding: 4px 16px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.editor pre {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 14px;
  overflow-x: auto;
  margin: 0 0 .7em;
}
.editor hr { border: 0; border-top: 1px solid var(--line-2); margin: 1.1em 0; }
.editor img { max-width: 100%; height: auto; border-radius: 6px; }

.pagefoot {
  max-width: 820px;
  margin: 8px auto 0;
  padding: 0 4px 8px;
  color: var(--text-mute);
  font-size: 12px;
  text-align: right;
}

/* ---------- Empty state ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  top: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  text-align: center;
  padding: 24px;
}
.empty-inner { max-width: 340px; }
.empty-logo { font-size: 46px; opacity: .8; margin-bottom: 8px; }
.empty-state h2 { margin: 0 0 6px; font-size: 20px; }
.empty-state p { margin: 0 0 18px; color: var(--text-dim); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 90%;
}
.toast.err { border-color: #5a2b32; background: var(--danger-bg); color: #ffb4b4; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #454b5e; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   RESPONSIVE — tablet & narrow (lb-tablet iframe)
   ============================================================ */
@media (max-width: 760px) {
  #toggle-sidebar { display: inline-flex; }
  .sidebar {
    position: absolute;
    z-index: 30;
    top: 0; bottom: 0; left: 0;
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 20;
  }
  .page { padding: 28px 22px; border-radius: 10px; }
  .page-scroll { padding: 14px 12px 8px; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .toolbar, .pagefoot, #toast { display: none !important; }
  body, .app, .editor-pane, .page-scroll { height: auto; overflow: visible; background: #fff; }
  .page {
    box-shadow: none; border: 0; max-width: none;
    background: #fff; color: #000; padding: 0;
  }
  .editor, .editor * { color: #000 !important; }
}
