:root {
  --bg: #f7f8ff;
  --surface: #ffffff;
  --surface-soft: #f0f3ff;
  --ink: #061635;
  --muted: #68728a;
  --line: #dfe4f2;
  --green: #22bf4f;
  --green-dark: #10913a;
  --blue: #315fd2;
  --purple: #6b35ee;
  --navy: #061635;
  --amber: #c56a14;
  --red: #b93434;
  --shadow: 0 18px 40px rgba(6, 22, 53, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
select,
input,
textarea {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  height: 100vh;
  background: #f9fbfa;
  border-right: 1px solid var(--line);
  color: var(--ink);
}

.module-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 18px 12px;
  background: var(--navy);
  color: #f7fbf8;
}

.section-column {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 22px 16px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(107, 53, 238, 0.18);
  overflow: hidden;
}

.brand-mark img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.rail-list {
  display: grid;
  gap: 10px;
}

.rail-item {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #b9cbc2;
  font-size: 18px;
  font-weight: 900;
  text-decoration: none;
}

.rail-item:hover,
.rail-item.active {
  background: linear-gradient(135deg, rgba(107, 53, 238, 0.92), rgba(34, 191, 79, 0.78));
  color: #ffffff;
}

.rail-button {
  margin-top: auto;
  cursor: pointer;
}

.nav-list {
  display: grid;
  gap: 20px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  background: #eef1ff;
  color: var(--purple);
}

.nav-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item i {
  flex-shrink: 0;
  padding: 3px 7px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.nav-item.active i {
  background: linear-gradient(135deg, var(--purple), var(--green));
  color: #ffffff;
}

.nav-item .warn-pill {
  color: var(--amber);
}

.sync-card {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.sync-card span,
.sync-card strong,
.sync-card small {
  display: block;
}

.sync-card span,
.sync-card small {
  color: var(--muted);
}

.sync-card strong {
  margin: 8px 0 14px;
}

.sync-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.sync-meter i {
  display: block;
  width: 78%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--green));
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.topbar,
.filters,
.panel-head,
.topbar-actions,
.legend {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--purple);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 760px;
  font-size: 34px;
  line-height: 1.12;
}

h2 {
  font-size: 18px;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  gap: 10px;
  flex-shrink: 0;
}

.icon-button,
.primary-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--purple);
}

.primary-button {
  padding: 0 18px;
  background: linear-gradient(135deg, var(--purple), var(--green));
  color: #ffffff;
  font-weight: 800;
}

.ghost-button {
  padding: 0 16px;
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 700;
}

.compact {
  min-height: 34px;
  padding: 0 12px;
}

.filters {
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filters select {
  min-width: 170px;
  height: 38px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--ink);
}

.filters input {
  min-width: 210px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  color: var(--ink);
}

.compact-filters {
  box-shadow: none;
}

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

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

#operationsTable td:nth-child(5) {
  font-weight: 900;
}

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

.metric-card {
  padding: 18px;
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 27px;
  letter-spacing: 0;
  line-height: 1;
}

.metric-card small {
  font-size: 12px;
  font-weight: 700;
}

.good {
  color: var(--green) !important;
}

.warn {
  color: var(--amber) !important;
}

.bad {
  color: var(--red) !important;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.85fr);
  gap: 14px;
}

.lower-grid {
  margin-top: 14px;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

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

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-title h2 {
  font-size: 28px;
  line-height: 1.15;
}

.panel-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.legend {
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.revenue-dot {
  background: var(--purple);
}

.profit-dot {
  background: var(--green);
}

.chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: end;
  gap: 10px;
  height: 280px;
  padding: 26px 8px 0;
  border-radius: 8px;
  background:
    linear-gradient(to top, rgba(49, 95, 210, 0.1) 1px, transparent 1px) 0 0 / 100% 25%,
    #fbfcff;
}

.bar-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 3px;
  height: 100%;
}

.bar {
  min-height: 14px;
  border-radius: 6px 6px 0 0;
}

.bar.revenue {
  background: linear-gradient(180deg, var(--purple), var(--blue));
}

.bar.profit {
  background: linear-gradient(180deg, #31d967, var(--green));
}

.alert-list {
  display: grid;
  gap: 10px;
}

.alert-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.alert-badge {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: var(--purple);
  font-weight: 900;
}

.alert-item strong,
.alert-item span {
  display: block;
}

.alert-item strong {
  margin-bottom: 4px;
  font-size: 14px;
}

.alert-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

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

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

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

td {
  font-size: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
}

.tag.warning {
  color: var(--amber);
}

.tag.danger {
  color: var(--red);
}

.expense-stack {
  display: grid;
  gap: 14px;
}

.expense-row {
  display: grid;
  gap: 7px;
}

.expense-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.expense-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.expense-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--green));
}

.report-table {
  min-width: 780px;
}

.report-table tr.section-row td {
  padding-top: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.report-table td:last-child {
  text-align: right;
  font-weight: 900;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.timeline-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.timeline-item strong,
.timeline-item span,
.cash-card span,
.cash-card small {
  display: block;
}

.timeline-item span,
.cash-card span {
  color: var(--muted);
  font-size: 13px;
}

.timeline-amount {
  font-weight: 900;
}

.cash-card {
  display: grid;
  gap: 12px;
  min-height: 206px;
  align-content: center;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.cash-card strong {
  font-size: 34px;
}

.market-grid,
.stock-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.settings-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
}

.market-card,
.stock-card {
  display: grid;
  gap: 13px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.market-card h3,
.stock-card h3 {
  margin: 0;
  font-size: 17px;
}

.market-card dl,
.stock-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.market-card div,
.stock-card div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.market-card dt,
.stock-card dt {
  color: var(--muted);
}

.market-card dd,
.stock-card dd {
  margin: 0;
  font-weight: 900;
  text-align: right;
}

.stock-days {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--purple);
  font-size: 12px;
  font-weight: 900;
}

.stock-days.low {
  color: var(--red);
}

.connector-list,
.rule-list,
.settings-summary {
  display: grid;
  gap: 12px;
}

.connector-row,
.switch-row {
  display: grid;
  gap: 10px;
  padding: 13px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.connector-row {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.9fr);
  align-items: center;
}

.connector-row span,
.connector-row small {
  display: block;
}

.connector-row small {
  margin-top: 4px;
  color: var(--muted);
}

.connector-row input,
.modal-form input,
.modal-form textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.modal-form textarea {
  min-height: 132px;
  padding: 12px;
  resize: vertical;
}

.switch-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.switch-row input {
  width: 42px;
  height: 22px;
  accent-color: var(--green);
}

.settings-summary {
  margin-top: 14px;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.summary-line strong {
  color: var(--ink);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(12, 19, 16, 0.44);
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  display: none;
  width: min(640px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(12, 19, 16, 0.28);
}

.modal.active {
  display: block;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-head h2 {
  font-size: 20px;
}

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

.modal-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

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

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    grid-template-columns: 74px minmax(0, 1fr);
    height: auto;
  }

  .section-column {
    max-height: none;
  }

  .rail-button {
    margin-top: 0;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }

  .sync-card {
    margin-top: 0;
  }

  .kpi-grid,
  .report-grid,
  .market-grid,
  .stock-grid,
  .settings-grid,
  .content-grid,
  .lower-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .sidebar {
    grid-template-columns: 1fr;
  }

  .module-rail {
    flex-direction: row;
    justify-content: space-between;
    overflow-x: auto;
  }

  .rail-list {
    display: flex;
    gap: 8px;
  }

  .section-column {
    padding: 18px;
  }

  .workspace {
    padding: 18px;
  }

  .topbar,
  .page-title,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  h1 {
    font-size: 28px;
  }

  .nav-list,
  .kpi-grid,
  .report-grid,
  .market-grid,
  .stock-grid,
  .settings-grid,
  .content-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .connector-row {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 1fr;
  }

  .filters label,
  .filters select,
  .filters input,
  .ghost-button {
    width: 100%;
  }

  .chart {
    gap: 6px;
    height: 230px;
  }
}
