: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;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

#login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.06);
}
.login-card h1 { margin: 8px 0; font-size: 1.75rem; }
.login-card label { display: block; margin: 16px 0 6px; font-size: 0.875rem; font-weight: 600; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
}
.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.error { color: var(--red); font-size: 0.875rem; margin-top: 12px; }

.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; }

#app {
  width: 100%;
  max-width: none;
  margin: 0;
  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-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-primary, .btn-ghost, .btn-small {
  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;
}
.btn-small {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

.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 input,
.period-bar select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  min-width: 120px;
  background: var(--surface);
  color: var(--text);
}
.period-actions {
  display: flex;
  align-items: flex-end;
}
.month-hint {
  margin: -8px 0 16px;
  font-size: 0.85rem;
}

.section-title {
  margin: 28px 0 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.sales-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.mkt-costs-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top: 3px solid var(--accent);
  padding: 20px 22px;
  margin-bottom: 8px;
}

.mkt-costs-panel .metrics-table .metric-input {
  max-width: 220px;
  margin-left: auto;
}

.mkt-summary-row td {
  background: #fffbeb;
  border-top: 2px solid var(--border);
}

.mkt-summary-row:first-of-type td {
  border-top: 2px solid rgba(217, 119, 6, 0.25);
}

.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;
}

.sales-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;
}

.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;
}

.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;
}

.metric-input {
  width: 100%;
  max-width: 180px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  text-align: right;
}

.metric-input-sm {
  max-width: 72px;
  display: inline-block;
}

.metric-ok { color: var(--green); font-weight: 700; }
.metric-warn { color: var(--yellow); font-weight: 700; }
.metric-bad { color: var(--red); font-weight: 700; }

.sales-empty {
  grid-column: 1 / -1;
  padding: 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

#goals-company,
#goals-personal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  align-items: start;
}

.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 0;
}
.goal-card-revenue {
  grid-column: 1 / -1;
}
.goal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.goal-head input.title-input {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text);
}
.goal-head input.title-input:focus { outline: 2px solid rgba(217, 119, 6, 0.3); border-radius: 4px; }
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 8px;
}
.goal-head-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.source-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #0369a1;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}
.goal-card-nhanh input.readonly,
.goal-card-derived input.readonly {
  background: #f1f5f9;
  color: var(--muted);
  cursor: default;
}
.goal-card-derived {
  border-style: dashed;
  background: #fafbfc;
}
.source-badge.derived {
  color: #7c3aed;
  background: #f3e8ff;
  border-color: #ddd6fe;
}
.status-dot.green { background: var(--green); }
.status-dot.yellow { background: var(--yellow); }
.status-dot.red { background: var(--red); }

.revenue-def {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 0.8125rem;
}

.revenue-forecast {
  margin: 12px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 0.85rem;
  line-height: 1.5;
}
.revenue-forecast-on_track { border-color: #bbf7d0; background: #f0fdf4; }
.revenue-forecast-at_risk { border-color: #fde68a; background: #fffbeb; }
.revenue-forecast-behind { border-color: #fecaca; background: #fef2f2; }
.revenue-forecast-muted { background: #f8fafc; }
.forecast-title {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.forecast-line { margin: 0 0 4px; }
.forecast-line:last-child { margin-bottom: 0; }
.forecast-ok { color: var(--green); font-weight: 600; }
.forecast-warn { color: var(--yellow); font-weight: 600; }
.forecast-bad { color: var(--red); font-weight: 600; }

.progress-wrap { margin: 10px 0; }
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.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;
  transition: width 0.3s ease;
}

.goal-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.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-size: 0.9rem;
  font-family: inherit;
}
.goal-fields textarea { min-height: 52px; resize: vertical; }

.card-actions { margin-top: 12px; text-align: right; }
.card-actions button {
  border: none;
  background: transparent;
  color: var(--red);
  font-size: 0.8rem;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.875rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  z-index: 100;
}

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

@media (max-width: 600px) {
  .topbar { flex-direction: column; }
  .tabs { flex-direction: column; }
  #goals-company,
  #goals-personal {
    grid-template-columns: 1fr;
  }
  .metrics-table { font-size: 0.8rem; }
  .col-metric { width: auto; }
}

.tasks-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.tasks-header h2 {
  margin: 0;
  font-size: 1.25rem;
}
.tasks-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tasks-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  font-size: 0.875rem;
}
.tasks-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
.tasks-stat.warn { color: var(--red); border-color: rgba(220, 38, 38, 0.25); }
.tasks-kanban {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  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;
  min-height: 120px;
}
.tasks-column-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 0.9rem;
}
.tasks-column-count {
  color: var(--muted);
  font-weight: 600;
  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;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.task-card:hover {
  border-color: rgba(217, 119, 6, 0.35);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
.task-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.35;
  margin-bottom: 8px;
}
.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.task-label {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
}
.task-label.green { background: #16a34a; }
.task-label.yellow { background: #ca8a04; }
.task-label.orange { background: #ea580c; }
.task-label.red { background: #dc2626; }
.task-label.blue { background: #2563eb; }
.task-label.purple { background: #7c3aed; }
.task-label.sky { background: #0284c7; }
.task-label.lime { background: #65a30d; }
.task-label.pink { background: #db2777; }
.task-label.black { background: #334155; }
.task-due.overdue { color: var(--red); font-weight: 700; }
.task-check {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}
.task-check > span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}
.tasks-empty {
  color: var(--muted);
  font-size: 0.875rem;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}