/* Certificate Generator – styles
   Palette: ink navy for structure, a single gold accent reserved for the
   name-placement box (the thing users care about), cool neutral workspace. */
:root {
  --ink: #1c2a3f;
  --ink-2: #33445e;
  --muted: #5d6b80;
  --line: #d5dbe3;
  --bg: #eef1f5;
  --panel: #ffffff;
  --blue: #1f5c99;
  --blue-dark: #174a7c;
  --gold: #c28f2c;
  --gold-soft: rgba(194, 143, 44, 0.12);
  --ok: #1d7a4a;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --fail: #a32a2a;
  --fail-bg: #fbe9e9;
  --radius: 6px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: #f1f3f6; padding: 1px 6px; border-radius: 4px; font-size: 13px; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid rgba(31, 92, 153, 0.45); outline-offset: 2px; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--ink); color: #fff; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.brand-mark { width: 30px; height: 30px; color: #fff; }
.account { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.account-label { opacity: 0.85; }

/* stepper */
.stepper {
  display: flex; gap: 4px; padding: 0 24px; background: var(--panel);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
.step {
  display: flex; align-items: center; gap: 10px; border: 0; background: none;
  padding: 14px 16px 12px; font: inherit; color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.step .num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: 13px; font-weight: 600;
}
.step.active { color: var(--ink); border-bottom-color: var(--blue); font-weight: 600; }
.step.active .num { background: var(--blue); border-color: var(--blue); color: #fff; }
.step.done { color: var(--ink-2); }
.step.done .num { background: var(--ink-2); border-color: var(--ink-2); color: #fff; }
.step:disabled { cursor: not-allowed; opacity: 0.5; }

/* panels */
main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.panel-head { margin-bottom: 20px; max-width: 72ch; }
.panel-head h1 { font-size: 24px; margin: 0 0 6px; font-weight: 600; letter-spacing: -0.01em; }
.panel-head p { margin: 0; color: var(--muted); }
.actions {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 28px;
  padding-top: 20px; border-top: 1px solid var(--line);
}
.actions > :only-child { margin-left: auto; }

/* buttons */
.btn {
  font: inherit; font-weight: 500; padding: 9px 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--ink-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-light { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.4); padding: 6px 12px; font-size: 13px; }
.btn-light:hover:not(:disabled) { border-color: #fff; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-xl { padding: 14px 28px; font-size: 17px; width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.center { justify-content: center; margin-top: 12px; }

/* dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 48px 20px;
  position: relative; cursor: pointer; text-align: center; background: #fafbfc; transition: border-color .15s, background .15s;
}
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone:hover, .dropzone.over { border-color: var(--blue); background: #f2f7fc; }
.dropzone.compact { padding: 28px 16px; }
.dz-title { font-weight: 600; color: var(--blue); font-size: 16px; }
.dz-sub { color: var(--muted); font-size: 13px; }

.template-info { display: flex; gap: 20px; align-items: flex-start; margin-top: 20px; }
.thumb { width: 220px; height: auto; border: 1px solid var(--line); box-shadow: 0 1px 3px rgba(28, 42, 63, 0.12); }
.file-name { font-weight: 600; margin-bottom: 4px; word-break: break-all; }

/* notices */
.notice { margin-top: 10px; padding: 10px 14px; border-radius: var(--radius); background: #eef3f9; color: var(--ink-2); font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; min-width: 0; }
.field label, .field .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); width: 100%;
}
input[type="color"] { width: 100%; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
input[type="file"] { font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.four { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.field-row.four input { padding: 6px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.check.big { font-weight: 600; font-size: 16px; margin: 6px 0 12px; }
.check input { width: 17px; height: 17px; accent-color: var(--blue); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 7px 14px; border: 0; background: #fff; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: #fff; }
fieldset.pos { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 8px 0 10px; }
fieldset.pos legend { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0 4px; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.stage { min-width: 0; }
.canvas-wrap { position: relative; line-height: 0; border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(28, 42, 63, 0.10); user-select: none; touch-action: none; }
.canvas-wrap canvas { width: 100%; height: auto; display: block; }
.name-box {
  position: absolute; display: flex; align-items: center; line-height: 1;
  border: 2px dashed var(--gold); background: var(--gold-soft); cursor: move; overflow: visible;
}
.name-box:focus-visible, .name-box.dragging { border-style: solid; outline: none; box-shadow: 0 0 0 4px rgba(194, 143, 44, 0.25); }
.name-text { white-space: nowrap; pointer-events: none; padding: 0; display: inline-block; }
.handle {
  position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--gold); border-radius: 2px;
}
.handle[data-h="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.handle[data-h="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.handle[data-h="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.handle[data-h="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.handle.edge { width: 8px; height: 22px; top: calc(50% - 11px); border-radius: 4px; cursor: ew-resize; }
.handle[data-h="w"] { left: -5px; }
.handle[data-h="e"] { right: -5px; }
.guide-v { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; border-left: 1px dashed var(--blue); pointer-events: none; }
.controls { position: sticky; top: 16px; }

/* names */
.list-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
.excel-options { margin-top: 16px; }
.paste { margin-top: 18px; font-size: 14px; }
.paste summary { cursor: pointer; color: var(--blue); font-weight: 500; }
.paste textarea { margin: 10px 0 8px; resize: vertical; }
.names-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.table-wrap { max-height: 480px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.names { width: 100%; border-collapse: collapse; font-size: 14px; }
table.names th { position: sticky; top: 0; background: #f5f7fa; text-align: left; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); z-index: 1; }
table.names td { padding: 5px 10px; border-bottom: 1px solid #edf0f4; vertical-align: middle; }
table.names td input.nm { padding: 5px 8px; border-color: transparent; background: transparent; }
table.names td input.nm:hover, table.names td input.nm:focus { border-color: var(--line); background: #fff; }
table.names .c-num { width: 48px; color: var(--muted); text-align: right; }
table.names .c-inc { width: 70px; text-align: center; }
table.names td.fn { color: var(--muted); font-size: 13px; word-break: break-all; }
table.names tr.excluded td { opacity: 0.45; }
table.names tr.has-warn td { background: var(--warn-bg); }
.row-warn { font-size: 12px; color: var(--warn); padding: 0 8px 4px; }
table.names tr.empty td { text-align: center; color: var(--muted); padding: 40px 10px; }

/* review */
.review { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; }
.review-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.review-list ol { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.review-list li { padding: 7px 12px; font-size: 14px; cursor: pointer; border-bottom: 1px solid #edf0f4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-list li:hover { background: #f5f7fa; }
.review-list li.on { background: var(--ink); color: #fff; }
.review-list li.warn:not(.on) { background: var(--warn-bg); }
.review-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.review-label { font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-frame { position: relative; background: #dfe4ea; padding: 18px; border-radius: var(--radius); }
.preview-frame canvas { width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 3px 14px rgba(28, 42, 63, 0.2); }
.spinner { position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px; border: 3px solid rgba(28, 42, 63, 0.2); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* generate */
.gen-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; align-items: start; }
.indent { margin: 0 0 18px 27px; }
.dest > .notice { margin: -6px 0 18px 27px; }
.run { display: flex; flex-direction: column; gap: 12px; }
.progress .bar { height: 10px; background: #e3e8ee; border-radius: 5px; overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.progress-text { font-size: 14px; color: var(--muted); margin-top: 6px; }
.result { padding: 14px 16px; border-radius: var(--radius); font-size: 14px; }
.result.ok { background: var(--ok-bg); color: var(--ok); }
.result.warn { background: var(--warn-bg); color: var(--warn); }
.result.fail { background: var(--fail-bg); color: var(--fail); }
.result .btn { margin-top: 8px; }
.log-wrap { margin-top: 24px; max-height: 360px; }
table.log tr.ok td:last-child { color: var(--ok); }
table.log tr.fail td:last-child { color: var(--fail); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; max-width: min(560px, 92vw); pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--fail); }

@media (max-width: 960px) {
  .editor, .list-grid, .review, .gen-grid { grid-template-columns: 1fr; }
  .controls { position: static; }
  .review-list ol { max-height: 200px; }
  main { padding: 12px; }
  .panel { padding: 18px; }
  .step .lbl { display: none; }
  .step.active .lbl { display: inline; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01s !important; }
}
