/* SyncNote web UI */
:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --ink: #1d1b17;
  --muted: #7a746a;
  --line: #e4ded3;
  --sel: #eaf0ea;
  --accent: #0d6b63;
  --accent-ink: #ffffff;
  --danger: #b3392b;
  --warn: #b7791f;
  --ok: #2f855a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --surface: #1a1d1b;
    --ink: #ece8df;
    --muted: #9a958a;
    --line: #2a2e2b;
    --sel: #222a27;
    --accent: #45b8ab;
    --accent-ink: #06201d;
    --danger: #ef7a6b;
    --warn: #e3b25a;
    --ok: #62c48d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }
.brand { font: 600 21px/1 var(--serif); letter-spacing: -0.01em; margin: 0; }

/* ---- buttons / inputs ---- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sel); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.wide { width: 100%; padding: 11px 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=search], input[type=password], input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 12px;
}

/* ---- toasts ---- */
.toasts { position: fixed; z-index: 50; left: 0; right: 0; bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100vw - 32px);
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transition: opacity .35s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---- auth ---- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px 26px 26px; display: grid; gap: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.auth-card input { color: var(--ink); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 9px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 8px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---- app shell ---- */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; height: 56px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.nav { display: flex; gap: 4px; }
.nav button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.nav button.active { background: var(--sel); color: var(--ink); font-weight: 600; }
.who { font-size: 14px; }

.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.conn[data-state=live] i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.conn[data-state=connecting] i { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.view { flex: 1; min-height: 0; }

/* ---- notes ---- */
.notes-view { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; }
.list-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.list-tools { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.note-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.note-item {
  display: grid; gap: 2px; width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 0; border-radius: 9px; padding: 10px 12px;
}
.note-item:hover { background: var(--sel); }
.note-item.active { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
.ni-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ni-snippet { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ni-time { color: var(--muted); font-size: 12px; }

.empty { color: var(--muted); text-align: center; padding: 28px 16px; margin: 0; }
.empty.big { display: grid; place-items: center; height: 100%; font-family: var(--serif); font-size: 20px; }

.editor-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.editor { display: flex; flex-direction: column; flex: 1; min-height: 0; max-width: 820px; width: 100%; margin: 0 auto; padding: 8px 20px 12px; }
.editor-bar { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.back { display: none; }
.save-state { font-size: 13px; color: var(--muted); }
.save-state[data-state=saving], .save-state[data-state=dirty] { color: var(--warn); }
.save-state[data-state=conflict], .save-state[data-state=error] { color: var(--danger); }
.save-state[data-state=remote] { color: var(--accent); }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 8px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); font-size: 14px; }
.banner span { flex: 1 1 220px; }

.note-title { border: 0 !important; background: transparent !important; font: 600 28px/1.25 var(--serif) !important; padding: 8px 0 !important; border-radius: 0 !important; }
.note-title:focus { outline: none; }
.note-content { flex: 1; min-height: 0; width: 100%; resize: none; border: 0; background: transparent; padding: 4px 0 12px; font-size: 16px; line-height: 1.7; }
.note-content:focus { outline: none; }
.note-meta { font-size: 12px; padding-top: 6px; border-top: 1px solid var(--line); }

/* ---- files ---- */
.files-view { overflow-y: auto; }
.files-inner { max-width: 820px; margin: 0 auto; padding: 20px 16px 40px; display: grid; gap: 14px; }
.dropzone { display: grid; gap: 4px; text-align: center; padding: 26px 16px; border: 2px dashed var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone span { color: var(--muted); font-size: 14px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--sel); }

.upload-list, .file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.upload { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.u-top { display: flex; align-items: center; gap: 10px; }
.u-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-size, .status { font-size: 13px; color: var(--muted); }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.upload.ok .status { color: var(--ok); }
.upload.err { border-color: var(--danger); }
.upload.err .status { color: var(--danger); }

.file { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.thumb { flex: none; width: 48px; height: 48px; border-radius: 9px; overflow: hidden; background: var(--sel); display: grid; place-items: center; color: var(--accent); font: 700 12px var(--sans); letter-spacing: .03em; text-decoration: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.f-main { flex: 1; min-width: 0; display: grid; }
.f-name { color: var(--ink); text-decoration: none; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-name:hover { text-decoration: underline; }
.f-meta { color: var(--muted); font-size: 13px; }
.f-actions { display: flex; gap: 2px; flex: none; }
a.btn { text-decoration: none; display: inline-block; }

/* ---- small screens: list and editor become two screens ---- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .who { display: none; }
  .conn span { display: none; }
  .notes-view { grid-template-columns: 1fr; }
  .notes-view.editing .list-pane { display: none; }
  .notes-view:not(.editing) .editor-pane { display: none; }
  .back { display: inline-block; }
  .editor { padding: 4px 14px 10px; }
  .note-title { font-size: 24px !important; }
  .f-actions { flex-direction: column; }
}
