/* ── FONTS ──────────────────────────────────────────────────────────────────── */
/* Aptly is loaded via Typekit <link> in each HTML template */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

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

/* ── DESIGN TOKENS ──────────────────────────────────────────────────────────── */
:root {
  --brand:         #FD7014;
  --brand-dark:    #D45A00;
  --teal:          #037F8C;
  --ink:           #111111;
  --text-color:           rgb(18, 18, 18);
  --text-mid:           rgb(163, 163, 163);
  --light-text:    #9A938C;
  --text-on-teal: #FFFFFF;
  --bg:            #037F8C;
  --surface:       #FFFFFF;
  --surface-2:     #F0EDE8;
  --border:        #DDD8D2;
  --border-strong: #B8B0A8;
  --red:           #C83232;
  --green:         #1A7A3A;
  --font-display:  aptly, sans-serif;
  --font-body:     'IBM Plex Sans', sans-serif;
  --font-mono:     'IBM Plex Mono', monospace;
  --radius:        0px;
  --radius-md:     5px;
}

html {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 3px solid var(--brand);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -.01em;
  color: var(--ink);
  line-height: 1;
  flex-shrink: 0;
}

.header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 28px;
}

.nav-link {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink);
  transition: color .15s;
  white-space: nowrap;
}
.nav-link:hover  { color: var(--brand); }
.nav-link.active { color: var(--brand); }
.nav-link.muted  { color: var(--light-text); }

.nav-link-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--light-text);
}
.nav-link-btn:hover { color: var(--brand); }

/* ── GALLERY ────────────────────────────────────────────────────────────────── */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 16px;
  padding: 28px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: rgba(0,0,0,0.4) 0px 6px 7px -1px;
  transition: transform .15s, box-shadow .15s;
  animation: card-in .3s ease both;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: rgba(0,0,0,0.5) 0px 10px 12px -2px;
}

.card-preview {
  /* background: var(--surface-2); */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(240px + 28px);
  border-bottom: 1px solid var(--border);
  padding: 14px;
  transition: background .18s;
}
.card:hover .card-preview { background: var(--surface-2); }

.card-preview img {
  /* max-width: 100%;
  max-height: 96px; */
  object-fit: contain;
  display: block;
}

.card-no-preview {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--light-text);
  letter-spacing: .04em;
}

.card-info {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.card-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.card-desc {
  font-size: 0.9rem;
  color: var(--text-color);
  line-height: 1.45;
}

.card-id {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--text-mid);
  margin-top: 5px;
  letter-spacing: .02em;
}

/* ── SHARED UTILITIES ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  cursor: pointer;
  line-height: 1;
  transition: background .15s, opacity .15s, border-color .15s, color .15s;
  white-space: nowrap;
}

.btn-primary  { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }

.btn-secondary {
  background: transparent;
  color: var(--text-color);
  border-color: var(--border);
}
.btn-secondary:hover { color: var(--ink); border-color: var(--border-strong); }

.btn-sm  { padding: 5px 10px; font-size: .7rem; }
.btn-full { width: 100%; padding: 11px; }

.pane-label {
  font-family: var(--font-display);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-on-teal);
  flex-shrink: 0;
}

.muted      { color: var(--light-text); }
.ok-text    { color: var(--green); font-weight: 500; }
.error-text { color: var(--red); }
.error      { font-size: .8rem; color: var(--red); margin-top: 6px; line-height: 1.4; }

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FORMS ──────────────────────────────────────────────────────────────────── */
input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(253,112,20,.12);
}

label {
  display: block;
  font-size: .73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-color);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 16px; }

/* ── FORM / AUTH CARD ───────────────────────────────────────────────────────── */
body.form-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.form-card {
  background: var(--surface);
  /* border: 1px solid var(--border);
  border-top: 3px solid var(--brand);
  border-radius: var(--radius-md); */
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: rgba(0,0,0,0.4) 0px 6px 7px -1px;
}

.form-card h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -.01em;
  color: var(--ink);
  margin-bottom: 20px;
}

.form-card-centered { text-align: center; }
.form-card-centered h1 { text-align: center; }

.form-desc {
  color: var(--text-color);
  font-size: .875rem;
  line-height: 1.6;
  margin-bottom: 20px;
}
.form-desc strong { color: var(--ink); font-weight: 600; }

.form-card .error-text { margin-bottom: 14px; font-size: .85rem; }

.sent-icon {
  display: block;
  font-size: 2.6rem;
  text-align: center;
  margin-bottom: 18px;
}

.form-note {
  margin-top: 12px;
  color: var(--light-text);
  font-size: .825rem;
  line-height: 1.5;
}

.form-link {
  display: inline-block;
  margin-top: 22px;
  font-size: .825rem;
  color: var(--brand);
  font-weight: 500;
  transition: color .15s;
}
.form-link:hover { color: var(--brand-dark); }

/* ── DETAIL PAGE (try-it) ───────────────────────────────────────────────────── */
.editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 62px);
}
@media (max-width: 700px) {
  .editor { grid-template-columns: 1fr; height: auto; }
}

.editor-pane, .preview-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 16px;
  overflow: hidden;
}
.editor-pane {
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid hsla(0,0%,100%,.2);
}
.preview-pane {
  padding-bottom: 32px;
}
#json-input {
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.65;
  border: none;
  padding: 10px 12px;
  resize: none;
  background: var(--surface);
  box-shadow: rgba(0,0,0,0.4) 0px 6px 7px -1px;
  outline: none;
  color: var(--ink);
}

.preview-card {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  box-shadow: rgba(0,0,0,0.4) 0px 6px 7px -1px;
  overflow: auto;
}

.preview-halves {
  display: flex;
  flex-direction: row;
  gap: 24px;
  padding: 20px;
  align-items: flex-start;
}

.preview-halves canvas {
  display: block;
  flex-shrink: 0;
  image-rendering: pixelated;
}

/* ── FULL EDITOR (3-column) ─────────────────────────────────────────────────── */
body.editor-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.editor-header {
  background: var(--surface);
  border-bottom: 3px solid var(--brand);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.editor-header h1 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -.01em;
}
.editor-header a {
  color: var(--text-color);
  font-size: .825rem;
  font-weight: 500;
  transition: color .15s;
}
.editor-header a:hover { color: var(--brand); }

.editor-template-name {
  font-family: var(--font-mono);
  font-size: .78rem;
  color: var(--text-color);
  margin-right: auto;
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.editor-3col {
  display: grid;
  grid-template-columns: 200px 1fr 320px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left: file list */
.editor-files {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.files-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--teal);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.btn-icon:hover { background: var(--brand-dark); }

.file-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.file-item {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  gap: 4px;
  border-left: 2px solid transparent;
  transition: background .1s;
}
.file-item:hover { background: var(--surface-2); }
.file-item.active {
  background: rgba(253,112,20,.07);
  border-left-color: var(--brand);
}

.file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: .77rem;
  color: var(--text-color);
}
.file-name.clickable { cursor: pointer; color: var(--ink); }
.file-name.clickable:hover { color: var(--brand); }

.btn-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--light-text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 2px;
  transition: background .1s, color .1s;
}
.btn-delete:hover { background: var(--red); color: #fff; }

.upload-status, .save-status {
  font-size: .77rem;
  padding: 6px 12px;
  flex-shrink: 0;
  font-weight: 500;
}

/* Middle: code editor */
.editor-code-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--teal);
}

.cm-host { flex: 1; overflow: auto; font-size: .85rem; }
.cm-host .cm-editor   { height: 100%; }
.cm-host .cm-scroller { overflow: auto; }

/* Right: JSON + preview */
.editor-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.right-section { 
  display: flex; 
  flex-direction: column; 
  padding: 10px 14px; 
  background-color: var(--teal);
}
.json-section    { 
  flex: 0 0 40%; 
  border-bottom: 1px solid var(--border); 
  background: var(--teal);
}
.preview-section { flex: 1; overflow: hidden; }

.json-section textarea {
  flex: 1;
  font-family: var(--font-mono);
  font-size: .8rem;
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  resize: none;
  outline: none;
  color: var(--ink);
  background: var(--surface);
  margin-top: 6px;
  min-height: 0;
  height: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.json-section textarea:focus {
  border-color: var(--white);
  box-shadow: 0 0 0 3px rgba(253,112,20,.09);
}

.preview-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: var(--radius);
}
.preview-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }
.no-preview { color: var(--light-text); font-size: 1.1rem; font-family: var(--font-mono); }

.render-error-box {
  max-width: 100%; max-height: 100%; overflow: auto;
  padding: 12px 14px;
  background: #fff3f3; border: 1px solid #f5c5c5;
  border-radius: var(--radius);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: .77rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; text-align: left;
}

/* ── ADMIN ───────────────────────────────────────────────────────────────────── */
body.admin-page { background: var(--bg); }

.admin-main {
  max-width: 960px;
  margin: 28px auto;
  padding: 0 24px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.admin-toolbar h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -.01em;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: .875rem;
}
.admin-table thead { background: var(--surface-2); border-bottom: 2px solid var(--border); }
.admin-table th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-display);
  font-size: .66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-color);
}
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table code {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--teal);
  background: rgba(3,127,140,.07);
  padding: 2px 6px;
  border-radius: var(--radius);
}

.admin-actions { display: flex; gap: 8px; align-items: center; }

/* ── STATS / CACHE ──────────────────────────────────────────────────────────── */
.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 440px;
}
.stats-card table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.stats-card th,
.stats-card td    { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.stats-card tr:last-child th,
.stats-card tr:last-child td { border-bottom: none; }
.stats-card th {
  background: var(--surface-2);
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-color); white-space: nowrap; width: 35%;
}
.stats-card code { font-family: var(--font-mono); font-size: .8rem; color: var(--teal); }
