:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d9dee7;
  --facebook: #1877f2;
  --instagram: #c13584;
  --teal: #0f766e;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  color: #0b1f3a;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  font-size: 58px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(24, 119, 242, 0.12);
}

h2 {
  font-size: 20px;
}

h2 {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.sync-status {
  max-width: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.sync-status[data-mode="cloud"] {
  color: #027a48;
  border-color: #abefc6;
  background: #ecfdf3;
}

.sync-status[data-mode="error"] {
  color: var(--danger);
  border-color: #fecdca;
  background: #fffbfa;
}

.entry-panel,
.filter-panel,
.history-panel,
.chart-panel,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
}

.entry-panel {
  padding: 14px;
  margin-bottom: 14px;
}

.entry-form {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input {
  width: 100%;
  height: 42px;
  border: 1px solid #cfd6e2;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.filter-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  margin-bottom: 16px;
}

.range-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  background: #f2f4f7;
}

.range-tab {
  min-height: 36px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
}

.range-tab:hover,
.range-tab.active {
  background: #ffffff;
  color: var(--ink);
  border-color: #d0d5dd;
}

.custom-range {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  opacity: 0.45;
}

.custom-range.active {
  opacity: 1;
}

button:hover {
  background: #344054;
}

button.danger {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #fecdca;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 16px 0;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 132px;
  padding: 18px;
}

.metric-label,
.metric small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  font-size: 38px;
  line-height: 1;
}

.metric.facebook {
  border-top: 5px solid var(--facebook);
}

.metric.instagram {
  border-top: 5px solid var(--instagram);
}

.metric.total {
  border-top: 5px solid var(--teal);
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-panel {
  min-width: 0;
  padding: 20px;
}

.facebook-chart-panel {
  border-color: #84c5ff;
  background: #eff8ff;
}

.facebook-chart-panel h2,
.facebook-chart-panel .chart-heading span {
  color: #0b4a8b;
}

.instagram-chart-panel {
  border-color: #f0a8d2;
  background: #fff5fb;
}

.instagram-chart-panel h2,
.instagram-chart-panel .chart-heading span {
  color: #8f1d5b;
}

.chart-heading,
.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.chart-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.platform-logo {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.facebook-logo {
  background: #1877f2;
  font-family: Arial, sans-serif;
}

.instagram-logo {
  position: relative;
  background: linear-gradient(135deg, #f58529, #dd2a7b 48%, #8134af);
}

.instagram-logo::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff;
  border-radius: 5px;
}

.instagram-logo::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffffff;
}

canvas {
  display: block;
  width: 100%;
  height: 380px;
  border: 1px solid #e4e7ec;
  border-radius: 8px;
}

.chart-canvas-wrap {
  position: relative;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 3px;
  min-width: 140px;
  border: 1px solid #101828;
  border-radius: 8px;
  background: #101828;
  color: #ffffff;
  padding: 9px 10px;
  font-size: 12px;
  box-shadow: 0 14px 26px rgba(16, 24, 40, 0.22);
  pointer-events: none;
}

.chart-tooltip strong {
  font-size: 13px;
}

.chart-tooltip span {
  color: #d0d5dd;
}

.history-panel {
  padding: 18px;
}

.history-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.history-actions button {
  min-height: 40px;
  background: #eef4ff;
  color: #1849a9;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  border-bottom: 1px solid #edf0f5;
  padding: 13px 10px;
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.positive {
  color: #027a48;
  font-weight: 800;
}

.negative {
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 900px) {
  h1 {
    font-size: 44px;
  }

  .topbar,
  .filter-panel,
  .chart-heading,
  .history-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .sync-status,
  .chart-heading span {
    max-width: none;
    text-align: left;
  }

  .entry-form,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .custom-range {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 20px 0;
  }

  h1 {
    font-size: 34px;
  }

  .entry-panel,
  .filter-panel,
  .history-panel,
  .chart-panel,
  .metric {
    padding: 12px;
  }

  .entry-form {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .entry-form label:first-child,
  .entry-form button {
    grid-column: 1 / -1;
  }

  label {
    gap: 5px;
    font-size: 12px;
  }

  input {
    height: 38px;
    padding: 0 10px;
  }

  button {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
  }

  .range-tabs,
  .custom-range {
    width: 100%;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .custom-range {
    grid-template-columns: 1fr 1fr;
  }

  canvas {
    height: 340px;
  }
}
