* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1c1c1e;
  background: #f5f5f7;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-top: 2rem; }

a { color: #0a58ca; }
code {
  background: #ececf0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  word-break: break-all;
}
.muted { color: #6e6e73; }
.error { color: #c0392b; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e2e2e6;
}
.brand { font-weight: 700; text-decoration: none; color: #1c1c1e; }

.btn {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  background: #fff;
  color: #1c1c1e;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f0f0f2; }
.btn-primary { background: #0a58ca; border-color: #0a58ca; color: #fff; }
.btn-primary:hover { background: #0b5ed7; }
.btn-danger { color: #c0392b; border-color: #e5b4ae; }
.btn-danger:hover { background: #fdf0ee; }
.btn-ghost { border: none; background: none; color: #6e6e73; }
.btn-copy {
  padding: 2px 8px;
  font-size: 0.9rem;
  vertical-align: middle;
  margin-left: 4px;
}
.btn-copy.copied { color: #1a7f37; border-color: #a6d8b4; }

.create-form { display: flex; gap: 8px; margin: 20px 0; }
.create-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  font-size: 1rem;
}

.table-wrap {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; text-align: left; font-size: 0.9rem; vertical-align: middle; }
th {
  background: #fafafa;
  color: #6e6e73;
  font-weight: 600;
  border-bottom: 1px solid #e2e2e6;
  white-space: nowrap;
}
tbody tr + tr td { border-top: 1px solid #f0f0f2; }
td.ua { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.cell-date { white-space: nowrap; }
td.cell-link { white-space: nowrap; }
td.cell-link code { white-space: nowrap; }
td.cell-visits { white-space: nowrap; }
.cell-visits strong { font-size: 1rem; }
.cell-visits .sub { display: block; font-size: 0.75rem; color: #6e6e73; }

.actions { display: flex; gap: 6px; align-items: center; }
.actions form { margin: 0; }
td .actions .btn { padding: 5px 9px; font-size: 0.8rem; }

.detail-grid { display: flex; gap: 32px; flex-wrap: wrap; align-items: flex-start; margin-top: 16px; }
.qr-preview { text-align: center; }
.qr-preview img { background: #fff; border: 1px solid #e2e2e6; border-radius: 8px; padding: 8px; max-width: 100%; height: auto; }
.qr-preview .actions { justify-content: center; margin-top: 10px; }

.meta dt { color: #6e6e73; font-size: 0.8rem; margin-top: 12px; }
.meta dd { margin: 2px 0 0; }
.big-number { font-size: 2rem; font-weight: 700; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
  padding: 12px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  overflow-x: auto;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 36px;
  flex-shrink: 0;
}
.bar { width: 24px; background: #0a58ca; border-radius: 3px 3px 0 0; }
.bar-label { font-size: 0.65rem; color: #6e6e73; margin-top: 4px; white-space: nowrap; }
.bar-count { font-size: 0.7rem; margin-bottom: 2px; }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 300px;
  max-width: 100%;
  padding: 28px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.login-card h1 { margin: 0 0 4px; text-align: center; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  font-size: 1rem;
}

/* --- Mobile --- */
@media (max-width: 720px) {
  .create-form { flex-direction: column; }
  .create-form .btn { padding: 10px 12px; }

  /* the QR list turns into cards; other tables keep horizontal scroll */
  .qr-table thead { display: none; }
  .qr-table, .qr-table tbody, .qr-table tr, .qr-table td { display: block; width: 100%; }
  .qr-table tr { padding: 12px 14px; }
  .qr-table tr + tr { border-top: 1px solid #e2e2e6; }
  .qr-table td { padding: 4px 0; border: none !important; }
  .qr-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    color: #6e6e73;
    margin-bottom: 1px;
  }
  .qr-table .cell-name { padding-top: 0; }
  .qr-table .cell-name::before { display: none !important; }
  .qr-table .cell-name a { font-size: 1.05rem; font-weight: 600; text-decoration: none; }
  .qr-table td.cell-link code { white-space: normal; }
  .qr-table .cell-visits .sub { display: inline; margin-left: 6px; }
  .qr-table .cell-actions { padding-top: 10px; }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 auto; text-align: center; }

  .detail-grid { flex-direction: column; gap: 20px; }
  .qr-preview { align-self: center; }
}
