@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@500;700&family=Sora:wght@500;700&display=swap");

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at -14% -10%, color-mix(in srgb, var(--piky-primary) 18%, transparent), transparent 70%),
    radial-gradient(760px 420px at 110% -8%, color-mix(in srgb, var(--focus-ring) 18%, transparent), transparent 72%),
    var(--bg);
  line-height: 1.45;
}

body.modal-open {
  overflow: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Sora", "Manrope", sans-serif;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

a {
  color: var(--link);
}

a,
button,
input,
select,
textarea {
  font: inherit;
}

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

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 22px 16px 30px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--piky-primary);
  color: #fff;
  font-weight: 700;
}

.sub {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.inline-status--ok {
  border-color: color-mix(in srgb, var(--success) 40%, var(--border));
  color: color-mix(in srgb, var(--success) 90%, var(--text));
}

.inline-status--error {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  color: color-mix(in srgb, var(--danger) 92%, var(--text));
}

.app-grid {
  margin-top: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: 320px minmax(0, 1fr);
}

.stack {
  display: grid;
  gap: 12px;
}

.help-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.help-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
  color: var(--text);
  text-decoration: none;
  background: var(--surface-2);
  font-size: 0.9rem;
  transition: border-color 0.14s ease, transform 0.14s ease, background 0.14s ease;
}

.help-link:hover {
  border-color: color-mix(in srgb, var(--focus-ring) 38%, var(--border));
  transform: translateY(-1px);
}

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

.kv {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.kv-row b {
  color: var(--text);
}

.warn {
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border));
  background: color-mix(in srgb, var(--warning) 14%, var(--bg));
  color: color-mix(in srgb, var(--warning) 70%, var(--text));
  font-size: 0.85rem;
  padding: 8px 10px;
}

.links-head {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.links-controls {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 180px auto;
}

.links-head-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.links-list {
  display: grid;
  gap: 8px;
}

.empty-state {
  border: 1px dashed color-mix(in srgb, var(--border) 72%, transparent);
  border-radius: 14px;
  padding: 20px;
  background:
    linear-gradient(
      160deg,
      color-mix(in srgb, var(--surface) 88%, transparent),
      color-mix(in srgb, var(--surface-2) 76%, transparent)
    );
  display: grid;
  gap: 12px;
  justify-items: start;
}

.link-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 44px minmax(0, 1fr) auto auto;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 14px;
  background: var(--surface);
  padding: 10px 12px;
  transition: border-color 0.14s ease, transform 0.14s ease, background 0.14s ease;
}

.link-row[role="button"] {
  cursor: pointer;
}

.link-row:hover {
  border-color: color-mix(in srgb, var(--focus-ring) 36%, var(--border));
  transform: translateY(-1px);
}

.link-row:focus-visible {
  border-color: color-mix(in srgb, var(--focus-ring) 52%, var(--border));
  background: color-mix(in srgb, var(--surface) 86%, var(--surface-2));
}

.link-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-weight: 700;
}

.link-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.link-main {
  min-width: 0;
}

.link-title {
  margin: 0;
  font-weight: 700;
  color: var(--text);
  font-size: 0.96rem;
}

.link-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.link-url {
  margin-top: 2px;
  display: inline-block;
  font-size: 0.82rem;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.row-actions {
  position: relative;
}

.inline-error {
  border: 1px solid color-mix(in srgb, var(--danger) 34%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  padding: 12px;
  display: grid;
  gap: 10px;
}

.inline-error__title {
  font-weight: 700;
}

.inline-error .muted {
  font-size: 0.88rem;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 16, 33, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 45;
  width: min(520px, 94vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.15s ease;
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--border);
}

.sheet.open {
  transform: translateX(0);
}

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

.sheet-sub {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 0.84rem;
}

.sheet-body {
  display: grid;
  gap: 12px;
}

.sheet-group {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 10px;
}

.sheet-group h4 {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field > label {
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.toggle input {
  margin: 0;
}

.modal-stack {
  display: grid;
  gap: 10px;
}

.stat-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-value {
  margin-top: 3px;
  font-size: 1rem;
  font-weight: 700;
}

.turnstile-wrap {
  margin-top: 4px;
}

.section-note {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.form-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  min-height: 1.2em;
}

.form-hint--error {
  color: var(--danger);
}

.form-hint--ok {
  color: var(--success);
}

.debug-panel {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(480px, calc(100vw - 32px));
  max-height: min(44vh, 360px);
  z-index: 95;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 95%, var(--bg));
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
  display: grid;
  overflow: hidden;
}

.debug-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.debug-panel__body {
  margin: 0;
  padding: 10px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
  white-space: pre-wrap;
}

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

@media (max-width: 720px) {
  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .links-controls {
    grid-template-columns: 1fr;
  }

  .links-head-actions {
    justify-content: stretch;
  }

  .links-head-actions .btn {
    width: 100%;
  }

  .link-row {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    align-items: start;
  }

  .link-thumb {
    width: 40px;
    height: 40px;
  }

  .badge {
    margin-top: 3px;
  }

  .row2,
  .stat-grid {
    grid-template-columns: 1fr;
  }
}
