/* Minimalist Web Notepad — note.ms style */

:root {
  --font: 'SF Mono', 'Cascadia Code', 'Consolas', 'Menlo', monospace;
  --bg:       #ebeef2;
  --surface:  #fff;
  --text:     #333;
  --text-dim: #bbb;
  --border:   rgba(0,0,0,.06);
  --radius:   6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #1a1a1a;
    --surface:  #222;
    --text:     #ddd;
    --text-dim: #888;
    --border:   rgba(255,255,255,.06);
  }
}

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

html, body {
  height: 100%;
  background: var(--bg);
  transition: background .3s;
}

/* ── Stack: outer wrapper ─────────────────────────── */

.stack {
  position: fixed;
  inset: 20px;
  display: flex;
  flex-direction: column;
}

/* ── Layers: paper-stack effect ──────────────────── */

.layer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.layer .layer {
  box-shadow: 0 0 0 1px var(--border);
}

.layer .layer .layer {
  box-shadow: 0 1px 4px rgba(0,0,0,.04), 0 0 0 1px var(--border);
  background: var(--surface);
  border-radius: var(--radius);
}

/* ── Editor (contenteditable div) ──────────────── */

textarea.content, #content {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 18px;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
  border-radius: var(--radius);

  /* Hide scrollbar but keep scrolling */
  scrollbar-width: none;
  -ms-overflow-style: none;

  font-family: var(--font);
  font-size: 20px;  line-height: 1.7;
  color: var(--text);
  background: transparent;
}

#content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

textarea.content::-webkit-scrollbar,
#content::-webkit-scrollbar {
  display: none;
}

.flag {
  flex-shrink: 0;
  padding: 10px 0 0 2px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

.flag a {
  color: inherit;
  text-decoration: none;
}

.flag a:hover {
  text-decoration: underline;
}

/* ── Print ───────────────────────────────────────── */

#printable { display: none; }

@media print {
  .stack { display: none; }
  #printable {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font);
    font-size: 10pt;
    line-height: 1.6;
    padding: 0.5in;
    color: #000;
  }
}

/* ── Status bar ──────────────────────────────────── */

#status-bar {
  position: fixed;
  bottom: 14px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}

.stack:focus-within ~ #status-bar,
#status-bar:hover {
  opacity: 1;
}

#status-indicator {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status--idle   { background: var(--text-dim); }
.status--saving { background: #f5a623; }
.status--saved  { background: #4cd964; }
.status--error  { background: #ff3b30; }

#status-text {
  font-size: 11px;
  color: var(--text-dim);
  user-select: none;
}

/* ── Mobile ──────────────────────────────────────── */

@media (max-width: 480px) {
  .stack { inset: 10px; }
  textarea.content, #content { padding: 12px; font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* ── Table (inside contenteditable) ──────────────── */

#content table {
  border-collapse: collapse;
  margin: 8px 0;
  width: auto;
  min-width: 60%;
}

#content th, #content td {
  border: 1px solid var(--text-dim);
  padding: 6px 12px;
  min-width: 60px;
  text-align: left;
  vertical-align: top;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
}

#content th {
  font-weight: 600;
}

#content td:focus, #content th:focus {
  background: rgba(0,122,255,.06);
  border-color: #007aff;
}

@media (prefers-color-scheme: dark) {
  #content th, #content td {
    border-color: #555;
  }
  #content td:focus, #content th:focus {
    background: rgba(10,132,255,.12);
    border-color: #0a84ff;
  }
}

/* ── Context Menu ────────────────────────────────── */

.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  padding: 4px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
}

.ctx-menu button {
  display: block;
  width: 100%;
  padding: 6px 16px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}

.ctx-menu button:hover {
  background: rgba(0,122,255,.1);
}

.ctx-menu hr {
  margin: 4px 8px;
  border: none;
  border-top: 1px solid var(--border);
}

/* ── Insert Table Dialog ─────────────────────────── */

#dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

#dialog-box {
  background: var(--surface);
  border-radius: 10px;
  padding: 24px 28px;
  box-shadow: 0 8px 40px rgba(0,0,0,.15);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}

#dialog-box h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}

#dialog-box .row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#dialog-box label {
  min-width: 50px;
}

#dialog-box input {
  width: 70px;
  padding: 4px 8px;
  border: 1px solid var(--text-dim);
  border-radius: 4px;
  font-size: 14px;
  background: transparent;
  color: var(--text);
  text-align: center;
}

#dialog-box .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

#dialog-box .actions button {
  padding: 6px 18px;
  border: 1px solid var(--text-dim);
  border-radius: 6px;
  font-size: 13px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

#dialog-box .actions button.primary {
  background: #007aff;
  color: #fff;
  border-color: #007aff;
}

@media (prefers-color-scheme: dark) {
  #dialog-box .actions button.primary {
    background: #0a84ff;
    border-color: #0a84ff;
  }
}
