/* CEO Dashboard — widget grid layout */

/* ---- Global toolbar ---- */
.ceodash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.ceodash-period-btns {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--card);
}

.ceodash-period-btn {
  padding: 7px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.ceodash-period-btn:last-child { border-right: none; }
.ceodash-period-btn:hover { background: #f0ede8; }
.ceodash-period-btn.active { background: #1a1a2e; color: #fff; font-weight: 600; }
.ceodash-period-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.ceodash-toolbar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ---- Widget grid ---- */
.wd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "revenue   purchases orders"
    "trend     trend     trend"
    "customers customers ar";
  gap: 16px;
}

.wd-grid.wd-grid-with-margin {
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-areas:
    "revenue   purchases orders   margin"
    "trend     trend     trend    trend"
    "customers customers ar       ar";
}

@media (max-width: 1200px) {
  .wd-grid.wd-grid-with-margin {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "revenue   purchases"
      "orders    margin"
      "trend     trend"
      "customers customers"
      "ar        ar";
  }
}

@media (max-width: 1000px) {
  .wd-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "revenue   purchases"
      "orders    orders"
      "trend     trend"
      "customers customers"
      "ar        ar";
  }
}

@media (max-width: 600px) {
  .wd-grid,
  .wd-grid.wd-grid-with-margin {
    grid-template-columns: 1fr;
    grid-template-areas:
      "revenue"
      "purchases"
      "orders"
      "margin"
      "trend"
      "customers"
      "ar";
  }
}

/* ---- Widget card ---- */
.wd-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
}

.wd-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
  flex-wrap: wrap;
}

.wd-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  letter-spacing: 0.01em;
}

.wd-card-body {
  flex: 1;
  min-height: 60px;
}

/* ---- Per-widget period pills ---- */
.wd-pills {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.wd-period-pill {
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: 500;
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.wd-period-pill:last-child { border-right: none; }
.wd-period-pill:hover { background: #f0ede8; color: var(--text); }
.wd-period-pill.active { background: #1a1a2e; color: #fff; font-weight: 600; }

/* ---- Metrics ---- */
.wd-metric-row {
  display: flex;
  gap: 20px;
  align-items: flex-end;
}
.wd-sub-row { margin-top: 10px; }

.wd-metric-block {
  flex: 1;
  min-width: 0;
}

.wd-metric-big {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}

.wd-metric-med {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.3;
}

.wd-metric-sm {
  font-size: 0.92rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.wd-metric-unit {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 2px;
}

.wd-divider {
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

/* ---- Delta badges ---- */
.wd-delta {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 4px;
}
.wd-delta.delta-up   { background: #dcfce7; color: #166534; }
.wd-delta.delta-down { background: #fee2e2; color: #991b1b; }

/* ---- Sparkline ---- */
.wd-spark {
  display: block;
  width: 100%;
  height: 40px;
  margin: 10px 0 4px;
}

/* ---- Bar chart (trend widget) ---- */
.wd-bars-wrap {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  height: 170px;
}

.wd-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.wd-bar-val {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
}

.wd-bar-track {
  width: 100%;
  max-width: 44px;
  height: 120px;
  display: flex;
  align-items: flex-end;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
}

.wd-bar-fill {
  width: 100%;
  background: #2563eb;
  border-radius: 3px 3px 0 0;
  transition: height 0.4s ease;
  min-height: 2px;
}

.wd-bar-lbl {
  font-size: 0.68rem;
  color: var(--text);
  margin-top: 5px;
  font-weight: 600;
}

.wd-bar-sub {
  font-size: 0.58rem;
  color: var(--muted);
  margin-top: 1px;
}

.wd-trend-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.wd-trend-total {
  font-weight: 600;
  color: var(--text);
}

/* ---- List rows (customers, AR) ---- */
.wd-list-row {
  display: grid;
  grid-template-columns: 22px 1fr minmax(60px, auto) 70px 42px;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  font-size: 0.76rem;
}
.wd-list-row + .wd-list-row {
  border-top: 1px solid #f0ede8;
}

.wd-list-rank {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-align: center;
}

.wd-list-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wd-list-bar {
  height: 8px;
  background: #f0ede8;
  border-radius: 999px;
  overflow: hidden;
}

.wd-list-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
  min-width: 2px;
}
.wd-fill-blue  { background: #2563eb; }
.wd-fill-amber { background: #d97706; }

.wd-list-val {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.wd-list-pct {
  font-weight: 500;
  color: var(--muted);
  text-align: right;
  font-size: 0.7rem;
}

/* ---- Margin widget ---- */
.wd-margin-breakdown {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wd-margin-cur-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.wd-margin-cur-row + .wd-margin-cur-row {
  border-top: 1px solid #f0ede8;
}

.wd-margin-cur-code {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  min-width: 36px;
}

.wd-margin-cur-lines {
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1;
}

.wd-margin-cur-sum {
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.wd-val-pos { color: #166534; }
.wd-val-neg { color: #991b1b; }

/* ---- Spinner ---- */
.wd-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 0;
}

.wd-spin {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--line);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: wd-rotate 0.65s linear infinite;
}

@keyframes wd-rotate {
  to { transform: rotate(360deg); }
}

/* ---- Empty / Error ---- */
.wd-empty {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 16px 0;
  text-align: center;
}

.wd-error {
  font-size: 0.78rem;
  color: #991b1b;
  padding: 12px 0;
}

/* ---- Responsive tweaks ---- */
@media (max-width: 600px) {
  .wd-metric-big { font-size: 1.1rem; }
  .wd-bars-wrap { height: 130px; }
  .wd-bar-track { height: 90px; }
  .wd-list-row {
    grid-template-columns: 20px 1fr 60px 36px;
    font-size: 0.7rem;
  }
  .wd-list-bar { display: none; }
  .ceodash-period-btns { flex-wrap: wrap; }
}
