:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #cd0f23;
  --accent-hover: #e3192e;
  --focus: #ff4d5e;
  --danger: #ff5c5c;
  --success: #3ecf8e;

  --brand-red: rgb(205, 15, 35);
  --brand-dark: rgb(104, 4, 12);
  --brand-grey: rgb(112, 111, 112);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: "Liberation Sans", Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--accent-hover); }

h1 { font-size: 1.5rem; margin: 0 0 18px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }

.muted { color: var(--muted); font-weight: 400; }
.inline { display: inline; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand img { width: 24px; height: 24px; display: block; }
.brand-accent { color: var(--accent); }
.brand-sub { font-weight: 400; }

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

.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  text-decoration: none;
}

.nav-link svg,
.signout svg { width: 16px; height: 16px; flex: none; }

.nav-link:hover { background: var(--surface-2); color: var(--text); }

.nav-link[aria-current="page"] {
  background: rgba(205, 15, 35, 0.15);
  color: var(--text);
}

.nav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.nav-divider { width: 1px; height: 24px; margin: 0 6px; background: var(--border); }

.signout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.signout:hover { border-color: var(--accent); color: var(--text); }

@media (max-width: 820px) {
  .brand-sub { display: none; }
}

@media (max-width: 640px) {
  .nav-label { display: none; }
  .nav-link { padding: 8px 10px; }
  .nav-divider { margin: 0 2px; }
}

/* Layout */

.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 56px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.card.narrow { max-width: 440px; margin: 48px auto; }

.auth-card { max-width: 440px; margin: 56px auto; }
.auth-logo { display: block; width: 56px; height: 56px; margin: 0 auto 14px; }
.auth-card h1 { text-align: center; }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; flex: none; }

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

.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--muted); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: rgba(255, 92, 92, 0.12); }

.btn-sm { min-height: 28px; padding: 0 8px; border-radius: 7px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

a.button:hover { border-color: var(--muted); }

button.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent-hover);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button.link:hover { text-decoration: underline; }

/* Alerts */

.alert { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.88rem; }
.alert.error { background: rgba(255, 92, 92, 0.1); border-color: rgba(255, 92, 92, 0.35); color: #ffb3b3; }
.alert.success { background: rgba(62, 207, 142, 0.1); border-color: rgba(62, 207, 142, 0.35); color: #b6f2d7; }
.alert ul { margin: 0; padding-left: 1.1rem; }

/* Forms */

label { display: block; margin: 0 0 6px; font-size: 0.9rem; }

input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

input::placeholder { color: #6b7382; }

input[type="text"]:focus-visible,
input[type="password"]:focus-visible,
input[type="search"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

input[aria-invalid="true"] { border-color: var(--danger); }

input[type="checkbox"] { accent-color: var(--accent); }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hint { display: block; margin-top: 5px; color: var(--muted); font-size: 0.8rem; }
.field-error { margin: 5px 0 0; color: var(--danger); font-size: 0.82rem; }

.input-group { display: flex; align-items: stretch; }
.input-group input { flex: 1; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

/* Generator */

.generator-layout {
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}

.preview-column { position: sticky; top: 80px; }

@media (max-width: 960px) {
  .generator-layout { grid-template-columns: 1fr; }
  .preview-column { order: -1; position: static; }
}

.form-section + .form-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-section h2 {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-actions { margin-top: 16px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.segment { position: relative; display: block; margin: 0; }

.segment input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segment-body {
  display: block;
  height: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.segment-title { display: block; font-size: 0.9rem; font-weight: 600; }
.segment-help { display: block; margin-top: 4px; color: var(--muted); font-size: 0.78rem; line-height: 1.35; }

.segment input:checked + .segment-body {
  border-color: var(--accent);
  background: rgba(205, 15, 35, 0.12);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.segment input:focus-visible + .segment-body { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (max-width: 420px) {
  .segmented { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

/* Preview */

.preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.preview-head h2 { margin-bottom: 2px; }
.preview-head .muted { margin: 0; font-size: 0.82rem; }

.zoom {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.zoom button {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.zoom button:hover { color: var(--text); }
.zoom button[aria-pressed="true"] { background: rgba(205, 15, 35, 0.2); color: var(--text); }

.email-canvas {
  padding: 22px 24px;
  border: 1px solid #e6e6e8;
  border-radius: 8px;
  background: #fff;
  color: #222;
  overflow: auto;
}

.kind-regards {
  margin: 0 0 14px;
  color: #222;
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(14px * var(--zoom, 1));
}

#preview-img {
  display: block;
  width: calc(600px * var(--zoom, 1));
  max-width: none;
  height: auto;
}

.preview-placeholder { margin: 0; color: #8a8a8f; font-size: calc(13px * var(--zoom, 1)); }
#preview-error { margin-top: 12px; }

.links-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.link-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.link-list li { display: flex; justify-content: space-between; gap: 12px; font-size: 0.82rem; }
.link-list .link-name { color: var(--muted); }
.link-list .link-url { color: var(--text); text-align: right; overflow-wrap: anywhere; }

/* History */

.filter { display: flex; gap: 8px; max-width: 520px; margin-bottom: 16px; }
.filter input { flex: 1; }

.history-form { margin-top: 4px; }

.bulk-bar {
  position: sticky;
  top: 68px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.bulk-count { margin-right: auto; color: var(--muted); font-size: 0.88rem; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

table.grid th,
table.grid td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
  text-align: left;
  vertical-align: middle;
}

table.grid th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.grid tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
table.grid tr:last-child td { border-bottom: none; }

td.thumb { width: 132px; }
td.thumb img {
  display: block;
  width: 120px;
  height: 40px;
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

th.select,
td.select { width: 2.25rem; text-align: center; }
th.select input,
td.select input { width: auto; }

td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge-html { border-color: rgba(205, 15, 35, 0.5); background: rgba(205, 15, 35, 0.15); color: #ffd0d5; }
.badge-svg { border-color: rgba(94, 160, 255, 0.4); background: rgba(94, 160, 255, 0.12); color: #bfd7ff; }
.badge-png { border-color: rgba(210, 180, 90, 0.4); background: rgba(210, 180, 90, 0.12); color: #e6dcb8; }

.pager { display: flex; align-items: center; gap: 16px; margin-top: 16px; color: var(--muted); font-size: 0.88rem; }
.pager a { color: var(--text); text-decoration: none; }
.pager a:hover { color: var(--accent-hover); }

/* Dialog */

.dialog {
  max-width: 440px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog h2 { margin-top: 0; }
.dialog p { margin: 8px 0; }
.dialog .warning { color: #ffb3b3; font-size: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Result page */

.result-panel { margin-bottom: 24px; }

.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.result-actions .muted { font-size: 0.85rem; }

.result-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

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

.email-preview {
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  color: #222;
  overflow: auto;
}

.email-preview > img,
.email-preview > svg { display: block; max-width: 100%; height: auto; }

.tab-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.tab {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.tab[aria-selected="true"] { border-color: var(--accent); background: rgba(205, 15, 35, 0.15); color: var(--text); }

.tab-panel ol { margin: 0; padding-left: 1.2rem; }
.tab-panel li { margin-bottom: 6px; }

code,
kbd {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.82em;
}

.result-back { margin-top: 24px; color: var(--muted); font-size: 0.9rem; }
.result-back a { color: var(--text); text-decoration: none; }
.result-back a:hover { color: var(--accent-hover); }

/* Company footer */

.alert.warning {
  margin-top: 10px;
  margin-bottom: 14px;
  background: rgba(255, 190, 60, 0.12);
  border-color: rgba(255, 190, 60, 0.45);
  color: #ffe1a6;
}

textarea.code {
  width: 100%;
  min-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre;
  overflow: auto;
  resize: vertical;
}

textarea.code:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.mode-switch { max-width: 720px; margin-bottom: 18px; }
