/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-muted: #eeece7;
  --text: #181713;
  --muted: #716c61;
  --line: #ded9cf;
  --accent: #174f43;
  --accent-strong: #0d342c;
  --danger: #8d271f;
  --profit: #13795b;
  --loss: #a23025;
  --info-bg: #e7f0f7;
  --info: #24506f;
  --warning-bg: #fff3db;
  --success-bg: #e5f2eb;
  --danger-bg: #f8dfdc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgb(246 245 242 / 94%);
  backdrop-filter: blur(12px);
}

.app-header-inner {
  width: min(1440px, calc(100% - 32px));
  min-height: 58px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-link {
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
  text-decoration: none;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  min-height: 34px;
  padding: 7px 11px;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-link-active {
  background: var(--accent);
  color: #fff;
}

.nav-link-active:hover {
  background: var(--accent-strong);
  color: #fff;
}

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

.page-header,
.panel-header,
.filters,
.import-row {
  display: flex;
  align-items: center;
}

.page-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 2px 0 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.button {
  appearance: none;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button-secondary {
  background: #fff;
  color: var(--accent);
}

.button-secondary:hover {
  background: var(--success-bg);
  color: var(--accent-strong);
}

.button-disabled,
.button-disabled:hover {
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  cursor: default;
}

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

.button-danger:hover {
  border-color: #641913;
  background: #641913;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

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

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1;
}

.profit-positive {
  color: var(--profit);
}

.profit-negative {
  color: var(--loss);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    linear-gradient(135deg, rgb(23 79 67 / 8%), transparent 34%),
    linear-gradient(315deg, rgb(19 121 91 / 10%), transparent 38%),
    var(--bg);
}

.auth-panel {
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgb(24 23 19 / 10%);
  padding: 24px;
}

.auth-brand {
  margin-bottom: 20px;
}

.auth-brand h1 {
  margin: 4px 0 8px;
  font-size: 38px;
  line-height: 1;
  letter-spacing: 0;
}

.auth-brand p:last-child {
  margin: 0;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-input,
.auth-submit {
  width: 100%;
}

.auth-actions {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

.auth-link {
  color: var(--accent);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.auth-link:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.panel {
  margin-top: 14px;
  overflow: hidden;
}

.panel-compact {
  margin-top: 18px;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.panel-header {
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.filters {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 0 10px;
  width: 180px;
}

.input-small {
  width: 120px;
}

.input-page {
  width: 88px;
}

.input-wide {
  width: min(100%, 420px);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.text-area {
  min-height: 110px;
  padding-top: 10px;
  resize: vertical;
}

.file-input {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  max-width: 320px;
  min-height: 38px;
  padding: 7px 10px;
}

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

.table-toolbar {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 16px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table-compact {
  min-width: 720px;
}

.data-table-compact th,
.data-table-compact td {
  padding: 9px 12px;
}

.numeric {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.table-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

.sort-link {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

.sort-link:hover,
.sort-link-active {
  color: var(--accent);
}

.pagination {
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
}

.pagination-status {
  color: var(--muted);
  font-weight: 800;
}

.status-pill {
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 180px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-completed {
  background: var(--success-bg);
  color: var(--accent-strong);
}

.status-failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-processing {
  background: var(--warning-bg);
  color: #6d4d00;
}

.status-estimated {
  background: var(--warning-bg);
  color: #6d4d00;
}

.status-approved {
  background: var(--success-bg);
  color: var(--profit);
}

.status-info {
  background: var(--info-bg);
  color: var(--info);
}

.empty-state,
.muted {
  color: var(--muted);
}

.empty-state {
  padding: 18px 16px;
  text-align: center;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  border-radius: 6px;
  padding: 11px 13px;
  font-weight: 700;
}

.flash-notice {
  background: var(--success-bg);
  color: var(--accent-strong);
}

.flash-alert {
  background: var(--danger-bg);
  color: var(--danger);
}

.import-list {
  display: grid;
}

.import-row {
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.import-row:last-child {
  border-bottom: 0;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.details-grid .panel {
  margin-top: 0;
  padding: 16px;
}

.details-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.details-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}

.details-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.details-list dt {
  color: var(--muted);
  font-weight: 700;
}

.details-list dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.breakdown-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 4px 16px 14px;
}

.breakdown-list div,
.compact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.breakdown-list div:last-child,
.compact-row:last-child {
  border-bottom: 0;
}

.breakdown-list dt {
  color: var(--muted);
  font-weight: 700;
}

.breakdown-list dd {
  margin: 0;
  font-weight: 900;
  text-align: right;
}

.breakdown-total {
  font-size: 15px;
}

.expense-dashboard {
  display: grid;
  gap: 18px;
  padding: 16px;
}

.expense-charts,
.expense-tables {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-box,
.expense-tables article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.chart-box {
  padding: 14px;
}

.chart-box h3,
.expense-tables h3 {
  margin: 0;
  font-size: 14px;
}

.chart-box h3 {
  margin-bottom: 12px;
}

.expense-tables h3 {
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

.report-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.report-chart {
  margin-top: 0;
}

.chart-box-flat {
  border: 0;
  border-radius: 0;
}

.reports-table {
  min-width: 1640px;
}

.reports-table td:first-child {
  min-width: 180px;
}

.report-expense-dashboard {
  padding: 0;
}

.report-expense-dashboard .expense-charts {
  grid-template-columns: 1fr;
}

.attention-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px;
}

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

.attention-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  display: grid;
  gap: 8px;
  min-height: 82px;
  padding: 12px;
  text-decoration: none;
}

.attention-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.attention-card strong {
  font-size: 28px;
  line-height: 1;
}

.attention-card-alert {
  border-color: #e3b750;
  background: var(--warning-bg);
}

.compact-list {
  display: grid;
  padding: 4px 16px 14px;
}

.compact-row {
  color: inherit;
  text-decoration: none;
}

.compact-row span {
  color: var(--muted);
  font-weight: 800;
}

.compact-row strong {
  white-space: nowrap;
}

details {
  padding: 16px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.raw-json {
  overflow: auto;
  margin: 14px 0 0;
  border-radius: 6px;
  background: #171a17;
  color: #f6f5f2;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
}

.form-panel {
  padding: 16px;
}

.danger-panel {
  border-color: var(--danger);
}

.danger-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.stacked-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  max-width: 520px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-weight: 800;
}

.rule-form-wrap {
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.rule-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.table-form {
  display: contents;
}

.inline-pair,
.inline-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.inline-field {
  display: grid;
  gap: 5px;
}

.inline-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: var(--muted);
  font-weight: 800;
}

.products-popover {
  display: inline-block;
}

.products-popover-button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  font: inherit;
  font-weight: 800;
  white-space: nowrap;
}

.products-popover-button:hover {
  background: var(--success-bg);
  border-color: var(--accent);
}

.products-popover-panel {
  position: fixed;
  z-index: 50;
  width: min(520px, calc(100vw - 24px));
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgb(24 23 19 / 16%);
  padding: 12px;
}

.popover-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 0 0 10px;
}

.popover-summary span,
.product-popover-metrics dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.popover-summary strong {
  font-size: 18px;
}

.products-list {
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.product-popover-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.product-popover-main {
  display: block;
}

.product-popover-main div {
  display: grid;
  gap: 4px;
}

.product-popover-main strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.3;
}

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

.product-popover-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 0;
}

.product-popover-metrics div {
  display: grid;
  gap: 3px;
}

.product-popover-metrics dd {
  margin: 0;
  font-weight: 800;
}

.cost-chart {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 16px;
  overflow: visible;
}

.cost-chart polyline {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .app-header-inner {
    width: min(100% - 20px, 1440px);
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0;
  }

  .main-nav {
    width: 100%;
    overflow-x: auto;
  }

  .page-header,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics-grid,
  .metrics-grid-three,
  .details-grid,
  .expense-charts,
  .expense-tables,
  .report-chart-grid,
  .attention-grid,
  .attention-grid-small {
    grid-template-columns: 1fr;
  }

  .filters,
  .inline-upload,
  .rule-form,
  .input {
    width: 100%;
  }

  .button,
  .file-input,
  .rule-form .input,
  .filters form,
  .filters .button {
    width: 100%;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }
}
