:root {
  color-scheme: light;
  --ink: #24364b;
  --muted: #607087;
  --paper: #f4f7fb;
  --panel: #ffffff;
  --line: #d9e2ec;
  --line-strong: #c6d3e1;
  --brand: #2f8fb3;
  --brand-2: #ff7a59;
  --brand-3: #33475b;
  --danger: #c53f3f;
  --warning: #8a6500;
  --success: #217a6b;
  --sidebar: #24364b;
  --sidebar-soft: #33475b;
  --shadow: 0 1px 2px rgba(24, 42, 62, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-size: 13px;
  margin: 0;
  min-height: 100vh;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #26384d;
  color: #d8e1eb;
  display: flex;
  gap: 1rem;
  height: 34px;
  justify-content: space-between;
  left: 0;
  padding: 0 12px;
  position: sticky;
  right: 0;
  top: 0;
  z-index: 20;
}

.topbar::before {
  color: var(--brand-2);
  content: "⌁";
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.topbar-search {
  background: #3d526d;
  border-radius: 5px;
  color: #dfe7ef;
  flex: 0 1 420px;
  padding: 5px 12px;
}

.topbar-search::before {
  content: "⌕ ";
  opacity: 0.9;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 18px;
  font-size: 12px;
}

.shell {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  min-height: calc(100vh - 34px);
}

.sidebar {
  background: var(--sidebar);
  color: #d8e1eb;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 34px);
  padding: 14px 8px;
  position: sticky;
  top: 34px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 10px;
  padding: 2px 8px 14px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: transparent;
  color: var(--brand-2);
  display: inline-flex;
  font-size: 22px;
  font-weight: 800;
  height: 24px;
  justify-content: center;
  letter-spacing: -0.05em;
  width: 24px;
}

.brand strong {
  color: #fff;
  display: block;
  font-size: 14px;
  line-height: 1.1;
}

.brand small {
  color: #b7c4d2;
  display: block;
  font-size: 11px;
  margin-top: 2px;
}

nav {
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  display: grid;
  gap: 2px;
  padding-top: 10px;
}

nav a,
.ghost {
  border: 0;
  border-radius: 4px;
  color: #d8e1eb;
  font-size: 13px;
  padding: 8px 10px;
  text-align: left;
  text-decoration: none;
}

nav a.active,
nav a:hover,
.ghost:hover {
  background: #516987;
  color: white;
}

.ghost {
  background: transparent;
  cursor: pointer;
  margin-top: auto;
}

main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 12px 16px 20px;
}

.hero {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
  padding: 10px 12px;
}

h1 {
  color: #24364b;
  font-size: 18px;
  letter-spacing: 0;
  line-height: 1.2;
  margin: 0;
}

h2,
h3 {
  color: #24364b;
  letter-spacing: 0;
  margin: 0;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 14px;
}

p {
  color: var(--muted);
  line-height: 1.35;
  margin: 4px 0 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 10px 12px;
}

.table-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  position: relative;
}

.login-card {
  margin: 8vh auto;
  max-width: 420px;
  padding: 22px;
}

.grid {
  display: grid;
  gap: 10px;
}

.status-card-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.status-panel {
  align-self: start;
}

.status-tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
}

.status-tile small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 600;
}

.status-tile .metric {
  margin-top: 2px;
}

.kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two-col {
  grid-template-columns: minmax(0, 1.3fr) minmax(20rem, 0.7fr);
}

.admin-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
}

.card small,
label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 600;
}

.metric {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 4px;
}

.toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.column-picker-wrap {
  position: relative;
}

.column-picker {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(24, 42, 62, 0.16);
  display: grid;
  gap: 2px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 190px;
  z-index: 10;
}

.column-picker-title {
  color: #40566e;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 4px 6px;
  text-transform: uppercase;
}

.column-option {
  align-items: center;
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-size: 12px;
  font-weight: 500;
  gap: 7px;
  padding: 5px 4px;
}

.column-option:hover {
  background: #f5f9fd;
}

.column-option input {
  accent-color: var(--brand);
  height: auto;
  width: auto;
}

.column-option input:disabled {
  cursor: not-allowed;
}

.column-reset {
  margin-top: 6px;
  width: 100%;
}

.toolbar label {
  min-width: 148px;
}

.date-range-control {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.date-range-row {
  align-items: end;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.date-range-row label {
  min-width: 138px;
}

.date-range-row:first-child label {
  min-width: 220px;
}

.date-range-control input[type="date"] {
  min-width: 138px;
}

.filter-panel {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 150px minmax(0, 1fr);
  margin-bottom: 10px;
}

.filter-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(130px, 1fr));
}

.metric-picker {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.metric-select-wrap {
  position: relative;
}

.metric-select-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 170px;
}

.metric-select-button::after {
  color: var(--muted);
  content: "▾";
  font-size: 10px;
}

.metric-options {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(24, 42, 62, 0.16);
  display: grid;
  gap: 2px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 210px;
  z-index: 12;
}

.metric-option {
  align-items: center;
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-size: 12px;
  font-weight: 600;
  gap: 7px;
  padding: 6px 5px;
}

.metric-option:hover {
  background: #f5f9fd;
}

.metric-option input {
  accent-color: var(--brand);
  height: auto;
  width: auto;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--ink);
  height: 30px;
  padding: 5px 8px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(47, 143, 179, 0.12);
  outline: none;
}

.editable-cell {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  min-height: 28px;
  overflow: hidden;
  padding: 4px 6px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.editable-cell:hover,
.editable-cell:focus {
  background: #f5f9fd;
  border-color: var(--line-strong);
  outline: none;
}

.inline-editor-input {
  background: #fff;
  border: 1px solid var(--brand);
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(47, 143, 179, 0.12);
  color: var(--ink);
  height: 30px;
  padding: 5px 8px;
  width: 100%;
}

.floating-menu {
  background: var(--panel);
  border-color: var(--brand);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(24, 42, 62, 0.16);
  display: grid;
  gap: 4px;
  padding: 6px;
  position: absolute;
  z-index: 50;
}

.floating-menu button {
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  height: 28px;
  padding: 4px 8px;
  text-align: left;
}

.floating-menu button:hover {
  background: #f5f9fd;
}

.floating-menu .danger-menu-action {
  color: var(--danger);
}

.floating-menu .danger-menu-action:hover {
  background: rgba(197, 63, 63, 0.08);
}

.access-floating-menu {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
}

button.primary {
  background: var(--brand-2);
  border: 1px solid var(--brand-2);
  border-radius: 3px;
  color: white;
  cursor: pointer;
  font-weight: 700;
  height: 30px;
  padding: 5px 10px;
}

button.secondary {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  height: 30px;
  padding: 5px 9px;
}

.compact-button {
  height: 24px;
  padding: 3px 7px;
}

.danger-button {
  border-color: #e8b9b9;
  color: var(--danger);
}

.text-danger {
  color: var(--danger);
  font-weight: 700;
}

.row-actions,
.client-edit-form {
  align-items: center;
  display: flex;
  gap: 6px;
}

.secondary-link {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--ink);
  display: inline-flex;
  font-weight: 600;
  height: 30px;
  padding: 5px 9px;
  text-decoration: none;
}

.ad-account-edit-form {
  align-items: end;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 10px 0;
}

.ad-account-edit-form button[type="submit"] {
  justify-self: start;
  white-space: nowrap;
}

.ad-account-edit-form label {
  min-width: 0;
}

.ad-account-edit-form:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.add-account-form {
  background: #f8fbfe;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-bottom: 10px;
  padding: 10px;
}

.account-meta {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 3px;
}

.client-edit-form input[name="name"] {
  height: 26px;
  max-width: 280px;
}

.inline-check {
  align-items: center;
  display: inline-flex;
  gap: 5px;
  margin: 0;
}

.inline-check input {
  height: auto;
  width: auto;
}

.company-picker {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
}

.company-picker legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 0 4px;
}

.company-option {
  min-height: 24px;
}

.company-option:has(input:disabled) {
  color: var(--muted);
}

.budget-value {
  background: transparent;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.budget-value:hover {
  color: var(--brand);
  text-decoration: underline;
}

.budget-edit {
  align-items: center;
  display: inline-flex;
  gap: 4px;
}

.budget-edit input[name="budget_amount"] {
  height: 24px;
  padding: 3px 6px;
  width: 82px;
}

.icon-button {
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  height: 22px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 22px;
}

.icon-button.save {
  background: #e3f5ed;
  color: var(--success);
}

.icon-button.cancel {
  background: #fde8e8;
  color: var(--danger);
}

.campaign-link,
.primary-link {
  color: #2f8fb3;
  display: inline-block;
  font-weight: 700;
  text-decoration: none;
}

.campaign-link:hover,
.primary-link:hover {
  text-decoration: underline;
}

table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f5f9fd;
}

th {
  background: #f1f5f9;
  color: #40566e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

.column-header-content {
  align-items: center;
  display: flex;
  gap: 5px;
  min-height: 18px;
  position: relative;
}

.column-sort-button {
  align-items: center;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: inherit;
  gap: 4px;
  height: auto;
  padding: 0;
  text-align: left;
  text-transform: inherit;
}

.column-sort-button:hover {
  color: var(--brand);
}

.sort-indicator {
  color: var(--brand);
  display: inline-block;
  font-size: 11px;
  min-width: 8px;
}

.column-drag-handle {
  color: #7890aa;
  cursor: grab;
  font-size: 12px;
  letter-spacing: -0.18em;
  opacity: 0;
  transform: translateX(-2px);
  transition: opacity 120ms ease;
  user-select: none;
}

th:hover .column-drag-handle {
  opacity: 1;
}

.column-drag-handle:active {
  cursor: grabbing;
}

.column-resize-handle {
  bottom: 0;
  cursor: col-resize;
  opacity: 0;
  position: absolute;
  right: -8px;
  top: 0;
  width: 8px;
}

.column-resize-handle::after {
  background: var(--brand);
  bottom: -6px;
  content: "";
  opacity: 0;
  position: absolute;
  right: 3px;
  top: -6px;
  width: 2px;
}

th:hover .column-resize-handle,
th:hover .column-resize-handle::after,
.column-resize-handle:hover,
.column-resize-handle:hover::after {
  opacity: 1;
}

th.column-drop-target {
  background: #dceeff;
  box-shadow: inset 2px 0 0 var(--brand);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 4px;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.user-table-wrap {
  overflow: visible;
}

.table-wrap table {
  border: 0;
}

.table-wrap th,
.table-wrap td {
  border-left: 0;
  border-right: 0;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 7px;
}

.badge.meta {
  background: #e6f0ff;
  color: #235a96;
}

.badge.google {
  background: #e3f5ed;
  color: #166f5f;
}

.badge.tiktok {
  background: #f1e8ff;
  color: #68428d;
}

.badge.good,
.badge.success {
  background: #e3f5ed;
  color: var(--success);
}

.badge.warn {
  background: #fff2cc;
  color: var(--warning);
}

.badge.bad {
  background: #fde8e8;
  color: var(--danger);
}

.chart {
  min-height: 180px;
}

.chart svg {
  display: block;
  height: auto;
  width: 100%;
}

.mini-chart {
  min-width: 86px;
  width: 96px;
}

.mini-chart svg {
  display: block;
  overflow: visible;
  width: 100%;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 4px;
  padding: 24px;
  text-align: center;
}

#toast {
  background: var(--ink);
  border-radius: 3px;
  bottom: 12px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 8px 10px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 8px);
  transition: 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  .topbar {
    position: static;
  }

  .topbar-search {
    display: none;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  main {
    padding: 10px;
  }

  .hero {
    align-items: start;
    flex-direction: column;
  }

  .metric-picker {
    align-items: flex-start;
    flex-direction: column;
  }

  .date-range-control {
    justify-content: flex-start;
  }

  .filter-panel,
  .filter-grid,
  .ad-account-edit-form {
    grid-template-columns: 1fr;
  }

  .metric-options {
    justify-content: flex-start;
  }

  .kpis,
  .two-col,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
