:root {
  --bg: #f7f4f0;
  --surface: #ffffff;
  --surface-2: #fbf9f6;
  --text: #2b2620;
  --muted: #8a8076;
  --border: #e7e0d8;
  --accent: #8a5a3b;
  --accent-2: #b67d52;
  --accent-soft: #f1e6dc;
  --ok: #2f7d4f;
  --ok-soft: #e3f3ea;
  --error: #b4453a;
  --error-soft: #f8e6e4;
  --warn: #b8842b;
  --warn-soft: #f7eed6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43,38,32,.04), 0 6px 20px rgba(43,38,32,.06);
  --shadow-lg: 0 10px 40px rgba(43,38,32,.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: .05em .4em; border-radius: 6px; font-size: .85em; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 28px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand a { color: var(--text); }
.brand a:hover { text-decoration: none; }
.logo { font-size: 1.3rem; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted); padding: 8px 14px; border-radius: 9px; font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }
.user { margin-left: auto; color: var(--muted); font-size: .9rem; }
.user a { font-weight: 500; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 64px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid > .card:only-child { grid-column: 1 / -1; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } .topbar { padding: 0 16px; gap: 10px; } .topbar nav a { padding: 6px 8px; } .user { display: none; } .container { padding: 18px 14px 48px; } }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card-title { margin: 0 0 16px; font-size: 1.1rem; font-weight: 600; }
.h3 { font-size: .98rem; font-weight: 600; margin: 0 0 10px; }
.help { background: var(--surface-2); }
.help ol { margin: 0; padding-left: 20px; }
.help ol li { margin: 6px 0; }
.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* Forms */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .9rem; color: var(--text); }
label.full, .full { grid-column: 1 / -1; }
input[type=text], input[type=password], input[type=url], input[type=file], select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }
.row-between { display: flex; gap: 12px; align-items: flex-end; }
.row-between > * { flex: 1; }
.grow { flex: 1; }
.prompt-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 16px; text-decoration: none; transition: all .15s;
}
.btn:hover { border-color: var(--accent-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--error); border-color: var(--error-soft); }
.btn.danger:hover { background: var(--error-soft); border-color: var(--error); }
.btn.tiny { padding: 5px 10px; font-size: .82rem; }
.btn.full { width: 100%; }
.inline { display: inline; }
form .btn { margin-top: 14px; }

/* Chips */
.chip {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 500;
  margin: 0 4px 4px 0; font-family: ui-monospace, monospace;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 26px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: all .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent-2); background: var(--accent-soft); }
.dz-icon { font-size: 2rem; }
.dz-text { margin-top: 6px; font-weight: 500; }
.dz-text span { color: var(--accent); }
.dz-hint { margin-top: 4px; }

/* Lists */
.tpl-list, .doc-list, .prov-list { display: flex; flex-direction: column; gap: 10px; }
.tpl-row, .doc-row, .prov-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 11px; padding: 14px 16px;
}
.doc-row { text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.doc-row:hover { border-color: var(--accent-2); box-shadow: var(--shadow); text-decoration: none; }
.tpl-name, .doc-title, .prov-name { font-weight: 600; }
.tpl-actions, .doc-dl, .prov-actions { display: flex; gap: 8px; align-items: center; }
.tpl-fields { margin: 6px 0; }
.small { font-size: .82rem; }
.muted { color: var(--muted); }
.empty {
  text-align: center; color: var(--muted); padding: 30px 12px;
  background: var(--surface-2); border-radius: 11px; border: 1px dashed var(--border);
}
.meta { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; padding: 12px 14px; background: var(--surface-2); border-radius: 11px; }
.dl-buttons { display: flex; flex-direction: column; gap: 10px; }
.dl-buttons .btn { justify-content: flex-start; }
.raw pre { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 10px; overflow: auto; }

/* Auth */
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 34px; box-shadow: var(--shadow-lg); width: 380px; max-width: 92vw;
  display: flex; flex-direction: column; gap: 6px;
}
.auth-card h1 { margin: 0 0 2px; text-align: center; font-size: 1.5rem; }
.auth-card .muted { text-align: center; margin-bottom: 14px; }
.auth-card label { margin-bottom: 12px; }
.auth-card .btn { margin-top: 8px; }

/* Flashes */
.flash {
  padding: 12px 16px; border-radius: 11px; margin-bottom: 16px; cursor: pointer;
  border: 1px solid transparent; font-weight: 500;
}
.flash-ok    { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.flash-error { background: var(--error-soft); border-color: var(--error); color: var(--error); }
.flash-warn  { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(43,38,32,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 22px; }
.modal-body label { margin-bottom: 12px; }
.icon-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Overlay (loading) */
.overlay { position: fixed; inset: 0; background: rgba(43,38,32,.5); display: grid; place-items: center; z-index: 60; }
.overlay[hidden] { display: none; }
.overlay-box { background: var(--surface); padding: 28px 36px; border-radius: 16px; text-align: center; box-shadow: var(--shadow-lg); }
.spinner {
  width: 38px; height: 38px; border: 4px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 70; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 11px; padding: 12px 16px; box-shadow: var(--shadow-lg); max-width: 360px;
  animation: slidein .2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--error); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
