:root {
  --bg: #f3f1ec;
  --bg-2: #ebe7df;
  --surface: #fffcf7;
  --ink: #1c1915;
  --muted: #6b645a;
  --line: #ddd6cb;
  --accent: #1f6b4a;
  --accent-2: #163f2e;
  --danger: #b42318;
  --ok: #1f6b4a;
  --warn: #9a6700;
  --shadow: 0 12px 40px rgba(28, 25, 21, 0.08);
  --radius: 14px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9ebe2 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #efe6d4 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--bg-2);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(255, 252, 247, 0.86);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.nav { display: flex; gap: 0.35rem; flex: 1; }
.nav a {
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 500;
}
.nav a:hover, .nav a.is-active {
  color: var(--ink);
  background: var(--bg-2);
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }
.user-chip {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg-2);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}
.nav-toggle {
  display: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}
.main-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  max-width: none;
  padding: 2rem 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: #fff5f4; color: var(--danger); border-color: #f0c7c2; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.9rem; }
.btn-block { width: 100%; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-weight: 500;
}
.flash-ok { background: #e7f4ec; color: #14532d; }
.flash-error { background: #fdeceb; color: #7f1d1d; }

.auth-card {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.auth-hero {
  padding: 2.5rem;
  background:
    linear-gradient(160deg, rgba(31,107,74,0.12), transparent 50%),
    linear-gradient(0deg, #f7f3ea, #eef5f0);
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 0.75rem;
}
.auth-hero h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.lead { color: var(--muted); margin: 0; font-size: 1.05rem; }
.auth-form {
  padding: 2.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.auth-form h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 500; }
label span { color: var(--muted); font-size: 0.9rem; }
input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
select,
textarea {
  font: inherit;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 107, 74, 0.25);
  border-color: var(--accent);
}
.hint { color: var(--muted); font-size: 0.88rem; margin: 0; }

.page-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 4.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: var(--shadow);
}
.side-block + .side-block { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.side-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}
.side-link:hover { background: var(--bg-2); text-decoration: none; }
.side-link.is-active { background: #e4efe8; color: var(--accent-2); }
.side-link em {
  margin-left: auto;
  font-style: normal;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.side-link.muted { color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; }
.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--dot, #64748b);
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.toolbar h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}
.sub { margin: 0.2rem 0 0; color: var(--muted); }
.search-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.search-form input[type="search"] { min-width: 220px; }

.entry-list { display: flex; flex-direction: column; gap: 0.65rem; }
.entry-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.entry-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0;
  cursor: pointer;
  user-select: none;
}
.entry-head-main {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  min-width: 0;
  flex: 1;
}
.entry-toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 0.15rem 0.1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.entry-card.is-open .entry-toggle {
  transform: rotate(90deg);
  color: var(--accent);
}
.entry-head h2 {
  margin: 0.15rem 0 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.entry-body {
  display: none;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.entry-card.is-open .entry-body { display: block; }
.entry-card.is-open .entry-head { margin-bottom: 0; }
.cat-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cat, var(--accent));
  background: color-mix(in srgb, var(--cat, var(--accent)) 12%, white);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.tags span { color: var(--muted); font-size: 0.82rem; }
.entry-actions { display: flex; gap: 0.25rem; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font: inherit;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  text-decoration: none;
}
.icon-btn:hover { background: var(--bg-2); text-decoration: none; }
.inline { display: inline; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.55rem;
}
.field-item {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  user-select: none;
}
.field-item:hover {
  border-color: var(--accent);
  background: #f4faf6;
  transform: translateY(-1px);
}
.field-item.is-copied {
  border-style: solid;
  border-color: var(--accent);
  background: #e8f5ee;
}
.field-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.15rem;
}
.field-value {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  word-break: break-all;
}
.field-value.is-secret .field-text { letter-spacing: 0.05em; }
.field-link { color: var(--accent); font-family: var(--mono); font-size: 0.88rem; }
.copy-hint {
  margin-left: auto;
  font-family: var(--font);
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}
.field-item:hover .copy-hint { opacity: 1; }
.reveal-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  opacity: 0.7;
  flex-shrink: 0;
}
.entry-foot {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.entry-card.is-copied-all {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.empty {
  text-align: center;
  padding: 3.5rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty h2 { margin: 0 0 0.5rem; }
.empty p { color: var(--muted); }

.editor-page, .narrow-page { max-width: 860px; }
.back-link { color: var(--muted); font-size: 0.9rem; }
.tpl-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--muted);
}
.chip {
  display: inline-flex;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}
.chip:hover, .chip.is-active {
  background: #e4efe8;
  border-color: #b9d4c5;
  text-decoration: none;
}

.editor-form, .panel, .stack-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.panel { margin-bottom: 1rem; }
.panel h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.span-2 { grid-column: span 2; }
.check-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.fields-editor {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fff;
}
.fields-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.fields-editor-head h2 { margin: 0; font-size: 1rem; }
.fields-hint {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.35rem;
}
.field-row {
  display: grid;
  grid-template-columns: 28px 1fr 120px minmax(0, 1.4fr) auto;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
  align-items: center;
}
.field-row.is-dragging {
  opacity: 0.55;
  background: #f4faf6;
  border-radius: 10px;
  outline: 1px dashed var(--accent);
}
.drag-handle {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.35rem 0;
  touch-action: none;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.field-value-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}
.field-value-wrap .field-value-input { flex: 1; min-width: 0; }
.field-value-actions {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}
.notes-label { margin-bottom: 1rem; }
.form-actions { display: flex; gap: 0.6rem; }

.inline-create {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
}
.inline-create input[type="text"] { flex: 1; min-width: 180px; }
.cat-table { display: flex; flex-direction: column; gap: 0.5rem; }
.cat-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto;
  gap: 0.5rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}
.muted { color: var(--muted); font-size: 0.9rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}
.stat strong {
  display: block;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}
.stat span { color: var(--muted); font-size: 0.88rem; }
.stack-form { display: flex; flex-direction: column; gap: 0.85rem; box-shadow: none; border: 0; padding: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-panel {
  position: relative;
  width: min(420px, 100%);
  max-height: min(80vh, 560px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.modal-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}
.modal-actions-top {
  display: flex;
  gap: 0.35rem;
}
.copy-pick-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 40vh;
  overflow: auto;
}
.copy-pick-item {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
}
.copy-pick-item:hover { border-color: var(--accent); background: #f4faf6; }
.copy-pick-item input { margin-top: 0.2rem; }
.copy-pick-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.copy-pick-meta strong { font-size: 0.9rem; }
.copy-pick-meta em {
  font-style: normal;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

@media (max-width: 900px) {
  .page-grid { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .auth-card { grid-template-columns: 1fr; }
  .nav { display: none; }
  .nav.is-open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0.75rem;
  }
  .topbar-inner { position: relative; flex-wrap: wrap; }
  .nav-toggle { display: inline-block; margin-left: auto; }
  .topbar-right { order: 3; width: 100%; justify-content: flex-end; }
  .form-grid, .cat-row, .stat-row { grid-template-columns: 1fr; }
  .field-row {
    grid-template-columns: 28px 1fr auto;
  }
  .field-row > input[name="field_label[]"],
  .field-row > select,
  .field-row > .field-value-wrap {
    grid-column: 1 / -1;
  }
  .span-2 { grid-column: auto; }
  .field-row .remove-field { justify-self: end; grid-column: 3; grid-row: 1; }
  .field-row .drag-handle { grid-column: 1; grid-row: 1; }
}
