@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-body: #f8f9ff;
  --bg-surface: #ffffff;
  --bg-success: #dbffde;
  --bg-error: #ffe0e0;
  --bg-tabs: #dce9ff;
  --bg-button-primary: #0b1c30;
  --bg-button-secondary: #e9ebf2;
  --bg-button-tertiary: #ffffff;
  --text-body: #0b1c30;
  --text-muted: #64748b;
  --text-inverted: #ffffff;
  --text-success: #0e6909;
  --text-error: #86161d;
  --input-border: #b1c4da;
  --border-subtle: #dce9ff;
  --border-button-primary: #0b1c30;
  --border-button-secondary: #e9ebf2;
  --border-button-tertiary: #dce9ff;
  --border-radius-regular: 8px;
  --border-radius-small: 4px;
  --status-bg: #f8fafc;
  --box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
  --font-size-body: 1.6rem;
  --font-size-small: 1.4rem;
  --font-size-tiny: 1.2rem;
  --font-sans:
    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 62.5%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
  padding: 0;
  font-size: var(--font-size-body);
  display: grid;
  gap: 3.2rem;
}

footer {
  padding-bottom: 3.2rem;
}

h1,
.h1 {
  font-size: 4rem;
  font-weight: 700;
}

h2,
.h2 {
  font-size: 3.6rem;
  font-weight: 700;
}

h3,
.h3 {
  font-size: 2.8rem;
  font-weight: 700;
}

.wrapper {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.6rem;
  display: grid;
  gap: 3.2rem;
}

a {
  color: var(--text-body);
}

.button {
  padding: 1.6rem 2.4rem;
  border-radius: var(--border-radius-small);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: var(--font-size-body);
  text-decoration: none;
  color: var(--text-body);
  cursor: pointer;
  display: flex;
  gap: 0.8rem;
  align-items: center;
  position: relative;
  width: fit-content;

  &.icon-button {
    img {
      width: 24px;
      height: 24px;
    }
  }

  img {
    height: 16px;
  }

  &.primary {
    background: var(--bg-button-primary);
    border-color: var(--border-button-primary);
    color: var(--text-inverted);
  }

  &.secondary {
    background: var(--bg-button-secondary);
    border-color: var(--border-button-secondary);
  }

  &.tertiary {
    background: var(--bg-button-tertiary);
    border-color: var(--border-button-tertiary);
  }
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 0.8rem;
  border-radius: 999px;
  background: var(--text-body);
  color: var(--text-inverted);
  font-size: var(--font-size-tiny);
  font-weight: 700;
  line-height: 1;
  position: absolute;
  right: -0.8rem;
  top: -0.8rem;
}

.error-page {
  display: grid;
  gap: 1.6rem;
  max-width: 64rem;
  padding: 4.8rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-regular);
}

.error-page p {
  color: var(--text-muted);
}

.error-code {
  font-size: var(--font-size-small);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text-body);
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-top: 1.6rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 2.4rem;
  background: rgba(248, 249, 255, 0.82);
}

.is-importing .loading-overlay {
  display: grid;
}

.loading-panel {
  display: inline-flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1.6rem 2.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-regular);
  box-shadow: var(--box-shadow);
  font-weight: 700;
}

.loading-spinner {
  width: 2.4rem;
  height: 2.4rem;
  border: 0.3rem solid var(--border-subtle);
  border-top-color: var(--text-body);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

input {
  padding: 1.6rem;
  border: 1px solid var(--input-border);
  font-family: var(--font-sans);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
  font-size: var(--font-size-body);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  gap: 0.8rem;
  max-height: 51px;
  border-radius: var(--border-radius-small);
}

select {
  padding: 1.6rem;
  border: 1px solid var(--input-border);
  border-radius: var(--border-radius-small);
  background: var(--bg-surface);
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: var(--font-size-body);
}

/* nabar */
.navbar {
  background: var(--bg-surface);
  box-shadow: var(--box-shadow);
  padding: 1.6rem 0;

  .wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
    align-items: start;

    @media (min-width: 782px) {
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
    }
  }

  .logo {
    display: block;
    width: auto;
    height: 74px;
  }
}

/* Date Control Switchers */
.dashboard-actions {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 1.6rem;

  .date-picker-form {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 1.6rem;
  }
}

.report-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.6rem;
  padding: 1.6rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-small);
}

.range-picker-form,
.report-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1.2rem;
}

.range-picker-form label {
  display: grid;
  gap: 0.8rem;
}

.range-picker-form label span {
  font-size: var(--font-size-tiny);
  font-weight: 600;
}

/* Header Styling */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 3.2rem;
  flex-direction: column;

  @media (min-width: 782px) {
    flex-direction: row;
    align-items: flex-end;
  }

  .tabs {
    background: var(--bg-tabs);
    padding: 0.8rem 1.6rem;
    gap: 1.6rem;
    display: flex;
    border-radius: var(--border-radius-small);
  }

  .dashboard-text {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* tabs */
/* --- Tabs Component Container --- */
.tabs-container {
  display: flex;
  flex-wrap: wrap; /* Allows content panels to wrap below the labels */

  /* Hide the native, ugly radio buttons entirely */
  input[type='radio'] {
    display: none;
  }

  /* --- Tab Labels (The Buttons) --- */
  .tab-label {
    padding: 1.6rem 2.4rem;
    cursor: pointer;
    background: var(--bg-button-secondary);
    border-bottom: none;
    margin-right: 0.8rem;
    border-radius: var(--border-radius-small) var(--border-radius-small) 0 0;
    transition: all 0.2s ease;
    user-select: none;
    display: flex;
    flex-direction: row;
    gap: 0.8rem;
    font-weight: 600;
    align-items: center;

    img {
      height: 20px;
    }
  }

  /* --- Content Panels --- */
  .tab-content {
    width: 100%;
    order: 1; /* Guarantees all content blocks sit below the labels */
    display: none; /* Hide all panels by default */
  }

  /* --- THE MAGIC ENGINE (Sibling Combinators) --- */

  /* 1. Dynamic Button Highlighting: Style the label next to the checked radio */
  #tab1:checked ~ [for='tab1'],
  #tab2:checked ~ [for='tab2'],
  #tab3:checked ~ [for='tab3'] {
    background: var(--bg-button-tertiary);
    position: relative;
    z-index: 2; /* Sits slightly above the content border */

    /* Optional fine-tuning: hides the line separating the active tab from its content box */
    box-shadow: 0 2px 0 var(--bg-button-tertiary);
  }

  /* 2. Dynamic Content Switching: Show the content block associated with the checked radio */
  #tab1:checked ~ #content1,
  #tab2:checked ~ #content2,
  #tab3:checked ~ #content3 {
    display: block;
  }
}

/* card and kpis */
.card {
  background: var(--bg-surface);
  border-radius: var(--border-radius-small);
  box-shadow: var(--box-shadow);
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 3.2rem;
}

.dashboard-card-grid {
  display: grid;
  gap: 3.2rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));

  @media (max-width: 1000px) {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}

.dashboard-card-header {
  align-items: start;
  display: flex;
  gap: 1.6rem;
  justify-content: space-between;
  width: 100%;
}

.dashboard-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.6rem;
  justify-content: flex-end;
}

.dashboard-card-kpis {
  display: grid;
  gap: 1.6rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-card-kpis .highlight {
  padding: 1.2rem;
}

.dashboard-card-kpis .kpi-highlight {
  padding-right: 6.8rem;
}

.dashboard-card-kpis .kpi-badge {
  right: 1.2rem;
  top: 1.2rem;
}

.dashboard-card-header p {
  color: var(--text-muted);
  font-size: var(--font-size-small);
}

.dashboard-card-header-text {
  display: grid;
  gap: 0.4rem;
}

.monthly-comparison-card {
  gap: 2.4rem;
}

.monthly-comparison-header {
  align-items: start;
  display: flex;
  gap: 1.6rem;
  justify-content: space-between;

  p {
    color: var(--text-muted);
    font-size: var(--font-size-small);
    margin-top: 0.4rem;
  }
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  justify-content: flex-end;

  span {
    align-items: center;
    color: var(--text-muted);
    display: inline-flex;
    font-size: var(--font-size-small);
    font-weight: 600;
    gap: 0.6rem;
  }
}

.legend-swatch {
  border-radius: 999px;
  display: inline-block;
  height: 1rem;
  width: 1rem;

  &.current {
    background: var(--text-body);
  }

  &.previous {
    background: var(--input-border);
  }
}

.monthly-line-chart {
  display: grid;
  gap: 0.8rem;
}

.monthly-line-svg {
  border-bottom: 1px solid var(--border-subtle);
  display: block;
  height: 18rem;
  overflow: visible;
  width: 100%;
}

.monthly-grid-line {
  stroke: var(--border-subtle);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.monthly-zero-line {
  stroke: var(--text-error);
  stroke-dasharray: 6 6;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.monthly-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;

  &.current {
    stroke: var(--text-body);
  }

  &.previous {
    stroke: var(--input-border);
  }
}

.monthly-point {
  stroke: var(--surface);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;

  &.current {
    fill: var(--text-body);
  }

  &.previous {
    fill: var(--input-border);
  }

  &.negative {
    fill: var(--text-error);
  }
}

.monthly-line-axis {
  color: var(--text-muted);
  display: grid;
  font-size: var(--font-size-small);
  font-weight: 600;
  gap: 0.2rem;
  line-height: 1;
  min-height: 1.2rem;
  text-align: center;
}

.monthly-line-axis span {
  min-width: 0;
}

.kpi-grid {
  display: grid;
  gap: 1.6rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));

  @media (max-width: 1200px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @media (max-width: 782px) {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}

.highlight {
  padding: 1.6rem;
  border: 1px solid transparent;
  border-radius: var(--border-radius-small);
  background: var(--bg-body);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;

  &.positive {
    color: var(--text-success);
    background: var(--bg-success);
    border-color: var(--bg-success);

    .kpi-badge {
      background: var(--text-success);
      color: var(--text-inverted);
    }
  }

  &.negative {
    color: var(--text-error);
    background: var(--bg-error);
    border-color: var(--bg-error);

    .kpi-badge {
      background: var(--text-error);
      color: var(--text-inverted);

      .kpi-badge-icon {
        transform: scaleY(-1);
      }
    }
  }
}

.kpi-highlight {
  position: relative;
  padding-right: 6.8rem;
}

.kpi-badge {
  position: absolute;
  top: 1.6rem;
  right: 1.6rem;
  border-radius: 999px;
  background: var(--bg-surface);
  color: inherit;
  font-size: var(--font-size-small);
  font-weight: 600;
  line-height: 1;
  padding: 0.4rem 0.8rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;

  .kpi-badge-icon {
    width: 16px;
  }
}

.kpi-previous {
  font-size: var(--font-size-small);
}

/* Region Sections */
.region-section {
  background: var(--bg-surface);
  border-radius: var(--border-radius-small);
  box-shadow:
    0 1px 3px 0 rgba(0, 0, 0, 0.05),
    0 1px 2px -1px rgba(0, 0, 0, 0.05);
  padding: 32px;
  margin-bottom: 32px;
  border: 1px solid rgba(0, 0, 0, 0.02);
}

/* Table Layout Refinements */
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  font-size: var(--font-size-small);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

td {
  padding: 16px;
  font-size: var(--font-size-body);
  color: var(--text-body);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.totals-row td {
  background: #f8fafc;
  border-top: 2px solid #e2e8f0;
  color: var(--text-body);
  font-weight: 700;
}

.refund-row td {
  background: #fff7ed;
}

.note {
  color: var(--text-muted);
  font-size: var(--font-size-small);
  margin-bottom: 18px;
}

.grid {
  display: grid;
  gap: 1.6rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid span {
  color: var(--text-muted);
  display: block;
  font-size: var(--font-size-small);
  font-weight: 600;
  margin-bottom: 6px;
}

.grid strong {
  color: var(--text-body);
  display: block;
}

.calculation-block {
  display: grid;
  gap: 0.8rem;
}

.calculation-row {
  align-items: center;
  background: #ffffff;
  display: grid;
  gap: 1.6rem;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 0.8rem 1.6rem;
  border-radius: var(--border-radius-small);

  &.highlight,
  &.subtotal {
    padding: 1.2rem 1.6rem;
  }
}

.calculation-row > span {
  font-size: var(--font-size-small);
  font-weight: 600;
}

.calculation-label {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.calculation-formula {
  display: inline;
  font-size: var(--font-size-small);
}

.calculation-row small {
  font-size: var(--font-size-small);
  font-weight: 400;
}

.calculation-row.result,
.calculation-row.subtotal {
  background: var(--bg-body);
}

.summary-adjustments {
  border-top: 1px solid var(--border-subtle);
  margin-top: 1.6rem;
  padding-top: 1.6rem;
}

.summary-adjustments h3 {
  margin-bottom: 0.8rem;
}

.summary-adjustments th,
.summary-adjustments td {
  padding: 0.8rem 1.2rem;
}

.summary-adjustments td {
  font-size: var(--font-size-small);
}

/* Secondary timestamp text below the Order ID */
td .timestamp-text {
  display: block;
  font-size: var(--font-size-tiny);
  color: var(--text-muted);
  margin-top: 4px;
}

/* Alignments */
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}

/* Empty dash state mapping for missing values */
.negative-fee:empty::before,
td:empty::before {
  content: '—';
  color: var(--text-muted);
}

.sync-notice {
  border-radius: var(--border-radius-small);
  padding: 1.6rem;
}

.sync-notice.success {
  background: var(--text-success);
  border: 1px solid var(--text-success);
  color: var(--text-inverted);
}

.sync-notice.error {
  background: var(--text-error);
  border: 1px solid var(--text-error);
  color: var(--text-inverted);
}

.dashboard-footer-note {
  color: var(--text-muted);
  font-size: var(--font-size-small);
  text-align: center;
}

.reconciliation-list {
  display: grid;
  gap: 12px;
}

.manual-adjustment-form {
  display: flex;
  gap: 1.6rem;
  align-items: end;
  flex-wrap: wrap;

  label {
    display: grid;
    gap: 0.8rem;
  }

  input {
    width: 100%;
  }

  @media (min-width: 782px) {
    input[name='adjustment_date'] {
      width: fit-content;
    }

    input[name='description'] {
      max-width: 500px;
    }

    input[name='woocommerce_order_id'] {
      width: 100px;
    }

    input[name='printify_order_id'] {
      width: 200px;
    }

    input[name='amount_gbp'] {
      width: 100px;
    }
  }
}

.order-search-form {
  align-items: end;
  display: grid;
  gap: 1.6rem;
  grid-template-columns: minmax(18rem, 32rem) auto;
  justify-content: start;

  label {
    display: grid;
    gap: 0.8rem;
  }
}

.order-search-form label span {
  font-size: var(--font-size-tiny);
  font-weight: 600;
}

.order-search-form input {
  width: 100%;
}

.manual-adjustment-form label span {
  font-size: var(--font-size-tiny);
  font-weight: 600;
}

.manual-adjustment-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
}

.data-card input,
.data-card select {
  width: 100%;
}

.reconciliation-row {
  align-items: end;
  border: 1px solid #e2e8f0;
  border-radius: var(--border-radius-small);
  display: grid;
  gap: 1.6rem;
  grid-template-columns: 170px minmax(180px, 1fr) 150px auto;
  padding: 14px;
}

.reconciliation-order strong,
.reconciliation-order span,
.reconciliation-row label span {
  display: block;
}

.reconciliation-order strong {
  color: var(--text-body);
  margin-bottom: 4px;
}

.reconciliation-order span,
.reconciliation-row label span {
  color: var(--text-muted);
  font-size: var(--font-size-small);
  font-weight: 700;
  margin-bottom: 6px;
}

.reconciliation-row input {
  border: 1px solid #cbd5e1;
  border-radius: var(--border-radius-small);
  color: var(--text-body);
  font: inherit;
  height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.login-page {
  min-height: 100vh;
  place-items: center;
}

.login-shell {
  display: grid;
  padding: 3.2rem 1.6rem;
  width: min(100%, 46rem);
}

.login-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-regular);
  box-shadow: var(--box-shadow);
  display: grid;
  gap: 2.4rem;
  padding: 3.2rem;
}

.login-logo {
  height: 100px;
  width: max-content;
  margin: 0 auto;
}

.login-form {
  display: grid;
  gap: 1.6rem;
}

.login-form label {
  display: grid;
  gap: 0.8rem;
}

.login-form label span {
  font-weight: 600;
}

.login-form .button {
  justify-content: center;
}

@media (max-width: 782px) {
  .calculation-row {
    grid-template-columns: 2fr;
  }

  .calculation-row strong {
    text-align: left;
  }

  .reconciliation-panel-header,
  .manual-adjustment-form,
  .reconciliation-row {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 2fr;
  }
}
