/* ---------- Base ---------- */
@font-face {
  font-family: 'NotoFlags';
  unicode-range: U+1F1E6-1F1FF;
  src: url(https://cdn.jsdelivr.net/gh/googlefonts/noto-emoji@main/fonts/NotoColorEmoji.ttf) format('truetype');
  font-display: swap;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "NotoFlags", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1f2933;
  background: #f5f7fa;
}

a { color: #2ea3f2; text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.6em; }
h2 { font-size: 1.3em; }
h3 { font-size: 1.1em; }
h4 { font-size: .95em; text-transform: uppercase; letter-spacing: .05em; color: #627d98; }

p { margin: 0 0 .8em; }

.muted { color: #829ab1; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.5rem;
  background: #fff; color: #333;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-bottom: 1px solid #e5e7eb;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #102a43; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.4em; }
.brand-logo { height: 28px; width: auto; display: block; }
.topbar-nav { display: flex; align-items: center; gap: .5rem; flex: 1; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
.topbar-nav::-webkit-scrollbar { height: 3px; }
.topbar-nav::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.nav-link {
  color: #3a5083 !important; padding: .25rem .5rem; border-radius: 4px;
  background: none; border: none; cursor: pointer; font-size: 14px; font-weight: 700;
  transition: opacity .2s ease-in;
}
.nav-link:hover { opacity: .7; text-decoration: none; }
.nav-link-active { font-weight: 700; }
.doc-name { color: #666; font-weight: 500; }

.version-tag {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0.1em 0.5em;
  border-radius: 10px;
  font-size: 0.65em;
  font-weight: 700;
  letter-spacing: 0.05em;
  vertical-align: middle;
  text-transform: uppercase;
}
.version-v1 { background: #fde68a; color: #78350f; }
.version-v2 { background: #93c5fd; color: #1e3a8a; }

.main { padding: 1.5rem; margin: 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem; font-size: 14px; font-weight: 500;
  border: 1px solid #d9e2ec; border-radius: 6px; background: #fff;
  color: #1f2933; cursor: pointer; transition: all .15s;
  text-decoration: none;
}
.btn:hover { background: #f0f4f8; text-decoration: none; }
.btn-primary { background: #ff9900; color: #fff; border-color: #ff9900; }
.btn-primary:hover { background: #e68a00; }
.btn-ghost { background: transparent; }
.btn-danger { color: #c81e1e; border-color: #f3b6b6; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: .25rem .6rem; font-size: 13px; }

/* ---------- Page header ---------- */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { margin-bottom: .25rem; }

.actions-bar { display: flex; gap: .5rem; margin-bottom: 1.5rem; }

/* ---------- Card grid ---------- */
.card-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  background: #fff; border: 1px solid #d9e2ec; border-radius: 8px;
  padding: 1rem; display: flex; flex-direction: column; gap: .75rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card-title { margin: 0; font-size: 1.1em; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { color: #2563eb; }
.card-subtitle { color: #486581; font-size: .9em; margin: .25em 0 0; }
.card-meta { color: #829ab1; font-size: .8em; margin: 0; }
.card-actions { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal[hidden] { display: none; }
.modal-content {
  background: #fff; border-radius: 8px; min-width: 420px; max-width: 80vw;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); overflow: hidden;
}
.modal-content h3 { padding: 1rem 1.25rem; border-bottom: 1px solid #e4e7eb; margin: 0; }
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.modal-body label { display: flex; align-items: center; gap: .5rem; }
.modal-body input[type="text"], .modal-body input[type="number"], .modal-body select {
  padding: .35rem .5rem; border: 1px solid #cbd2d9; border-radius: 4px; font: inherit;
}
.modal-actions { padding: .75rem 1.25rem; border-top: 1px solid #e4e7eb;
  display: flex; justify-content: flex-end; gap: .5rem; align-items: center; }
.modal-actions .spacer { flex: 1; }
.modal-actions .btn-danger { margin-right: auto; }

.edit-image-preview {
  display: flex; justify-content: center; align-items: center;
  background: #f0f4f8; border-radius: 4px; padding: 1rem; min-height: 80px;
  margin-bottom: 1rem;
}
.edit-image-preview img { max-width: 100%; max-height: 240px; }

.modal-body fieldset {
  border: 1px solid #d9e2ec; border-radius: 4px; padding: .5rem .75rem;
  margin: .25rem 0;
}
.modal-body legend {
  padding: 0 .35em; color: #486581; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}
.dim-row, .align-row, .dim-presets {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .35rem 0;
}
.dim-row label, .align-row label { flex: 1; min-width: 120px; }
.dim-row input, .modal-body input[type="text"] {
  padding: .35rem .5rem; border: 1px solid #cbd2d9; border-radius: 4px; font: inherit; width: 100%;
}

.asset-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: .5rem; max-height: 220px; overflow: auto; padding: .5rem;
  background: #f0f4f8; border-radius: 4px;
}
.asset-grid .asset-item {
  border: 1px solid #d9e2ec; background: #fff; border-radius: 4px;
  padding: 4px; cursor: pointer; text-align: center; font-size: 11px;
  word-break: break-all; transition: border-color .15s;
}
.asset-grid .asset-item:hover { border-color: #f59e0b; background: #fffbeb; }
.asset-grid .asset-item img { max-width: 100%; max-height: 60px; display: block; margin: 0 auto; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { padding: .6rem 1rem; background: #1f2933; color: #fff; border-radius: 4px; box-shadow: 0 4px 10px rgba(0,0,0,.15); }
.toast.ok { background: #0d8050; }
.toast.err { background: #c81e1e; }
