* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  -webkit-font-smoothing: antialiased;
}

header {
  background: white;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #e5e5e7;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}
.auth-status {
  font-size: 0.85rem;
  color: #666;
}
.auth-status .clear-token {
  cursor: pointer;
  color: #0066cc;
  text-decoration: underline;
  margin-left: 0.5rem;
}

.stats {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: stretch;
}
.stat {
  background: #fafbfd;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  min-width: 100px;
  border: 1px solid #e5e5e7;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-primary {
  background: linear-gradient(135deg, #eaf2ff, #f4f8ff);
  border-color: #cfdcef;
}
.stat-num {
  font-size: 1.45rem;
  font-weight: 700;
  color: #0066cc;
  line-height: 1.15;
}
.stat-denom {
  font-size: 0.85rem;
  font-weight: 500;
  color: #888;
  margin-left: 2px;
}
.stat-label {
  font-size: 0.78rem;
  color: #666;
  margin-top: 0.2rem;
  font-weight: 500;
}
.plat-stat { min-width: 88px; padding: 0.6rem 0.8rem; }
.plat-stat .stat-num { color: var(--brand); }
.plat-stat .stat-label { color: var(--brand); opacity: 0.85; font-weight: 600; }
.tiktok-stat { --brand: #fe2c55; }
.ig-stat     { --brand: #c13584; }
.fb-stat     { --brand: #1877f2; }
.yt-stat     { --brand: #ff0000; }

.last-sync {
  align-self: center;
  font-size: 0.78rem;
  color: #999;
  margin-left: auto;
  padding: 0 0.5rem;
}

main {
  padding: 1.25rem 2rem 3rem;
}

.toolbar {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar button {
  padding: 0.5rem 1rem;
  border: 1px solid #d2d2d7;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.toolbar button:hover { background: #f0f0f0; }
.toolbar .sync-btn {
  background: #0066cc;
  color: white;
  border-color: #0066cc;
}
.toolbar .sync-btn:hover { background: #0055aa; }
.toolbar .sync-btn:disabled {
  background: #99c0e6;
  border-color: #99c0e6;
  cursor: wait;
}
.toolbar .tt-btn { background: #fe2c55; border-color: #fe2c55; }
.toolbar .tt-btn:hover { background: #d62449; }
.toolbar .tt-btn:disabled { background: #fcb1c2; border-color: #fcb1c2; }

/* TikTok inline edit cells */
.platform-cell.tiktok-col .metrics input {
  width: 64px;
  font-size: 0.78rem;
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  font-family: inherit;
  color: #555;
}
.platform-cell.tiktok-col .metrics input:hover {
  border-color: #fe2c55;
  background: white;
}
.platform-cell.tiktok-col .metrics input:focus {
  outline: none;
  border-color: #fe2c55;
  background: #fff5f7;
  color: #1d1d1f;
}
.platform-cell.tiktok-col .metrics input.saving { background: #fff8b3; }
.platform-cell.tiktok-col .metrics input.saved { background: #d4edda; }
.platform-cell.tiktok-col .metrics input.error { background: #f8d7da; }
.platform-cell.tiktok-col .metrics .inline-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 2px;
}
.platform-cell.tiktok-col .metrics .inline-row .icon {
  width: 14px;
  flex-shrink: 0;
}

.sync-report {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid #cde4f8;
  background: #f0f7ff;
  font-size: 0.88rem;
  line-height: 1.6;
}
.sync-report.hidden { display: none; }
.sync-report.error {
  background: #fff0f0;
  border-color: #ecc;
  color: #a33;
}
.sync-report .close-x {
  float: right;
  cursor: pointer;
  color: #888;
  margin-left: 1rem;
}
.sync-report ul { margin: 0.3rem 0; padding-left: 1.2rem; }
.sync-report li { margin: 2px 0; }
.toolbar .filter {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.toolbar .hint {
  margin-left: auto;
  font-size: 0.85rem;
  color: #999;
}

.table-wrap {
  background: white;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
  border: 1px solid #e5e5e7;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th {
  background: #fafafc;
  padding: 0.75rem 0.6rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  border-bottom: 2px solid #e5e5e7;
  color: #555;
}
td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #f0f0f2;
  vertical-align: top;
}
tbody tr:hover { background: #fafafc; }
.col-num { width: 40px; text-align: center; }
.col-title { min-width: 140px; }
.col-drive { width: 90px; }
.col-plat { min-width: 130px; }
.tiktok-col  { color: #fe2c55; }
.ig-col      { color: #c13584; }
.fb-col      { color: #1877f2; }
.yt-col      { color: #ff0000; }

.num { color: #999; font-weight: 600; text-align: center; }
.title { font-weight: 500; }
.col-source { width: 80px; }
.source-cell { text-align: center; }
.source-tag {
  display: inline-block;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}
.source-zhibai   { background: #ffe1e8; color: #c62853; }
.source-siliq    { background: #e1efff; color: #1856b0; }
.recorded-date {
  font-size: 0.7rem;
  color: #999;
  margin-left: 0.3rem;
}
.toolbar select {
  margin-left: 0.3rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid #d2d2d7;
  border-radius: 5px;
  font-size: 0.85rem;
  font-family: inherit;
  background: white;
}
.drive a { color: #0066cc; text-decoration: none; font-size: 0.85rem; }
.drive a:hover { text-decoration: underline; }

.platform-cell {
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
  border-left: 1px solid #f0f0f2;
}
.platform-cell:hover { background: #eef5ff; }
.platform-cell.empty {
  opacity: 0.55;
}

.cell-top {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}
.status-no { opacity: 0.4; }
.review-flag {
  background: #fff3cd;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 0.85rem;
}
.link {
  margin-left: auto;
  font-size: 0.85rem;
  text-decoration: none;
  color: #0066cc;
}
.link:hover { text-decoration: underline; }

.metrics {
  display: flex;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: #555;
}
.metrics span { white-space: nowrap; }

.platform-title {
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 130px;
}

.last-updated {
  font-size: 0.7rem;
  color: #aaa;
  margin-top: 0.15rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
  background: white;
  padding: 1.75rem;
  border-radius: 12px;
  min-width: 380px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-content h2 {
  margin: 0 0 1.25rem 0;
  font-size: 1.15rem;
}

#edit-form label {
  display: block;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: #555;
}
#edit-form .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: #1d1d1f;
}
#edit-form input[type=text],
#edit-form input[type=url],
#edit-form input[type=number] {
  display: block;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #d2d2d7;
  border-radius: 6px;
  font-size: 0.95rem;
  margin-top: 0.3rem;
  font-family: inherit;
}
#edit-form input:focus {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}
.metric-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
}

.url-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
  margin-top: 0.3rem;
}
.url-row input { margin-top: 0 !important; }
.url-row .url-open {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  border: 1px solid #d2d2d7;
  border-radius: 6px;
  text-decoration: none;
  color: #0066cc;
  font-size: 1.05rem;
  background: white;
}
.url-row .url-open:hover { background: #eef5ff; }
.url-row .url-open.disabled {
  pointer-events: none;
  opacity: 0.3;
  color: #aaa;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1.5rem;
}
.modal-actions .spacer { flex: 1; }
.modal-actions button {
  padding: 0.55rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  border: 1px solid #d2d2d7;
  background: white;
  font-family: inherit;
}
.modal-actions .primary {
  background: #0066cc;
  color: white;
  border-color: #0066cc;
}
.modal-actions .primary:hover { background: #0055aa; }
.modal-actions .danger {
  color: #c33;
  border-color: #ecc;
}
.modal-actions .danger:hover { background: #fee; }

@media (max-width: 768px) {
  header, main { padding-left: 1rem; padding-right: 1rem; }
  .col-plat { min-width: 90px; }
  .metrics { flex-direction: column; gap: 2px; }
}
