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

:root {
  --text:        #111827;
  --text-2:      #6b7280;
  --text-3:      #9ca3af;
  --text-info:   #2563eb;
  --text-danger: #dc2626;
  --bg:          #ffffff;
  --bg-2:        #f9fafb;
  --bg-info:     #eff6ff;
  --border:      #e5e7eb;
  --border-2:    #d1d5db;
  --border-info: #93c5fd;
  --radius:      6px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, "Courier New", monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Auth overlay ─────────────────────────────────────────────────────────── */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-overlay.hidden { display: none; }
.auth-card {
  width: min(360px, 90vw);
  padding: 2rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 1rem;
  text-align: center;
}
.auth-card h1 { font-size: 1.5rem; font-weight: 600; }
.auth-card p  { color: var(--text-2); font-size: 0.875rem; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.header-title { font-weight: 600; font-size: 0.9375rem; letter-spacing: -0.01em; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 0.5625rem 1rem;
  font-size: 0.875rem;
  cursor: pointer;
  border: none; background: transparent;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-family: var(--sans);
  transition: color 0.1s;
}
.tab.active { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }
.tab:hover:not(.active) { color: var(--text); }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main { padding: 1rem; max-width: 760px; margin: 0 auto; }

/* ── Panes ────────────────────────────────────────────────────────────────── */
.pane { display: none; }
.pane.active { display: block; }

/* ── Stats ────────────────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
  margin-bottom: 0.875rem;
}
.stat {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-2); margin-bottom: 0.2rem; }
.stat-value { font-size: 1.375rem; font-weight: 500; }

/* ── Search row ───────────────────────────────────────────────────────────── */
.search-row { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.search-row input { flex: 1; }

/* ── Snippet list ─────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 0.5rem; }
.list-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6875rem 0.875rem;
  cursor: pointer;
  transition: border-color 0.1s;
}
.list-item:hover { border-color: var(--border-2); }
.item-row {
  display: flex; justify-content: space-between;
  align-items: baseline; gap: 0.75rem;
}
.item-trigger {
  font-family: var(--mono); font-size: 0.775rem; font-weight: 500;
  color: var(--text-info); background: var(--bg-info);
  padding: 2px 7px; border-radius: var(--radius); flex-shrink: 0;
}
.item-meta { font-size: 0.72rem; color: var(--text-3); flex-shrink: 0; }
.item-replacement {
  font-size: 0.8rem; color: var(--text-2); margin-top: 0.3rem;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  white-space: pre-wrap; line-height: 1.45;
}
.item-tags { display: flex; gap: 4px; margin-top: 0.45rem; flex-wrap: wrap; }
.item-tag {
  font-size: 0.7rem; padding: 1px 7px;
  background: var(--bg-2); color: var(--text-2);
  border-radius: var(--radius);
}
.list-empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-3); font-size: 0.875rem; }

/* ── Hint / secondary text ────────────────────────────────────────────────── */
.hint {
  font-size: 0.8125rem; color: var(--text-2);
  line-height: 1.6; margin-bottom: 0.75rem;
}
.hint code {
  font-family: var(--mono); font-size: 0.75rem;
  background: var(--bg-2); padding: 1px 5px; border-radius: 4px;
}

/* ── Scratchpad ───────────────────────────────────────────────────────────── */
textarea.scratch {
  min-height: 180px;
  font-family: var(--mono);
  font-size: 0.875rem;
}
.options-row {
  display: flex; gap: 1rem; margin: 0.625rem 0;
  padding: 0.5rem 0.75rem;
  background: var(--bg-2); border-radius: var(--radius);
  font-size: 0.8125rem; flex-wrap: wrap;
}
.options-row label {
  display: flex; align-items: center; gap: 0.375rem;
  cursor: pointer; color: var(--text-2);
}
.scratch-meta {
  display: flex; gap: 1rem;
  font-size: 0.75rem; color: var(--text-3); flex-wrap: wrap;
  margin-top: 0.375rem;
}
.scratch-meta strong { color: var(--text-2); font-weight: 400; }

/* ── Scratch lookup ───────────────────────────────────────────────────────── */
.scratch-lookup {
  margin-top: 0.75rem;
  position: relative;
}
.scratch-search-results {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 20;
  overflow: hidden;
}
.scratch-search-item {
  display: flex; align-items: baseline; gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background 0.1s;
}
.scratch-search-item:hover { background: var(--bg-2); }
.scratch-search-trigger {
  font-family: var(--mono); font-size: 0.75rem; font-weight: 500;
  color: var(--text-info); background: var(--bg-info);
  padding: 1px 6px; border-radius: var(--radius);
  flex-shrink: 0;
}
.scratch-search-preview {
  font-size: 0.8rem; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scratch-search-empty {
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem; color: var(--text-3); text-align: center;
}

/* ── Button rows ──────────────────────────────────────────────────────────── */
.row-actions { display: flex; gap: 0.5rem; margin: 0.75rem 0; flex-wrap: wrap; }

/* ── Edit form ────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 0.75rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.8rem; color: var(--text-2); }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.25rem; }

/* ── Data pane ────────────────────────────────────────────────────────────── */
textarea.data-area {
  min-height: 200px;
  font-family: var(--mono); font-size: 0.75rem;
}

/* ── Shared inputs ────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 0.4375rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 0.875rem;
  transition: border-color 0.15s, outline 0.1s;
}
input:focus, textarea:focus {
  outline: 2px solid var(--border-info);
  outline-offset: -1px;
  border-color: transparent;
}
textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button {
  padding: 0.4375rem 0.9375rem;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 0.875rem;
  cursor: pointer; white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}
button:hover  { background: var(--bg-2); }
button:active { background: var(--border); }

.btn-sm { padding: 0.3125rem 0.6875rem; font-size: 0.8rem; }

.btn-primary {
  background: var(--text); color: var(--bg); border-color: var(--text);
}
.btn-primary:hover  { background: #374151; border-color: #374151; }
.btn-primary:active { background: #1f2937; }

.btn-danger { color: var(--text-danger); border-color: #fca5a5; }
.btn-danger:hover  { background: #fff1f2; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  background: var(--text); color: var(--bg);
  padding: 0.5rem 0.9375rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 50;
  max-width: calc(100vw - 2.5rem);
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .form-row { grid-template-columns: 1fr; }
  .stats { gap: 0.5rem; }
  .stat-value { font-size: 1.125rem; }
  .main { padding: 0.75rem; }
  .tab { padding: 0.5rem 0.75rem; font-size: 0.8125rem; }
}
