/* Cekkent Notes — minimal, system-theme-aware styling.
   Colors follow the OS light/dark preference automatically. */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --bg-2: #f6f7f9;
  --bg-3: #eceef1;
  --fg: #1b1d21;
  --fg-dim: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --hover: #00000008;
  --selected: #2563eb1a;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-w: 270px;
  --topbar-h: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --bg-2: #1d2025;
    --bg-3: #272b31;
    --fg: #e6e8eb;
    --fg-dim: #9aa1ab;
    --border: #2c3036;
    --accent: #4f8cff;
    --accent-fg: #0b1220;
    --danger: #f87171;
    --hover: #ffffff0d;
    --selected: #4f8cff26;
  }
}

* { box-sizing: border-box; }

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

button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ------------------------------ login ----------------------------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { text-align: center; max-width: 22rem; }
.login-logo { font-size: 3rem; }
.login-card h1 { font-size: 1.4rem; margin: .25rem 0; }
.login-card p { color: var(--fg-dim); margin-bottom: 1.5rem; }
.btn-google {
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .6rem 1.1rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-2); color: var(--fg); text-decoration: none; font-weight: 600;
}
.btn-google:hover { background: var(--bg-3); }

/* ------------------------------ shell ----------------------------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: .5rem;
  height: var(--topbar-h); padding: 0 .6rem;
  border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: .95rem; }
.spacer { flex: 1; }
.user-badge {
  font-size: .8rem; color: var(--fg-dim); max-width: 40vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  border: 0; background: transparent; color: var(--fg);
  width: 34px; height: 34px; border-radius: 7px; font-size: 1.05rem;
  display: grid; place-items: center; flex: 0 0 auto;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.danger:hover { color: var(--danger); }
#menuBtn { display: grid; }

.layout { flex: 1; display: flex; min-height: 0; position: relative; }

/* ----------------------------- sidebar ---------------------------- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--border); background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 0;
}
.search-row { padding: .55rem .55rem .35rem; }
.search-input {
  width: 100%; border: 1px solid var(--border); background: var(--bg);
  color: var(--fg); border-radius: 7px; padding: .4rem .55rem; font-size: .85rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.sidebar-actions { display: flex; gap: .4rem; padding: 0 .55rem .55rem; border-bottom: 1px solid var(--border); }
.btn {
  border: 1px solid var(--border); background: var(--bg);
  color: var(--fg); border-radius: 7px; padding: .4rem .6rem; font-size: .85rem; font-weight: 600;
}
.sidebar-actions .btn { flex: 1; }
.btn:hover { background: var(--bg-3); }

.tree { flex: 1; overflow: auto; padding: .35rem .25rem 1rem; }
.search-head { color: var(--fg-dim); font-size: .75rem; padding: .35rem .6rem; text-transform: uppercase; letter-spacing: .03em; }

.sidebar-foot { border-top: 1px solid var(--border); padding: .4rem .5rem; }
.link-btn {
  width: 100%; border: 0; background: transparent; color: var(--fg-dim);
  text-align: left; padding: .35rem .4rem; border-radius: 6px; font-size: .8rem;
}
.link-btn:hover { background: var(--hover); color: var(--fg); }

.row {
  display: flex; align-items: center; gap: .2rem;
  padding: .28rem .35rem; border-radius: 6px; cursor: pointer;
  font-size: .88rem; user-select: none; white-space: nowrap;
}
.row:hover { background: var(--hover); }
.row.selected { background: var(--selected); }
.row.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 6px; }
.row .twisty {
  width: 16px; flex: 0 0 16px; text-align: center; color: var(--fg-dim);
  font-size: .7rem; transition: transform .12s;
}
.row.collapsed .twisty { transform: rotate(-90deg); }
.row .ic { flex: 0 0 18px; text-align: center; }
.row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.row .row-actions { display: none; gap: .1rem; }
.row:hover .row-actions { display: flex; }
.row-actions button {
  border: 0; background: transparent; color: var(--fg-dim);
  width: 22px; height: 22px; border-radius: 5px; font-size: .8rem;
}
.row-actions button:hover { background: var(--bg-3); color: var(--fg); }
.row-actions button.danger:hover { color: var(--danger); }
.tree .empty-hint { color: var(--fg-dim); font-size: .8rem; padding: .5rem .6rem; }

/* Trash row, pinned at the bottom of the list. */
.row.trash-row { border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .4rem; }
.row.trash-row .row-actions { display: flex; } /* keep "empty" action visible (incl. mobile) */

.scrim { display: none; }

/* ----------------------------- editor ----------------------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty { flex: 1; display: grid; place-items: center; color: var(--fg-dim); padding: 2rem; text-align: center; }

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

.breadcrumb {
  display: flex; align-items: center; gap: .2rem;
  padding: .3rem .6rem; border-bottom: 1px solid var(--border);
  font-size: .82rem; color: var(--fg-dim);
}
.breadcrumb .icon-btn { width: 30px; height: 30px; font-size: .95rem; }
.crumbs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.crumbs .sep { opacity: .5; margin: 0 .25rem; }
.shared-by { color: var(--accent); font-weight: 600; }
.save-state { font-size: .75rem; color: var(--fg-dim); margin-right: .2rem; white-space: nowrap; }

.title-input {
  border: 0; background: transparent; color: var(--fg);
  font-size: 1.4rem; font-weight: 700; padding: .7rem .9rem .2rem;
  outline: none; width: 100%;
}

.mode-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; flex: 0 0 auto; }
.mode-tab { border: 0; background: var(--bg); color: var(--fg-dim); padding: .25rem .6rem; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.mode-tab.active { background: var(--accent); color: var(--accent-fg); }

/* Formatting buttons share the toolbar row with the mode toggle; this wrapper
   lets them flow as direct flex items and hides as a group in plain mode. */
.format-tools { display: contents; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .1rem;
  padding: .35rem .7rem; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.toolbar button { border: 0; background: transparent; color: var(--fg); min-width: 30px; height: 30px; padding: 0 .4rem; border-radius: 6px; font-size: .85rem; }
.toolbar button:hover { background: var(--hover); }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 .3rem; }

.content {
  flex: 1; overflow: auto; padding: 1rem 1.1rem 4rem;
  outline: none; line-height: 1.6; width: 100%; border: 0;
  background: var(--bg); color: var(--fg); resize: none;
}
.content.rich { font-family: var(--sans); }
.content.rich:empty::before { content: "Start writing…"; color: var(--fg-dim); }
.content.rich img { max-width: 100%; height: auto; border-radius: 6px; }
.content.rich h1 { font-size: 1.6rem; }
.content.rich h2 { font-size: 1.3rem; }
.content.rich pre { background: var(--bg-3); padding: .7rem .9rem; border-radius: 8px; overflow: auto; font-family: var(--mono); font-size: .85rem; }
.content.rich a { color: var(--accent); cursor: pointer; }
.content.rich blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 1rem; color: var(--fg-dim); }

/* Plain mode is monospaced (mostly used for code). */
.content.plain { font-family: var(--mono); font-size: .88rem; line-height: 1.55; white-space: pre; tab-size: 2; }

/* ----------------------------- modals ----------------------------- */
.modal { position: fixed; inset: 0; background: #00000066; display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  width: min(30rem, 100%); max-height: 84vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-card h2 { font-size: 1rem; margin: 0; padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
.folder-picker { overflow: auto; padding: .4rem; flex: 1; }
.folder-picker .row.current { opacity: .5; pointer-events: none; }
.modal-actions { padding: .7rem 1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

/* Share modal */
.share-body { overflow: auto; padding: .4rem 1rem 1rem; }
.muted { color: var(--fg-dim); font-size: .82rem; }
.share-section { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.share-section:last-child { border-bottom: 0; }
.share-section h3 { font-size: .9rem; margin: 0 0 .2rem; }
.check-row { display: flex; align-items: center; gap: .55rem; padding: .35rem 0; font-size: .88rem; cursor: pointer; }
.check-row input { width: 16px; height: 16px; }
.link-controls { margin: .5rem 0; display: flex; flex-direction: column; gap: .3rem; }
.expiry-row { display: flex; align-items: center; gap: .4rem; font-size: .85rem; }
.expiry-select { border: 1px solid var(--border); background: var(--bg); color: var(--fg); border-radius: 6px; padding: .25rem .4rem; }
.url-row { display: flex; gap: .35rem; margin-top: .3rem; }
.url-input { flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--bg-2); color: var(--fg); border-radius: 7px; padding: .4rem .55rem; font-size: .8rem; font-family: var(--mono); }
.url-row .btn { text-decoration: none; display: inline-flex; align-items: center; }

/* -------------------- collapsible sidebar (desktop) --------------- */
@media (min-width: 721px) {
  .app.sidebar-collapsed .sidebar { display: none; }
}

/* ----------------------------- mobile ----------------------------- */
@media (max-width: 720px) {
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 12px #00000022; width: 82vw; max-width: 320px; flex-basis: auto;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: #00000055; z-index: 25; }
  .user-badge { display: none; }
  .title-input { font-size: 1.2rem; }
}
