:root {
  --accent: #d97706;
  --accent-dark: #b45309;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, sans-serif;
  --page-pad-x: clamp(20px, 3vw, 48px);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
.hidden { display: none !important; }
.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.muted { color: var(--muted); font-size: 0.875rem; }
.error { color: var(--red); font-size: 0.875rem; }

#app {
  padding: 24px var(--page-pad-x) 48px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.topbar h1 { margin: 4px 0 0; font-size: 1.5rem; }
.topbar-sub { margin: 4px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mode-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
}
.mode-badge.mode-edit {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}
.user-badge {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.btn-primary, .btn-ghost {
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.875rem;
}
.btn-primary {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--accent); color: #fff; }
.panel { display: none; }
.panel.active { display: block; }

.period-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}
.period-bar select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.period-label { font-weight: 600; }
.section-title {
  margin: 28px 0 14px;
  font-size: 1rem;
  font-weight: 700;
}

.month-hint { margin: -8px 0 16px; font-size: 0.85rem; }

.sales-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.sales-panel, .mkt-costs-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.sales-panel-gross { border-top: 3px solid #7c3aed; }
.sales-panel-revenue { border-top: 3px solid #0369a1; }
.mkt-costs-panel {
  grid-column: 1 / -1;
  border-top: 3px solid var(--accent);
  margin-bottom: 8px;
}
.sales-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.sales-title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.sales-sub { margin: 4px 0 0; font-size: 0.82rem; }
.sales-panel-meta { display: flex; align-items: center; gap: 8px; }
.sales-progress {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.sales-forecast { margin: 10px 0 0; font-size: 0.82rem; }
.sales-empty {
  grid-column: 1 / -1;
  padding: 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.source-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: #0369a1;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.875rem;
}
.metrics-table thead th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
.metrics-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.metrics-table tbody tr:last-child td { border-bottom: none; }
.metrics-table tbody tr:hover td { background: #fafbfc; }
.col-stt { width: 48px; text-align: center; color: var(--muted); font-weight: 600; }
.col-metric { width: 42%; font-weight: 600; }
.col-value { text-align: right; font-variant-numeric: tabular-nums; }
.mkt-api-value { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.mkt-sync-note { margin-top: 4px; font-size: 0.78rem; text-align: right; }
.mkt-summary-row td { background: #fffbeb; border-top: 2px solid var(--border); }
.metric-ok { color: var(--green); font-weight: 700; }
.metric-warn { color: var(--yellow); font-weight: 700; }
.metric-bad { color: var(--red); font-weight: 700; }

.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f59e0b);
  border-radius: 999px;
}
.progress-fill.green { background: var(--green); }
.progress-fill.yellow { background: var(--yellow); }
.progress-fill.red { background: var(--red); }

.media-schedule-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top: 3px solid #7c3aed;
  padding: 20px 22px;
  margin-bottom: 24px;
}
.media-schedule-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.media-section-title { margin: 0 0 4px; }
.media-section-sub { margin: 0; max-width: 52ch; }
.media-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.media-stat {
  font-size: 0.8125rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}
.media-stat-active { background: #fffbeb; border-color: #fde68a; }
.media-stat-done { background: #f0fdf4; border-color: #bbf7d0; }
.media-stat-cost { background: #faf5ff; border-color: #e9d5ff; }
.media-open-link { color: #7c3aed; text-decoration: none; font-weight: 700; }
.media-empty td { text-align: center; color: var(--muted); padding: 28px 16px; }
.media-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.media-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.media-table-edit { min-width: 1280px; }
.media-table th, .media-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.media-table th {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
}
.media-input, .media-select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
}
.status-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
}
.status-pill.status-green { background: #f0fdf4; color: #166534; }
.status-pill.status-yellow { background: #fffbeb; color: #a16207; }
.status-pill.status-red { background: #fef2f2; color: #b91c1c; }
.status-pill.status-muted { background: #f1f5f9; color: var(--muted); }
.note-cell { max-width: 180px; font-size: 0.82rem; color: var(--muted); }

.goals-grid, #goals-company {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  align-items: start;
}
.goal-title { margin: 0; font-size: 1.05rem; font-weight: 700; }
.goal-read-val { font-weight: 600; }
.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.goal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.goal-head h4 { margin: 0; font-size: 1rem; }
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.green { background: var(--green); }
.status-dot.yellow { background: var(--yellow); }
.status-dot.red { background: var(--red); }
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.goal-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.goal-note-wrap { grid-column: 1 / -1; }
.goal-fields label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.goal-fields input, .goal-fields textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}
.goal-note { margin: 0; font-size: 0.875rem; }

.tasks-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.tasks-header h2 { margin: 0; font-size: 1.25rem; }
.tasks-actions { display: flex; gap: 10px; }
.tasks-stats { display: flex; gap: 12px; margin-bottom: 20px; }
.tasks-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.875rem;
}
.tasks-stat.warn { color: var(--red); }
.tasks-kanban {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  align-items: flex-start;
}
.tasks-column {
  flex: 0 0 min(300px, 85vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.tasks-column-head {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  margin-bottom: 12px;
}
.tasks-column-count { color: var(--muted); font-size: 0.8rem; }
.task-card {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
}
.task-card:hover { border-color: rgba(217, 119, 6, 0.35); }
.task-card-title { font-weight: 600; margin-bottom: 6px; }
.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}
.task-label {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0369a1;
}
.task-due.overdue { color: var(--red); font-weight: 700; }
.task-check {
  height: 4px;
  background: #e2e8f0;
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}
.task-check span {
  display: block;
  height: 100%;
  background: var(--green);
}
.tasks-empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
}
.modal-card h2 { margin: 8px 0; font-size: 1.35rem; }
.modal-card label {
  display: block;
  margin: 16px 0 6px;
  font-size: 0.875rem;
  font-weight: 600;
}
.modal-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}
.modal-card button[type="submit"] {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.modal-close {
  margin-top: 12px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.875rem;
  z-index: 300;
}

@media (max-width: 900px) {
  .sales-dashboard { grid-template-columns: 1fr; }
  .tabs { flex-direction: column; }
}