/* ─── Reset & Base ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  min-height: 100dvh;
}

/* ─── Layout ───────────────────────────────────────────────────────────── */

.app { max-width: 960px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* ─── Header ───────────────────────────────────────────────────────────── */

.header {
  background: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e5e5e5;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header h1 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Month selector ──────────────────────────────────────────────────── */

.month-selector {
  display: flex; align-items: center; gap: 8px;
}
.month-selector input[type="month"] {
  padding: 6px 10px; border: 1px solid #d1d1d6; border-radius: 8px;
  font-size: 13px; font-family: inherit;
}

/* ─── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid #d1d1d6; border-radius: 8px;
  background: #fff; color: #1d1d1f; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn:hover { background: #f0f0f2; }
.btn-primary { background: #007aff; color: #fff; border-color: #007aff; }
.btn-primary:hover { background: #0066d6; }
.btn-danger { color: #ff3b30; border-color: #ff3b30; }
.btn-danger:hover { background: #fff5f5; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; border: none; background: transparent; cursor: pointer; border-radius: 6px; font-size: 16px; }
.btn-icon:hover { background: #f0f0f2; }

/* ─── Content area ─────────────────────────────────────────────────────── */

.content { flex: 1; padding: 16px 20px; }

/* ─── Dashboard table ──────────────────────────────────────────────────── */

.dashboard-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.dashboard-table th {
  background: #f9f9fb; padding: 10px 12px; text-align: left;
  font-size: 12px; font-weight: 600; color: #6e6e73; border-bottom: 1px solid #e5e5e5;
  white-space: nowrap;
}
.dashboard-table td {
  padding: 10px 12px; border-bottom: 1px solid #f0f0f2; font-size: 13px;
  white-space: nowrap;
}
.dashboard-table tr:last-child td { border-bottom: none; }
.dashboard-table tr:hover td { background: #f9f9fb; }
.dashboard-table .clickable { cursor: pointer; }

/* ─── Progress bar ─────────────────────────────────────────────────────── */

.progress-bar {
  width: 100px; height: 8px; background: #e5e5e5; border-radius: 4px; overflow: hidden;
  display: inline-block; vertical-align: middle; margin-right: 6px;
}
.progress-bar .fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-bar .fill.green { background: #34c759; }
.progress-bar .fill.yellow { background: #ff9f0a; }
.progress-bar .fill.red { background: #ff3b30; }
.progress-bar .fill.blue { background: #007aff; }

/* ─── Expected rate marker ─────────────────────────────────────────────── */

.progress-bar { position: relative; }
.progress-bar .expected-marker {
  position: absolute; top: -2px; bottom: -2px; width: 2px;
  background: #1d1d1f; opacity: 0.4;
}

/* ─── Platform badge ───────────────────────────────────────────────────── */

.platform-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
}
.platform-badge.tiktok_promote { background: #ffe0ec; color: #fe2c55; }
.platform-badge.meta { background: #e7f0ff; color: #1877f2; }
.platform-badge.tiktok { background: #f0f0f0; color: #000; }
.platform-badge.google { background: #e8f5e9; color: #1a73e8; }
.platform-badge.yahoo { background: #fff3e0; color: #ff0033; }
.platform-badge.line { background: #e8f5e9; color: #06c755; }
.platform-badge.x { background: #f0f0f0; color: #000; }

/* ─── Status badge ─────────────────────────────────────────────────────── */

.status-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: 10px;
}
.status-badge.on_track { background: #e8f5e9; color: #1b8a2e; }
.status-badge.behind { background: #ffebee; color: #d32f2f; }
.status-badge.ahead { background: #e3f2fd; color: #1565c0; }
.status-badge.no_budget { background: #f5f5f5; color: #9e9e9e; }

/* ─── Cards ────────────────────────────────────────────────────────────── */

.card {
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04); margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* ─── Form ─────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #6e6e73; margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid #d1d1d6; border-radius: 8px;
  font-size: 14px; font-family: inherit; transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
select.form-input { appearance: auto; }
textarea.form-input { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* ─── Summary stats ────────────────────────────────────────────────────── */

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat-card {
  background: #f9f9fb; border-radius: 10px; padding: 14px;
}
.stat-card .label { font-size: 12px; color: #6e6e73; margin-bottom: 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; }
.stat-card .sub { font-size: 11px; color: #6e6e73; margin-top: 2px; }

/* ─── Tabs ─────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 1px solid #e5e5e5; }
.tab {
  padding: 10px 16px; font-size: 13px; font-weight: 500; color: #6e6e73;
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s;
}
.tab:hover { color: #1d1d1f; }
.tab.active { color: #007aff; border-bottom-color: #007aff; }

/* ─── Empty state ──────────────────────────────────────────────────────── */

.empty-state { text-align: center; padding: 60px 20px; color: #6e6e73; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ─── Modal ────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; animation: fadeIn 0.15s;
}
.modal {
  background: #fff; border-radius: 16px 16px 0 0; width: 100%; max-width: 640px;
  max-height: 90dvh; overflow-y: auto; padding: 24px 20px; animation: slideUp 0.2s ease-out;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; padding-top: 16px; border-top: 1px solid #e5e5e5; }

/* ─── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1d1d1f; color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 13px; z-index: 200; animation: fadeIn 0.2s; pointer-events: none;
}

/* ─── Loading / Spinner ────────────────────────────────────────────────── */

.loading { text-align: center; padding: 40px; color: #6e6e73; }
.spinner {
  display: inline-block; width: 24px; height: 24px;
  border: 3px solid #e5e5e5; border-top-color: #007aff; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Back button ──────────────────────────────────────────────────────── */

.back-btn { font-size: 14px; cursor: pointer; color: #007aff; background: none; border: none; display: flex; align-items: center; gap: 4px; }
.back-btn:hover { text-decoration: underline; }

/* ─── Number formatting ────────────────────────────────────────────────── */

.num-positive { color: #34c759; }
.num-negative { color: #ff3b30; }

/* ─── URL cell ─────────────────────────────────────────────────────────── */

.url-cell { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a { color: #007aff; text-decoration: none; }
.url-cell a:hover { text-decoration: underline; }

/* ─── Search box ──────────────────────────────────────────────────────── */

.search-box { margin-bottom: 16px; }
.search-box .form-input { max-width: 320px; }

/* ─── Client grid ─────────────────────────────────────────────────────── */

.client-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.client-card {
  background: #fff; border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04); cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
  border: 2px solid transparent;
}
.client-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); transform: translateY(-1px); }
.client-card.no-data { opacity: 0.65; }
.client-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.client-card-name { font-size: 15px; font-weight: 700; }
.client-card-stats { display: flex; gap: 16px; margin-bottom: 10px; font-size: 13px; }
.client-card-stat { display: flex; flex-direction: column; }
.client-card-label { font-size: 11px; color: #6e6e73; }
.client-card-progress { display: flex; align-items: center; gap: 8px; }
.client-card-progress .progress-bar { flex: 1; }
.client-card-rate { font-size: 13px; font-weight: 600; min-width: 40px; text-align: right; }
.client-card-empty { font-size: 12px; color: #aeaeb2; }

/* ─── Settings table ──────────────────────────────────────────────────── */

.settings-table td { padding: 8px 12px; }
.settings-checkbox {
  display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px;
}
.settings-checkbox input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: #007aff; cursor: pointer;
}

/* ─── Timeline ────────────────────────────────────────────────────────── */

.tl-container { overflow-x: auto; position: relative; }
.tl-header-row { display: flex; border-bottom: 1px solid #e5e5e5; position: sticky; top: 0; background: #fff; z-index: 2; }
.tl-row { display: flex; border-bottom: 1px solid #f0f0f2; }
.tl-row:hover { background: #f9f9fb; }
.tl-label {
  min-width: 160px; max-width: 160px; padding: 10px 12px; font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0;
  border-right: 1px solid #e5e5e5;
}
.tl-track { position: relative; height: 40px; flex-shrink: 0; }
.tl-header-track { height: 28px; }
.tl-bar {
  position: absolute; top: 8px; height: 24px; border-radius: 4px; min-width: 4px;
  display: flex; align-items: center; justify-content: center; cursor: default;
}
.tl-bar-text { font-size: 10px; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; }
.tl-month-line {
  position: absolute; top: 0; bottom: 0; width: 1px; background: #e5e5e5; z-index: 1;
}
.tl-month-label {
  position: absolute; top: -18px; left: 2px; font-size: 10px; color: #6e6e73; white-space: nowrap;
}
.tl-header-month {
  position: absolute; top: 6px; font-size: 11px; color: #6e6e73; font-weight: 500; white-space: nowrap;
}
.tl-today {
  position: absolute; top: 0; bottom: 0; width: 2px; background: #ff3b30; z-index: 2;
}
.tl-today-label {
  position: absolute; top: -16px; left: -8px; font-size: 9px; color: #ff3b30; font-weight: 600; white-space: nowrap;
}

/* Platform background colors for timeline bars */
.platform-bg-tiktok_promote { background: #fe2c55; }
.platform-bg-meta { background: #1877f2; }
.platform-bg-tiktok { background: #333; }
.platform-bg-google { background: #1a73e8; }
.platform-bg-yahoo { background: #ff0033; }
.platform-bg-line { background: #06c755; }
.platform-bg-x { background: #333; }

/* ─── Animations ───────────────────────────────────────────────────────── */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ───────────────────────────────────────────────────────── */

@media (min-width: 641px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; max-height: 80dvh; }
}

@media (max-width: 600px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; gap: 0; }
  .dashboard-table { font-size: 12px; }
  .dashboard-table th, .dashboard-table td { padding: 8px 6px; }
  .progress-bar { width: 60px; }
  .client-grid { grid-template-columns: 1fr; }
  .search-box .form-input { max-width: 100%; }
}
