:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #002366;
  --accent-hover: #001a4d;
  --highlight: #fef9c3;
  --highlight-border: #facc15;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  font-family: inherit;
}

input, button, select, textarea {
  font-family: inherit;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

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

/* ===== Header ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.brand {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.logout { margin: 0; }

/* ===== Login ===== */
.login-card {
  max-width: 380px;
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .brand { font-size: 26px; }
.login-card p { margin: 4px 0 24px; font-size: 14px; }
.login-card .form-stack { text-align: left; }

/* ===== Forms ===== */
.form-stack > * + * { margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.01em;
}

input[type="password"],
input[type="url"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder {
  color: #b5b5be;
  opacity: 1;
}
input[type="password"]:focus,
input[type="url"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 35, 102, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface); border-color: var(--text-muted); text-decoration: none; }
.btn-disabled { opacity: 0.4; pointer-events: none; }

/* ===== Create card ===== */
.create-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
}
.create-form-block { display: block; }
.create-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.create-form .field { flex: 1; }
.create-form .btn-primary { width: auto; padding: 10px 22px; }

/* UTM collapsible block */
.utm-toggle {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.utm-toggle summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.utm-toggle summary::-webkit-details-marker { display: none; }
.utm-toggle summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.12s;
}
.utm-toggle[open] summary::before { transform: rotate(90deg); }
.utm-toggle summary:hover { color: var(--text); }

.utm-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}
@media (min-width: 700px) {
  .utm-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .utm-hint { grid-column: 1 / -1; }
}
.utm-hint { font-size: 12px; margin: 4px 0 0; }
.utm-hint code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 11px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ===== Alerts ===== */
.alert {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.alert.error { background: var(--error-bg); color: var(--error-text); }
.alert.success {
  background: #e7f7eb;
  color: #155f2d;
  border: 1px solid #b9e9c4;
}

/* Duplicate-found dialog */
.dup-short {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.dup-short__link {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  word-break: break-all;
}
.dup-dest {
  font-size: 12px;
  margin: 0 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Links table ===== */
.section-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.inline-form { margin: 0; display: inline; }

.link-table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
}
.link-table {
  width: 100%;
  min-width: 820px;
  border-collapse: separate;
  border-spacing: 0 6px;
  font-size: 14px;
}
.link-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 4px 12px 8px;
}
.link-table thead .col-qr,
.link-table thead .col-clicks,
.link-table thead .col-actions { text-align: center; }

.link-table tbody td {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  vertical-align: middle;
}
.link-table tbody td:first-child {
  border-left: 1px solid var(--border);
  border-top-left-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
}
.link-table tbody td:last-child {
  border-right: 1px solid var(--border);
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

/* Column-specific layout */
.link-table .col-short { width: 1%; white-space: nowrap; }
.link-table .col-dest { min-width: 280px; max-width: 0; }
.link-table .col-qr,
.link-table .col-clicks { width: 1%; text-align: center; }
.link-table .col-source { width: 1%; white-space: nowrap; text-align: center; }
.link-table .col-date { width: 1%; white-space: nowrap; }
.link-table .col-actions { width: 1%; text-align: right; }

.source-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
/* Per-label tints so the eye picks up source at a glance.
   Lowercased label is interpolated into the class — keep names short. */
.source-badge--marketing { background: #fff4d6; color: #6b5300; border-color: #f0d97a; }
.source-badge--team      { background: #e7f0ff; color: #1d3a8a; border-color: #b9cffc; }
.source-badge--default   { background: #f4ecff; color: #5b21b6; border-color: #d3c5f4; }

.short-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}
.link-short {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 14px;
  font-weight: 500;
}

.dest-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.dest-cell a {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.dest-cell a:hover { color: var(--accent); }
.favicon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--bg);
}

.col-clicks { font-variant-numeric: tabular-nums; font-weight: 500; }
.col-date time {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.actions-cell {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  justify-content: flex-end;
}

/* Icon buttons (used inside table + dialogs) */
.btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-icon:disabled {
  opacity: 1;
  color: var(--accent);
  cursor: default;
}
.btn-icon.btn-danger:hover {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-text);
}

/* Highlight just-created row — 2px royal-blue border around the row */
.link-row--new td {
  border-color: var(--accent);
  border-top-width: 2px;
  border-bottom-width: 2px;
  animation: pulseNew 1.2s ease-out;
}
.link-row--new td:first-child { border-left-width: 2px; }
.link-row--new td:last-child  { border-right-width: 2px; }
@keyframes pulseNew {
  0% { transform: translateY(-4px); opacity: 0.5; }
  100% { transform: translateY(0); opacity: 1; }
}

.empty-state { padding: 32px; text-align: center; }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}
.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===== Dialog (edit modal) ===== */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 480px;
  width: calc(100% - 32px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}
.dialog__form {
  padding: 22px 22px 18px;
}
.dialog__title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
}
.dialog__hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.dialog__hint code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12px;
  padding: 1px 6px;
  background: var(--bg);
  border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-all;
}
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.dialog__actions .btn-primary { width: auto; padding: 8px 18px; }
.dialog__hint strong {
  font-weight: 600;
  color: var(--text);
}

/* Native dialog open animation */
.dialog[open] {
  animation: dialogIn 0.14s ease-out;
}
.dialog[open]::backdrop {
  animation: backdropIn 0.14s ease-out;
}
@keyframes dialogIn {
  from { transform: translateY(-8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes backdropIn {
  from { background: rgba(15, 23, 42, 0); }
  to   { background: rgba(15, 23, 42, 0.45); }
}

/* Danger variant for destructive primary buttons */
.btn-primary.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: transparent;
}
.btn-primary.btn-danger:hover {
  background: #b91c1c;
}

/* ===== Header actions (Корзина + Выйти) ===== */
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== Full-screen dialog (reused by future search) ===== */
.dialog.dialog--fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  border: none;
  padding: 0;
  background: var(--bg);
  /* Long contents scroll inside the dialog, not the page underneath. */
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Body scroll lock — added by JS while a fullscreen dialog is open so
   the wheel/touch scroll over the backdrop doesn't move the page below. */
body.no-scroll {
  overflow: hidden;
}
.dialog--fullscreen::backdrop {
  background: rgba(15, 23, 42, 0.65);
}
.dialog__fullscreen-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 32px 64px;
}
.dialog__close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 22px;
  transition: background 0.12s, color 0.12s;
}
.dialog__close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
}
.dialog__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Trash overlay specifics */
.trash-title {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 600;
}
.trash-subtitle {
  margin: 0 0 22px;
  font-size: 14px;
}
.trash-empty {
  text-align: center;
  padding: 60px 0;
}
.trash-purge-hint {
  font-size: 11px;
  margin-top: 2px;
}
.link-short--muted {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ===== Custom-slug field inside Параметры block ===== */
.slug-row {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: grid;
  gap: 6px;
}

/* ===== 404 page ===== */
.not-found {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}
.not-found__code {
  font-size: clamp(96px, 18vw, 200px);
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--accent);
  line-height: 1;
}
.not-found__msg {
  margin: 0;
  font-size: 18px;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .create-form { flex-direction: column; align-items: stretch; }
  .create-form .btn-primary { width: 100%; }
  .dialog__fullscreen-inner { padding: 56px 16px 40px; }
  .header-actions .btn span { display: none; }
}
