/* ================================================================
   AI Card Collector — stylesheet
   Plain CSS. No framework, no CDN, no build step.
   ================================================================ */

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
main form p { margin: 0; }

/* ---- Variables ---- */
:root {
  --bg:          #f3f4f6;
  --surface:     #ffffff;
  --border:      #e5e7eb;
  --border-md:   #d1d5db;
  --text:        #111827;
  --text-muted:  #6b7280;
  --primary:     #2563eb;
  --primary-h:   #1d4ed8;
  --danger:      #dc2626;
  --danger-h:    #b91c1c;
  --radius:      6px;
  --shadow:      0 1px 4px rgba(0, 0, 0, .08);
}

/* ---- Base ---- */
html { font-size: 16px; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  padding: 0;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.3rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }

p { margin: 0 0 .75rem; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout: header ---- */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: .85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}

header h1 { margin: 0; }

header > p {
  margin: 0;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  color: var(--text-muted);
}

/* ---- Layout: main ---- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ---- Login page ---- */
body.page-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

body.page-login h1 {
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 1.5rem;
}

body.page-login form {
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---- Form fields ---- */
main form { max-width: 580px; }

main form > p,
main form > div.field {
  margin: 0 0 .65rem;
}

main form > p:last-of-type {
  margin-top: 1rem;
}

label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  margin-bottom: .25rem;
  color: var(--text);
}

label span[aria-label="required"] {
  color: var(--danger);
  margin-left: .15rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: .5rem .75rem;
  font-size: .95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea { resize: vertical; line-height: 1.5; }

/* ---- Buttons ---- */
/* Base: primary blue — applies to form submit buttons generally */
button[type="submit"] {
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  padding: .55rem 1.35rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  transition: background .15s;
}

button[type="submit"]:hover { background: var(--primary-h); }

/* Log out button — small, muted, in header */
header button[type="submit"] {
  padding: .28rem .8rem;
  font-size: .8rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-md);
}

header button[type="submit"]:hover {
  background: var(--bg);
  color: var(--text);
}

/* Delete button — danger style, in table */
.card-table button[type="submit"] {
  padding: .22rem .6rem;
  font-size: .78rem;
  font-weight: 500;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
}

.card-table button[type="submit"]:hover {
  background: var(--danger);
  color: #fff;
}

/* ---- Wanted cards table ---- */
.card-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  table-layout: fixed;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-top: 1.25rem;
}

.card-table th {
  background: #f9fafb;
  border-bottom: 2px solid var(--border);
  padding: .6rem 1rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
}

.card-table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Name and next-step columns may wrap */
.card-table td:nth-child(3),
.card-table .next-step-cell {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.card-table th {
  padding: .5rem .75rem;
}

.card-table tr:last-child td { border-bottom: none; }
.card-table tbody tr:hover { background: #fafafa; }

/* Score column — prominent */
.card-table td:first-child {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  text-align: center;
}

.card-table th:first-child { text-align: center; }

/* Actions column */
.card-table td:last-child { white-space: nowrap; }

/* Action links (Edit, Message) styled as small pill buttons */
.card-table a {
  display: inline-block;
  font-size: .78rem;
  padding: .22rem .6rem;
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  color: var(--text-muted);
  margin-right: .3rem;
  transition: border-color .12s, color .12s;
}

.card-table a:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

/* ---- Errors ---- */
.errors {
  list-style: none;
  padding: .75rem 1rem;
  margin: 0 0 1.25rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: .9rem;
}

.errors li + li { margin-top: .25rem; }

p.error {
  padding: .65rem 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: .9rem;
}

/* ---- Stats bar ---- */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1.25rem;
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .5rem .9rem;
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: border-color .12s, box-shadow .12s;
  min-width: 64px;
}

.stat-chip:hover {
  border-color: var(--primary);
  text-decoration: none;
}

.stat-chip.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.stat-num {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-chip.active .stat-num { color: var(--primary); }

.stat-label {
  font-size: .7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-top: .15rem;
  white-space: nowrap;
}

/* ---- List header (title + add button inline) ---- */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .25rem;
}

.list-header h2 { margin: 0; }

.btn-add {
  font-size: .82rem;
  font-weight: 600;
  padding: .35rem .9rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  white-space: nowrap;
  transition: background .12s;
}

.btn-add:hover {
  background: var(--primary-h);
  text-decoration: none;
  color: #fff;
}

/* ---- Table action buttons (Edytuj / Wiadomość / Usuń) ---- */
.actions-cell {
  white-space: nowrap;
}

.act-btn {
  display: inline-block;
  font-size: .75rem;
  font-weight: 500;
  font-family: inherit;
  padding: .22rem .6rem;
  border: 1px solid var(--border-md);
  border-radius: 4px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  transition: border-color .1s, color .1s;
}

.act-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}

.act-btn-danger {
  color: var(--danger);
  border-color: #fca5a5;
}

.act-btn-danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---- Score info tooltip ---- */
.score-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  font-size: .65rem;
  font-weight: 700;
  background: var(--text-muted);
  color: #fff;
  border-radius: 50%;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: .3rem;
}

.score-tooltip {
  display: none;
  position: fixed;
  background: #1f2937;
  color: #f9fafb;
  font-size: .78rem;
  font-weight: 400;
  line-height: 1.7;
  white-space: normal;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  z-index: 9999;
  width: 280px;
  pointer-events: none;
  text-transform: none;
  letter-spacing: 0;
}

.score-tooltip.visible { display: block; }

/* ---- Attention box ---- */
.attention-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid #f59e0b;
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: 1.25rem;
}

.attention-title {
  font-weight: 700;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #92400e;
  margin-bottom: .5rem;
}

.attention-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.attention-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
}

.attention-sep { color: #9ca3af; }

.attention-status {
  font-size: .72rem;
  font-weight: 600;
  padding: .15rem .45rem;
  border-radius: 99px;
  white-space: nowrap;
}

.attention-searching      { background: #dbeafe; color: #1e40af; }
.attention-contacted      { background: #fef3c7; color: #92400e; }
.attention-offer_received { background: #ede9fe; color: #5b21b6; }

/* ---- Table row status colours ---- */
.row-contacted      td { background: #fffbeb; }
.row-offer_received td { background: #f5f3ff; }
.row-acquired       td { background: #f0fdf4; }
.row-abandoned      td { color: #9ca3af; }

/* ---- Next step cell ---- */
.next-step-cell { white-space: normal; }

.next-step-link {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: .2rem .5rem;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  background: #eff6ff;
  white-space: normal;
  display: inline-block;
  line-height: 1.3;
}

.next-step-link:hover { background: #dbeafe; }

/* ---- API hint chip ---- */
.api-hint {
  font-size: .75rem;
  font-weight: 600;
  color: #5b21b6;
  background: #ede9fe;
  border: 1px solid #c4b5fd;
  border-radius: 99px;
  padding: .2rem .65rem;
  cursor: help;
  white-space: nowrap;
}

/* ---- Quick status select ---- */
.status-form { margin: 0; }

.status-select {
  width: auto;
  padding: .2rem .4rem;
  font-size: .78rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-md);
  background: var(--surface);
  cursor: pointer;
}

.status-select.status-searching      { border-color: #2563eb; color: #2563eb; }
.status-select.status-contacted      { border-color: #d97706; color: #d97706; }
.status-select.status-offer_received { border-color: #7c3aed; color: #7c3aed; }
.status-select.status-acquired       { border-color: #16a34a; color: #16a34a; }
.status-select.status-abandoned      { border-color: #9ca3af; color: #9ca3af; }

/* ---- Card thumbnail in table ---- */
.thumb-cell {
  padding: .3rem .4rem !important;
  text-align: center;
  vertical-align: middle;
}

.card-thumb {
  display: block;
  width: 30px;
  height: 42px;
  object-fit: contain;
  border-radius: 3px;
}

.card-thumb-placeholder {
  width: 30px;
  height: 42px;
  border-radius: 3px;
  background-color: #f0f2f5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 42'%3E%3Crect x='1' y='1' width='28' height='40' rx='3' fill='none' stroke='%23d1d5db' stroke-width='1.2'/%3E%3Crect x='4' y='4' width='22' height='15' rx='2' fill='%23e5e7eb'/%3E%3Ccircle cx='15' cy='28' r='5' fill='none' stroke='%23d1d5db' stroke-width='1.2'/%3E%3Cline x1='12' y1='28' x2='18' y2='28' stroke='%23d1d5db' stroke-width='1.2'/%3E%3Cline x1='15' y1='25' x2='15' y2='31' stroke='%23d1d5db' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}

/* ---- Score badge ---- */
.score-cell { text-align: center; padding: .4rem .3rem !important; }

.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 24px;
  padding: 0 .35rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: default;
}

.score-none     { background: #f3f4f6; color: #9ca3af; }
.score-low      { background: #dcfce7; color: #15803d; }
.score-medium   { background: #fef9c3; color: #854d0e; }
.score-high     { background: #ffedd5; color: #c2410c; }
.score-critical { background: #fee2e2; color: #991b1b; }

/* ---- Copy button (card-message page) ---- */
.copy-btn {
  display: inline-block;
  margin-top: .5rem;
  padding: .3rem .9rem;
  font-size: .82rem;
  font-weight: 500;
  font-family: inherit;
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, color .12s;
}

.copy-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* ---- Card message page ---- */
section + section { margin-top: 1.75rem; }

dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .3rem 1.25rem;
  margin: .5rem 0 1.25rem;
  font-size: .9rem;
}

dt { font-weight: 600; color: var(--text-muted); }
dd { margin: 0; }

textarea[readonly] {
  background: #f9fafb;
  font-family: "Courier New", Courier, monospace;
  font-size: .85rem;
  min-height: 210px;
  color: var(--text);
}

/* ---- Shared form sections (card-add / card-edit) ---- */
.edit-form { max-width: 760px; }

.form-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.form-section-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #6b7280;
  margin: 0 0 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid #f3f4f6;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 1.25rem;
}

.field-row.full { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: .25rem; }

.field label {
  font-size: .82rem;
  font-weight: 600;
  color: #374151;
  margin: 0;
}

.field label .req { color: #dc2626; margin-left: .15rem; }

.field input,
.field select,
.field textarea {
  font-size: .9rem;
  padding: .45rem .7rem;
}

.field textarea { min-height: 80px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: .5rem;
}

@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; }
  .edit-form, #add-form { max-width: 100%; }
}

/* ---- Flash toast ---- */
.flash-toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}

.flash-msg {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .7rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-size: .875rem;
  font-weight: 500;
  max-width: 340px;
  pointer-events: all;
  animation: flash-in .2s ease;
}

@keyframes flash-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.flash-success { background: #f0fdf4; border: 1px solid #86efac; color: #15803d; }
.flash-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.flash-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1d4ed8; }

.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  opacity: .6;
  padding: 0;
}
.flash-close:hover { opacity: 1; }

/* ---- Cancel / Reset buttons ---- */
.btn-cancel {
  font-size: .875rem;
  color: var(--text-muted);
  text-decoration: none;
}

.btn-cancel:hover {
  color: var(--text);
  text-decoration: underline;
}

.btn-reset {
  font-size: .75rem;
  font-family: inherit;
  padding: .2rem .6rem;
  border: 1px solid var(--border-md);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-reset:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ---- Market price delta (price-refresh feature) ---- */
.market-cell {
  font-variant-numeric: tabular-nums;
  font-size: .82rem;
  white-space: nowrap;
}

.market-delta {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.delta-warn     { color: #d97706; }
.delta-critical { color: #dc2626; }
.delta-ok       { color: #16a34a; }

/* Refresh button — matches act-btn but with a spinner state */
#btn-refresh-prices:disabled {
  opacity: .65;
  cursor: default;
}

/* ---- Table scroll wrapper (all viewports) ---- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1.25rem;
}

.table-scroll .card-table {
  margin-top: 0;
  min-width: 1020px;
}

/* ---- Responsive ---- */
@media (max-width: 700px) {
  header  { padding: .75rem 1rem; }
  main    { padding: 1.25rem 1rem; }
  main form { max-width: 100%; }
  body.page-login form { padding: 1.5rem; }
}
