/* ═══════════════════════════════════════════════════════════════
   Design tokens
   ═══════════════════════════════════════════════════════════════ */
:root {
  --bg:            #EEF2FB;
  --surface:       #FFFFFF;
  --surface-alt:   #F5F7FE;
  --border:        #DDE3F5;
  --border-strong: #C5CDE8;
  --text:          #111827;
  --text-2:        #4B5563;
  --text-3:        #8B95AA;
  --accent:        #4338CA;
  --accent-hover:  #3730A3;
  --accent-light:  #EEF2FF;
  --error-bg:      #FEF2F2;
  --error-border:  #FECACA;
  --error-text:    #DC2626;
  --warn-bg:       #FFFBEB;
  --warn-border:   #FCD34D;
  --warn-text:     #92400E;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 4px rgba(67,56,202,.07), 0 1px 2px rgba(67,56,202,.05);
  --shadow-md:     0 4px 20px rgba(67,56,202,.1);
  --font:          system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono:     'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* ═══════════════════════════════════════════════════════════════
   Reset & base
   ═══════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
}

/* ═══════════════════════════════════════════════════════════════
   App shell
   ═══════════════════════════════════════════════════════════════ */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.header-sub {
  font-size: 12px;
  color: var(--text-3);
}

/* Main */
.app-main {
  flex: 1;
  padding: 24px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ═══════════════════════════════════════════════════════════════
   Type selector bar
   ═══════════════════════════════════════════════════════════════ */
.type-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.type-bar::-webkit-scrollbar        { height: 4px; }
.type-bar::-webkit-scrollbar-track  { background: transparent; }
.type-bar::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 4px; }

.type-btn {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 14px 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: border-color .12s, background .12s, color .12s;
}

.type-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.type-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.type-icon  { font-size: 20px; line-height: 1; }
.type-label { font-size: 11px; font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════
   Content grid
   ═══════════════════════════════════════════════════════════════ */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .content-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════
   Card
   ═══════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════
   Payload header
   ═══════════════════════════════════════════════════════════════ */
.payload-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.payload-icon  { font-size: 28px; line-height: 1; }
.payload-title { font-size: 18px; font-weight: 700; line-height: 1.2; }
.payload-desc  { font-size: 13px; color: var(--text-3); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════════
   Form fields
   ═══════════════════════════════════════════════════════════════ */
.field-group { margin-bottom: 16px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}

.optional {
  font-weight: 400;
  color: var(--text-3);
  font-size: 12px;
}

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
  line-height: 1.4;
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,56,202,.12);
}

.field-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.field-check label {
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

/* Telegram prefix input */
.input-prefix-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
}

.input-prefix-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,56,202,.12);
}

.input-prefix {
  padding: 9px 10px 9px 12px;
  background: var(--surface-alt);
  color: var(--text-3);
  font-weight: 600;
  font-size: 14px;
  border-right: 1.5px solid var(--border);
  white-space: nowrap;
}

.field-input.prefixed {
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.field-input.prefixed:focus {
  border: none;
  box-shadow: none;
}

/* Section divider */
.section-divider {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.07em;
  margin: 20px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}

/* Raw payload details */
.raw-details {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.raw-summary {
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.raw-summary::marker,
.raw-summary::-webkit-details-marker { display: none; }

.raw-summary::before { content: '▶ '; font-size: 10px; }
details[open] .raw-summary::before { content: '▼ '; }

.raw-payload {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 140px;
  overflow-y: auto;
}

/* ═══════════════════════════════════════════════════════════════
   Settings panel
   ═══════════════════════════════════════════════════════════════ */
.settings-panel { display: flex; flex-direction: column; gap: 16px; }

.settings-section { margin-bottom: 18px; }
.settings-section:last-child { margin-bottom: 0; }

.setting-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Format buttons */
.format-group { display: flex; gap: 4px; }

.fmt-btn {
  flex: 1;
  padding: 9px 6px;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  cursor: pointer;
  transition: all .12s;
  letter-spacing: 0.02em;
}

.fmt-btn:hover  { border-color: var(--accent); color: var(--accent); }
.fmt-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Range sliders */
input[type="range"] {
  width: 100%;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

/* Color pickers */
.color-row { display: flex; gap: 12px; }

.color-pick {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.color-pick input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 3px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
  transition: border-color .12s;
}

.color-pick input[type="color"]:hover { border-color: var(--accent); }

.color-hex {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
}

/* Warnings */
.warn-msg {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  color: var(--warn-text);
  font-size: 12px;
}

/* Generate button */
.btn-generate {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-generate:hover:not(:disabled) { background: var(--accent-hover); }
.btn-generate:disabled              { opacity: .55; cursor: not-allowed; }

.spinner { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  color: var(--error-text);
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════════
   Preview
   ═══════════════════════════════════════════════════════════════ */
.preview-card { padding: 20px; }

.preview-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 180px;
}

.preview-box img { max-width: 100%; height: auto; display: block; }

/* SVG inside preview */
.preview-box svg { max-width: 100%; height: auto; }

/* ASCII */
.ascii-wrap {
  overflow: auto;
  max-height: 340px;
  max-width: 100%;
  padding: 4px;
}

.ascii-text {
  font-family: 'Courier New', Courier, monospace;
  font-size: 5px;
  line-height: 1;
  white-space: pre;
  color: var(--text);
  letter-spacing: 0;
}

/* Download row */
.download-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn-dl,
.btn-copy {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}

.btn-dl {
  background: var(--accent);
  color: #fff;
  border: none;
}

.btn-dl:hover { background: var(--accent-hover); }

.btn-copy {
  background: var(--surface-alt);
  color: var(--text-2);
  border: 1.5px solid var(--border);
}

.btn-copy:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════
   Blazor error UI overrides
   ═══════════════════════════════════════════════════════════════ */
#blazor-error-ui {
  background: var(--error-bg);
  border-top: 1px solid var(--error-border);
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0,0,0,.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
  color: var(--error-text);
  font-size: 13px;
}

#blazor-error-ui .dismiss { cursor: pointer; }

/* ═══════════════════════════════════════════════════════════════
   Additions
   ═══════════════════════════════════════════════════════════════ */

/* Visually hidden but still announced by screen readers.
   Routes.razor focuses an <h1> on navigation, so the page needs one. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 4px;
}

.field-hint code { font-size: 0.95em; }

/* Password inputs render a browser reveal icon in some engines; keep spacing tidy. */
.field-input[type="password"] { letter-spacing: 0.06em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Boot splash — shown while the .NET runtime downloads
   Markup lives in index.html and is replaced by <App /> on start.
   ═══════════════════════════════════════════════════════════════ */
.boot {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  color: var(--accent);
  font-family: var(--font);
  padding: 1.5rem;
  text-align: center;
}
.boot-title { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.boot-note  { font-size: 0.82rem; color: var(--text-3); max-width: 22rem; }
.boot-bar {
  width: min(240px, 70vw);
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.boot-fill {
  width: 40%;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  animation: boot-slide 1.1s ease-in-out infinite;
}
@keyframes boot-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ═══════════════════════════════════════════════════════════════
   Dark mode — follows the OS setting. Every rule above reads from
   the custom properties, so overriding them here is sufficient.
   ═══════════════════════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0F1420;
    --surface:       #171E2E;
    --surface-alt:   #1E2638;
    --border:        #2A3345;
    --border-strong: #3B465E;
    --text:          #E8ECF5;
    --text-2:        #AEB8CC;
    --text-3:        #7B8699;
    --accent:        #818CF8;
    --accent-hover:  #A5B4FC;
    --accent-light:  #1E2440;
    --error-bg:      #2A1618;
    --error-border:  #7F1D1D;
    --error-text:    #FCA5A5;
    --warn-bg:       #241D0E;
    --warn-border:   #78350F;
    --warn-text:     #FCD34D;
    --shadow:        0 1px 4px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md:     0 4px 20px rgba(0,0,0,.45);
  }

  /* The QR preview keeps a white plate regardless of theme. Scanners cope
     badly with inverted codes, and the default colors are black-on-white. */
  .preview-box {
    background: #FFFFFF;
    border-radius: var(--radius-sm);
  }
}

/* ═══════════════════════════════════════════════════════════════
   Centre logo controls
   ═══════════════════════════════════════════════════════════════ */
.logo-drop {
  position: relative;               /* anchors the invisible file input */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 1.1rem 0.75rem;
  cursor: pointer;
  text-align: center;
  background: var(--surface-alt);
  transition: border-color .15s, background .15s, transform .1s;
}
.logo-drop:hover { border-color: var(--accent); background: var(--accent-light); }

/* The real input is stretched over the whole zone at zero opacity. Browsers
   let a native file input accept dropped files, so this gives working
   drag-and-drop without any JavaScript. */
.logo-drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.logo-drop.dragging {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-light);
  transform: scale(1.01);
}

.logo-drop-icon { font-size: 1.4rem; line-height: 1; opacity: 0.75; }
.logo-drop-text { font-size: 0.85rem; color: var(--text-2); }
.logo-drop-text strong { color: var(--accent); font-weight: 600; }
.logo-drop-meta { font-size: 0.72rem; color: var(--text-3); }

.logo-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  margin-bottom: 0.6rem;
}
.logo-thumb {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 4px;
  /* Checkerboard so transparent logos are readable against any theme. */
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e3e3e3 25%, transparent 25%, transparent 75%, #e3e3e3 75%),
    linear-gradient(45deg, #e3e3e3 25%, transparent 25%, transparent 75%, #e3e3e3 75%);
  background-size: 10px 10px;
  background-position: 0 0, 5px 5px;
  flex-shrink: 0;
}
.logo-meta { flex: 1; min-width: 0; }
.logo-name {
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logo-kind { font-size: 0.72rem; color: var(--text-3); }
.btn-logo-remove {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 4px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}
.btn-logo-remove:hover {
  border-color: var(--error-border);
  color: var(--error-text);
  background: var(--error-bg);
}

.field-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
