:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1e2230;
  --muted: #6b7280;
  --line: #e6e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --success: #15803d;
  --accent: #f1f2f9;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 22, 40, .06), 0 8px 24px rgba(20, 22, 40, .05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: linear-gradient(100deg, #312e81, #4f46e5);
  color: #fff;
}
.topbar a.brand {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.01em;
}
.topbar a.brand:hover { text-decoration: none; opacity: .92; }
.topbar nav { display: flex; align-items: center; gap: 12px; }
.badge {
  background: rgba(255, 255, 255, .15);
  color: #e9e9ff;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
}

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 28px auto; padding: 0 24px; }
.footer { text-align: center; color: var(--muted); padding: 36px; font-size: 13px; }

h1 { font-size: 25px; margin: 22px 0 6px; letter-spacing: -.02em; }
h1 .muted { font-size: 14px; font-weight: 500; }
h2 { font-size: 16px; margin: 0 0 14px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0 0 4px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}
.section-head h2 { margin: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.add-card { border-color: #d9d9f3; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.tile { transition: transform .12s ease, box-shadow .12s ease; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(20, 22, 40, .1); }
.tile h3 a { color: var(--ink); }
.tile h3 a:hover { color: var(--primary); }

.muted { color: var(--muted); font-size: 13px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 18px 0 0; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.hint { font-size: 12.5px; color: var(--muted); }

/* ---------- Forms ---------- */
form { margin: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row input, .row select { flex: 1; min-width: 170px; }
.stack { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.stack > .btn { align-self: flex-start; }

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: #4b5168;
  width: 100%;
}

input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .14);
}
input[type="file"] { padding: 8px; background: var(--accent); cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  transition: background .12s ease, opacity .12s ease, transform .05s ease;
}
.btn:hover { background: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f3c6c6; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn-link {
  background: none; border: none; color: #e9e9ff;
  cursor: pointer; font-size: 14px; font-family: inherit;
}
.btn-link:hover { color: #fff; text-decoration: underline; }
.inline { display: inline; }

/* ---------- Tabs ---------- */
.tabs {
  display: inline-flex;
  background: var(--accent);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
  gap: 2px;
  flex-wrap: wrap;
}
.tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { background: #fff; color: var(--primary); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tab-panel.hidden { display: none; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed #c5c7e0;
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  background: #fafaff;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover { border-color: var(--primary); background: #f3f3ff; }
.dropzone.dragover { border-color: var(--primary); background: #ebebff; }
.dropzone.busy { opacity: .7; pointer-events: none; }
.dropzone-icon { font-size: 30px; }
.dropzone-text { font-weight: 600; margin: 6px 0 2px; }

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.table th {
  background: var(--accent);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.table tr:last-child td { border-bottom: none; }

/* ---------- Alerts & empty states ---------- */
.alert { padding: 11px 15px; border-radius: 9px; margin-bottom: 14px; font-size: 14px; }
.alert.error { background: #fef2f2; color: var(--danger); border: 1px solid #f3c6c6; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-state .ico { font-size: 30px; display: block; margin-bottom: 6px; }

/* ---------- Auth ---------- */
.auth-card { max-width: 370px; margin: 64px auto; }
.auth-card h1 { margin-top: 0; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .btn { width: 100%; justify-content: center; }

/* ---------- Components ---------- */
.component { display: flex; flex-direction: column; }
.thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 9px;
  background: var(--accent);
  margin-bottom: 10px;
}
.thumb.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.thumb.broken { display: none; }
.component-actions { margin-top: auto; padding-top: 10px; }
.component details { margin: 8px 0; }
.component summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  list-style: none;
}
.component summary::-webkit-details-marker { display: none; }
.component summary::before { content: "✎ "; }
.component details[open] summary::before { content: "▾ "; }
.component details .stack { margin-top: 10px; }

/* ---------- Public endpoint box ---------- */
.public-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: #eef0ff;
  border-color: #c9ccf5;
}
.public-box code {
  background: #fff;
  padding: 7px 11px;
  border-radius: 7px;
  font-size: 13px;
  border: 1px solid #c9ccf5;
  flex: 1;
  min-width: 220px;
  word-break: break-all;
}

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }

/* ---------- Animations ---------- */
@keyframes pop-in {
  from { opacity: 0; transform: scale(.94); }
  to { opacity: 1; transform: scale(1); }
}
.just-added {
  animation: pop-in .25s ease;
  box-shadow: 0 0 0 2px #86efac, var(--shadow);
}
.removing {
  opacity: 0;
  transform: scale(.92);
  transition: opacity .24s ease, transform .24s ease;
}

@media (max-width: 540px) {
  .container { padding: 0 16px; }
  .topbar { padding: 12px 16px; }
  .row input, .row select { min-width: 100%; }
}
