/*
 * Desktronic affiliate deep link generator.
 * Tokens are taken from the live desktronic.lt storefront:
 *   #19191c brand black, #6b6f56 moss green (the "Samanų žalia" swatch),
 *   #bc9869 oak, #cec5b1 warm neutral, Inter, 4px corners.
 */

:root {
  --moss: #6b6f56;
  --moss-hover: #5a5e47;
  --oak: #bc9869;
  --warm: #cec5b1;

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-warm: #fbfaf7;
  --text: #19191c;
  --text-muted: #74787e;
  --line: #ebebeb;
  --line-strong: #d9d9d9;
  --field-bg: #ffffff;
  --chip-bg: #f5f5f5;
  --warn-bg: #fdf8ee;
  --warn-line: #e6c98a;
  --warn-text: #7a5a12;
  --danger: #b23b3b;

  --radius: 4px;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark mode follows the system by default; the toggle overrides it either way. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131315;
    --surface: #19191c;
    --surface-warm: #1e1d1a;
    --text: #f2f2f0;
    --text-muted: #9a9a9e;
    --line: #2c2c30;
    --line-strong: #3a3a3f;
    --field-bg: #121214;
    --chip-bg: #232327;
    --warn-bg: #241f14;
    --warn-line: #6b5628;
    --warn-text: #d7b871;
    --moss: #8b9070;
    --moss-hover: #9aa07d;
    --danger: #e08585;
  }
}

:root[data-theme="dark"] {
  --bg: #131315;
  --surface: #19191c;
  --surface-warm: #1e1d1a;
  --text: #f2f2f0;
  --text-muted: #9a9a9e;
  --line: #2c2c30;
  --line-strong: #3a3a3f;
  --field-bg: #121214;
  --chip-bg: #232327;
  --warn-bg: #241f14;
  --warn-line: #6b5628;
  --warn-text: #d7b871;
  --moss: #8b9070;
  --moss-hover: #9aa07d;
  --danger: #e08585;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar: wordmark, tabs, theme toggle ---------- */

.topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 12px 24px;
}

.wordmark {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar .spacer { flex: 1; }

.topbar .subtitle { color: var(--moss); font-size: 13px; }

.tabs { display: flex; gap: 24px; }

/* The tabs are real links now: the two pages stand alone, so each has its
   own URL and can be handed to a partner directly. */
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  padding: 4px 0;
  text-decoration: none;
  transition: color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--moss); }
.tab[aria-current="page"] { border-bottom-color: var(--moss); color: var(--text); }

.icon-button {
  align-items: center;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  padding: 4px;
  transition: color .15s ease, opacity .15s ease;
}
.icon-button:hover { color: var(--text); }

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-size: 20px;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  font-weight: normal;
  line-height: 1;
  -webkit-font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout ---------- */

.page {
  margin: 0 auto;
  max-width: 1180px;
  padding: 32px 24px 64px;
}

.columns {
  display: grid;
  gap: 32px;
  grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
  align-items: start;
}

@media (max-width: 900px) {
  .columns { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .page { padding: 24px 16px 48px; }
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
}

/* ---------- form ---------- */

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

.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.label .optional {
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
}

input[type="text"], select, textarea {
  background: var(--field-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 11px;
  width: 100%;
}

input.mono, textarea.mono { font-family: var(--mono); font-size: 13px; }

input:focus, select:focus, textarea:focus {
  border-color: var(--moss);
  outline: 2px solid color-mix(in srgb, var(--moss) 25%, transparent);
  outline-offset: -1px;
}

textarea { min-height: 180px; resize: vertical; line-height: 1.6; }

.field-row {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

/* Segmented offer control */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented button {
  background: var(--field-bg);
  border: none;
  border-right: 1px solid var(--line-strong);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  padding: 9px 4px;
}
.segmented button:last-child { border-right: none; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
}

.button-primary {
  background: var(--moss);
  border: 1px solid var(--moss);
  border-radius: var(--radius);
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 16px;
  width: 100%;
}
.button-primary:hover { background: var(--moss-hover); border-color: var(--moss-hover); }
:root[data-theme="dark"] .button-primary,
:root:not([data-theme="light"]) .button-primary { color: #14140f; }

.button-secondary {
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
}
.button-secondary:hover { border-color: var(--text-muted); }

/* ---------- notices ---------- */

.notice {
  align-items: flex-start;
  border-radius: var(--radius);
  display: flex;
  font-size: 12.5px;
  gap: 8px;
  line-height: 1.45;
  margin-top: 8px;
  padding: 8px 10px;
}
.notice-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-text);
}
.notice-error {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.notice .glyph { flex: none; line-height: 1.35; }

/* ---------- result ---------- */

.section-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-head {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}
.result-head .spacer { flex: 1; }

.result-panel {
  background: var(--surface-warm);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.result-url {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-all;
}

.result-empty { color: var(--text-muted); font-family: var(--sans); }

.decoded { margin-top: 28px; }
.decoded pre {
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  margin: 8px 0 0;
  overflow-wrap: anywhere;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- recent list ---------- */

.recent { border-top: 1px solid var(--line); margin-top: 32px; padding-top: 20px; }
.recent-head { align-items: center; display: flex; gap: 12px; margin-bottom: 12px; }
.recent-head .spacer { flex: 1; }

.recent-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.recent-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  transition: background .15s ease;
}
.recent-row:last-child { border-bottom: none; }
.recent-row:hover { background: var(--surface-warm); }
.recent-row .grow { flex: 1; min-width: 0; }

.recent-label {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 2px 4px;
  width: 100%;
}
.recent-label:hover { border-color: var(--line-strong); }
.recent-label:focus { border-color: var(--moss); outline: none; }

.recent-link {
  color: var(--text-muted);
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  overflow: hidden;
  padding: 2px 4px 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chips { display: flex; flex: none; gap: 6px; }
.chip {
  background: var(--chip-bg);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* The row copy button fades in on hover, but stays put on touch devices
   where there is no hover to reveal it. */
.recent-row .icon-button { opacity: 0; }
.recent-row:hover .icon-button,
.recent-row .icon-button:focus-visible { opacity: 1; }
@media (hover: none) {
  .recent-row .icon-button { opacity: 1; }
}

/* ---------- bulk ---------- */

.bulk-actions { align-items: center; display: flex; gap: 12px; margin-top: 16px; }
.bulk-actions .spacer { flex: 1; }
.bulk-count { color: var(--text-muted); font-size: 12.5px; }

.table-wrap { margin-top: 24px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 9px 12px 9px 0;
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
td.mono {
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-all;
}
td.row-error { color: var(--danger); font-size: 12.5px; }

/* ---------- explainer ---------- */

.explainer {
  border-left: 2px solid var(--oak);
  margin-top: 36px;
  padding-left: 16px;
}
.explainer summary {
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  list-style: none;
  padding: 6px 0;
}
.explainer summary::-webkit-details-marker { display: none; }
.explainer summary::before { content: "› "; color: var(--text-muted); }
.explainer[open] summary::before { content: "⌄ "; }
.explainer .body {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.65;
  max-width: 70ch;
  padding: 4px 0 12px;
}
.explainer .body code {
  background: var(--chip-bg);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 4px;
}
.explainer .body pre {
  background: var(--chip-bg);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  overflow-x: auto;
  padding: 10px 12px;
}
.explainer .body p { margin: 0 0 12px; }

.hidden { display: none !important; }

.toast {
  background: var(--text);
  border-radius: var(--radius);
  bottom: 24px;
  color: var(--bg);
  font-size: 13px;
  left: 50%;
  opacity: 0;
  padding: 9px 16px;
  pointer-events: none;
  position: fixed;
  transform: translateX(-50%) translateY(6px);
  transition: opacity .16s ease, transform .16s ease;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- footer ---------- */

.site-footer {
  align-items: center;
  border-top: 1px solid var(--oak);
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 12px;
  justify-content: space-between;
  margin-top: auto;
  padding: 16px 24px;
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--oak); }

body { display: flex; flex-direction: column; min-height: 100vh; }
.page { flex: 1 0 auto; width: 100%; }

@media (max-width: 900px) {
  .site-footer { padding: 16px; }
}

/* ---------- mode switch and locked values ---------- */

.segmented-sm { border-radius: var(--radius); display: inline-flex; }
.segmented-sm button { font-size: 12px; padding: 5px 12px; }

.field-hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: 6px 0 0;
}

/* The parameters an affiliate cannot change: shown so they can see exactly
   what is being tracked, styled as information rather than as a form field. */
.locked {
  background: var(--surface-warm);
  border: 1px solid var(--line);
  border-left: 2px solid var(--oak);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.locked-head {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  font-size: 11.5px;
  margin-bottom: 8px;
}

.locked dl {
  display: grid;
  gap: 4px 14px;
  grid-template-columns: auto 1fr;
  margin: 0;
}
.locked dt {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 12px;
}
.locked dd {
  font-family: var(--mono);
  font-size: 12px;
  margin: 0;
  overflow-wrap: anywhere;
}
.locked dd.absent { color: var(--text-muted); font-family: var(--sans); font-style: italic; }

@media (max-width: 700px) {
  .topbar .subtitle { display: none; }
  .topbar { gap: 16px; }
}

/* The mode groups are wrappers, so the :last-child rule that removes the
   bottom margin inside a card must not fire on their last field. */
#affiliate-fields > .field:last-child,
#manager-fields-top > .field:last-child,
#manager-fields-bottom > .field:last-child { margin-bottom: 20px; }

/* The bulk page is a single column, so it does not need the full width. */
.page-narrow { max-width: 940px; }

.bulk-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 12px; }
.bulk-actions .spacer { flex: 1; }

/* Warnings sit under a link inside a table cell rather than beside it. */
td .notice { display: inline-flex; margin-top: 6px; }
