/* ───────────────────────────────────────
   TikTok CRM — Base styles
   Brand color via CSS variable --brand-color
   ─────────────────────────────────────── */

:root {
  --brand-color: #c8102e;
  --brand-color-dark: #a30c25;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #ea580c;
  --danger: #dc2626;
  --info: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial,
               "Sukhumvit Set", "Kanit", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--brand-color); text-decoration: none; }

.app-header {
  background: var(--brand-color);
  color: #fff;
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 10;
}
.app-header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.app-header .badge { background: rgba(255,255,255,0.18); padding: 4px 10px; border-radius: 16px; font-size: 13px; }

.app-main { padding: 16px; padding-bottom: 80px; max-width: 720px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
.card-subtle { color: var(--text-muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand-color); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  border: none; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: opacity 0.15s, transform 0.05s;
  text-align: center;
}
.btn:hover { opacity: 0.92; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { display: flex; width: 100%; }
.btn-outline {
  background: transparent;
  color: var(--brand-color);
  border: 1.5px solid var(--brand-color);
}
.btn-success { background: var(--success); }
.btn-danger  { background: var(--danger); }
.btn-warning { background: var(--warning); }
.btn-ghost   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: 6px 12px; font-size: 13px; }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-color);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.1);
}
.textarea { min-height: 80px; resize: vertical; }

.form-row { margin-bottom: 14px; }
.form-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; display: block; }

.list { list-style: none; padding: 0; margin: 0; }
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  background: var(--border);
  color: var(--text);
}
.badge-success { background: #dcfce7; color: var(--success); }
.badge-warning { background: #fed7aa; color: var(--warning); }
.badge-danger  { background: #fecaca; color: var(--danger); }
.badge-info    { background: #dbeafe; color: var(--info); }
.badge-tier-1  { background: #e0e7ff; color: #4338ca; }
.badge-tier-2  { background: #fef3c7; color: #92400e; }

.row { display: flex; gap: 8px; align-items: center; }
.row-between { justify-content: space-between; }
.muted { color: var(--text-muted); font-size: 13px; }

.tabs {
  display: flex; gap: 4px; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  padding-bottom: 0;
}
.tab {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 14px;
  white-space: nowrap;
}
.tab.active { color: var(--brand-color); border-color: var(--brand-color); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%) translateY(60px);
  background: #1e293b; color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0; transition: all 0.3s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-error   { background: var(--danger); }
.toast-success { background: var(--success); }

#global-loading {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.7); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center;
  z-index: 999;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}

.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; gap: 8px;
  z-index: 50;
}

.fab {
  position: fixed; bottom: 80px; right: 16px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--brand-color); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  cursor: pointer; font-size: 24px;
  border: none;
  z-index: 50;
}

.dialog {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 100; padding: 16px;
}
.dialog.show { display: flex; }
.dialog-content {
  background: #fff; border-radius: 16px;
  padding: 20px;
  max-width: 480px; width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.dialog-title { font-size: 17px; font-weight: 600; margin: 0 0 10px; }

@media (min-width: 480px) {
  .dialog { align-items: center; }
}

.preview-img {
  display: block; width: 100%; max-width: 280px;
  border-radius: 8px;
  margin-top: 8px;
}

table.simple {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.simple th, table.simple td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.simple th { background: #f1f5f9; font-weight: 600; }

.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin: 8px 0;
}
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--brand-color); }
.stat-label { font-size: 12px; color: var(--text-muted); }
