/* ============================================================
   E2E Notepad — stylesheet
   ============================================================ */

/* ---- Custom properties ---- */
:root {
  --bg:          #f5f5f5;
  --surface:     #ffffff;
  --border:      #e0e0e0;
  --text:        #1a1a1a;
  --muted:       #757575;
  --primary:     #2563eb;
  --primary-h:   #1d4ed8;
  --danger:      #dc2626;
  --danger-h:    #b91c1c;
  --write-color: #16a34a;
  --read-color:  #2563eb;
  --owner-color: #7c3aed;
  --radius:      8px;
  --shadow:      0 1px 4px rgba(0,0,0,.08);
  --font:        system-ui, -apple-system, sans-serif;
  --mono:        ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body    { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; }
a       { color: var(--primary); }
input, textarea, select { font-family: inherit; font-size: 1rem; }

/* ---- Layout ---- */
.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.hidden { display: none !important; }

/* ---- Site nav ---- */
.site-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.site-nav__inner {
  max-width: 860px;
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.site-nav__brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -.01em;
}
.site-nav__brand:hover { color: var(--primary); }
.site-nav__sep {
  color: var(--border);
  font-size: .9rem;
  user-select: none;
}
.site-nav__page {
  font-size: .875rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Site header ---- */
.site-header { margin-bottom: 1.5rem; }
.site-header h1 { font-size: 1.75rem; font-weight: 700; }
.tagline { color: var(--muted); margin-top: .25rem; }

/* ---- Form elements ---- */
label {
  display: block;
  font-weight: 600;
  margin: 1rem 0 .35rem;
  font-size: .875rem;
}
label:first-child { margin-top: 0; }

input[type="text"], textarea, select {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input[type="text"]:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

textarea { resize: vertical; }

.form-row { margin-bottom: .75rem; }

/* ---- Buttons ---- */
button, .btn-secondary, .btn-primary {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  transition: background .15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  margin-top: 1rem;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: var(--danger-h); }

.btn-sm { padding: .25rem .6rem; font-size: .8rem; }

.btn-copy {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .75rem;
  font-size: .85rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-copy:hover { background: #e8e8e8; }

.btn-link {
  color: var(--primary);
  text-decoration: none;
  font-size: .85rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: .2rem .4rem;
  border-radius: 4px;
  color: var(--muted);
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-write  { background: #dcfce7; color: var(--write-color); }
.badge-read   { background: #dbeafe; color: var(--read-color); }
.badge-owner  { background: #ede9fe; color: var(--owner-color); }

/* ---- Link groups (result page) ---- */
.link-group { margin-top: 1.25rem; }
.link-group label { font-size: .875rem; }
.link-row {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-top: .35rem;
}
.link-row input { font-family: var(--mono); font-size: .8rem; }

.hint    { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.warning { font-size: .8rem; color: var(--danger); margin-top: 1rem; font-weight: 600; }
.error   { font-size: .875rem; color: var(--danger); margin-top: .5rem; }
.muted   { color: var(--muted); }

.action-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

/* ---- Notes list (index page) ---- */
.notes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.notes-list li {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.note-title { flex: 1; font-weight: 600; }
.note-date  { font-size: .8rem; color: var(--muted); }

/* ---- Note page header ---- */
.note-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}
.note-header-left  { display: flex; align-items: center; gap: .75rem; }
.note-header-left h1 { font-size: 1.4rem; }
.note-header-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.countdown  { font-size: .85rem; color: var(--muted); font-family: var(--mono); }
.save-status { font-size: .85rem; }
.save-status.muted  { color: var(--muted); }
.save-status.saved { color: var(--write-color); }
.save-status.error { color: var(--danger); }
.conflict-btn {
  font-size: .78rem;
  padding: .15rem .5rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 600;
}
.conflict-btn:hover { background: var(--danger); color: #fff; }
.conflict-btn--force { color: var(--muted); border-color: var(--muted); }
.conflict-btn--force:hover { background: var(--muted); color: #fff; }

/* ---- Format toggle ---- */
.format-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.fmt-btn {
  padding: .25rem .65rem;
  font-size: .8rem;
  font-weight: 600;
  border: none;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  line-height: 1.6;
}
.fmt-btn:hover:not(.active) { background: var(--bg); }
.fmt-btn.active { background: var(--primary); color: #fff; }

/* ---- Split pane (write mode) ---- */
.split-pane {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: calc(100vh - 160px);
  min-height: 400px;
}
.split-pane.plain-mode {
  grid-template-columns: 1fr;
}
.split-pane.plain-mode #pane-preview {
  display: none;
}

.pane-editor, .pane-preview {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.pane-label {
  padding: .4rem .75rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

#editor {
  flex: 1;
  padding: .75rem;
  border: none;
  resize: none;
  font-family: var(--mono);
  font-size: .9rem;
  line-height: 1.6;
  background: var(--surface);
  color: var(--text);
}
#editor:focus { outline: none; }

.pane-preview > #preview {
  flex: 1;
  padding: .75rem 1rem;
  overflow-y: auto;
}

/* ---- Read-only pane ---- */
.read-only {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.plain-text { white-space: pre-wrap; font-family: inherit; font-size: .95rem; line-height: 1.7; }

/* ---- Markdown body ---- */
.markdown-body { font-size: .95rem; line-height: 1.7; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1.25rem 0 .5rem; font-weight: 700; }
.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 { font-size: 1.25rem; }
.markdown-body h3 { font-size: 1rem; }
.markdown-body p  { margin: .5rem 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5rem; margin: .5rem 0; }
.markdown-body li { margin: .25rem 0; }
.markdown-body pre { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: .75rem; overflow-x: auto; font-size: .85rem; }
.markdown-body code { font-family: var(--mono); font-size: .9em; background: var(--bg); padding: .1em .3em; border-radius: 3px; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--border); padding-left: .75rem; color: var(--muted); margin: .5rem 0; }
.markdown-body a { color: var(--primary); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: .5rem 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: .4rem .6rem; }
.markdown-body th { background: var(--bg); font-weight: 700; }

/* ---- Privacy cleared message ---- */
.cleared { color: var(--muted); font-style: italic; padding: 2rem; text-align: center; }

/* ---- Trust gate overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.gate-box { max-width: 400px; width: 90%; text-align: center; }
.gate-box h2 { margin-bottom: .75rem; }
.gate-box p  { margin-bottom: 1.25rem; color: var(--muted); }
.gate-buttons { display: flex; flex-direction: column; gap: .6rem; }
.gate-buttons button { width: 100%; }

/* ---- Manage page ---- */
.manage-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.manage-header h1   { font-size: 1.4rem; }
.manage-header-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }

.tokens-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.tokens-table th {
  text-align: left;
  padding: .5rem .6rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.tokens-table td {
  padding: .6rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tokens-table tr:last-child td { border-bottom: none; }

/* ---- Status box ---- */
#status-box p { color: var(--muted); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .split-pane {
    grid-template-columns: 1fr;
    height: auto;
  }
  .pane-editor { min-height: 280px; }
  #editor { min-height: 240px; }
  .pane-preview { min-height: 200px; }
  .note-header { flex-direction: column; }
  .tokens-table { font-size: .8rem; }
  .tokens-table th:nth-child(3),
  .tokens-table td:nth-child(3) { display: none; }
}
