:root {
  color-scheme: dark;
  --bg: #080d12;
  --surface: #111821;
  --surface-soft: #182330;
  --text: #e6edf3;
  --muted: #91a0b3;
  --border: #263443;
  --green: #38d993;
  --red: #ff6b6b;
  --blue: #79a7ff;
  --teal: #2dd4bf;
  --amber: #f6bd3f;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

button {
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: clamp(16px, 2vw, 24px);
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 8px 0 18px;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(720px, 100%);
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  white-space: normal;
  overflow-wrap: anywhere;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.status-pill.ok .dot {
  background: var(--green);
}

.status-pill.error .dot {
  background: var(--red);
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr)) minmax(220px, 1.2fr) auto auto;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c131b;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.datetime-pair {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 8px;
  min-width: 0;
}

.datetime-pair input {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.datetime-pair input::-webkit-calendar-picker-indicator {
  width: 16px;
  height: 16px;
  padding: 0;
  margin-left: 6px;
  opacity: 0.9;
  flex: 0 0 auto;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(121, 167, 255, 0.16);
}

.quick-actions,
.refresh-control {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  min-width: 0;
  max-width: 100%;
}

.quick-actions button,
.refresh-control button,
.ghost-btn {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 8px 12px;
  white-space: nowrap;
}

.quick-actions button:hover,
.refresh-control button:hover,
.ghost-btn:hover {
  border-color: #43576d;
}

.quick-actions button.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

.toggle {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  color: var(--text);
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #0c131b;
}

.toggle input {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 9px 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.tab.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

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

.metric-card,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.metric-card {
  padding: 16px;
}

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

.metric-value {
  margin-top: 8px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.1;
  font-weight: 850;
  overflow-wrap: anywhere;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.metric-value.value-up {
  color: var(--green);
  text-shadow: 0 0 18px rgba(56, 217, 147, 0.22);
}

.metric-value.value-down {
  color: var(--red);
  text-shadow: 0 0 18px rgba(255, 107, 107, 0.2);
}

.number-animate {
  display: inline-block;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.number-animate.value-up {
  color: var(--green);
  text-shadow: 0 0 14px rgba(56, 217, 147, 0.2);
}

.number-animate.value-down {
  color: var(--red);
  text-shadow: 0 0 14px rgba(255, 107, 107, 0.18);
}

.metric-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

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

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
  max-width: 100%;
}

.panel.active {
  display: block;
}

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

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

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

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

.compact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  background: #0c131b;
}

.compact-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-row span {
  color: var(--muted);
  font-size: 12px;
}

.compact-row .money {
  font-weight: 850;
  overflow-wrap: anywhere;
  text-align: right;
}

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

.stat-card {
  padding: 14px;
}

.card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.card-title h3 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 8px;
  background: var(--surface-soft);
}

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

.mini-stat {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px;
  background: #0c131b;
  min-width: 0;
}

.mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.mini-stat strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.meta-line span {
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 3px 7px;
}

.daily-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  align-items: end;
  gap: 10px;
  min-height: 190px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #0c131b;
}

.bar-wrap {
  display: grid;
  align-items: end;
  gap: 6px;
  min-width: 0;
}

.bar {
  min-height: 3px;
  border-radius: 6px 6px 2px 2px;
  background: var(--teal);
}

.bar.neg {
  background: var(--red);
}

.bar-label {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
  background: #0c131b;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: #121b26;
  color: var(--muted);
  font-size: 12px;
}

td {
  font-size: 13px;
}

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

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

.empty {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: #0c131b;
}

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

  .quick-actions,
  .refresh-control {
    flex-wrap: wrap;
  }

  .summary-grid,
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 12px;
  }

  h1 {
    font-size: 28px;
  }

  .filters {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    min-width: 0;
  }

  .datetime-pair {
    --datetime-inset: clamp(14px, 5vw, 28px);
    grid-template-columns: 1fr;
    gap: 8px;
    justify-items: center;
  }

  .datetime-pair input {
    width: calc(100% - var(--datetime-inset) - var(--datetime-inset));
    justify-self: center;
    min-height: 38px;
    padding-left: 28px;
    padding-right: 28px;
    text-align: center;
  }

  .datetime-pair input::-webkit-calendar-picker-indicator {
    width: 14px;
    height: 14px;
    margin-left: 0;
  }

  .overview-layout,
  .summary-grid,
  .card-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    gap: 10px;
  }

  .metric-card,
  .stat-card,
  .panel {
    box-shadow: none;
  }

  .metric-card {
    padding: 12px;
  }

  .metric-value {
    font-size: 23px;
  }

  .panel {
    padding: 12px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .ghost-btn {
    width: 100%;
  }

  .quick-actions,
  .refresh-control {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-actions button,
  .refresh-control button {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
  }

  .toggle {
    width: 100%;
    justify-content: center;
  }

  .status-pill {
    width: 100%;
    justify-content: flex-start;
    border-radius: 8px;
    padding: 8px 10px;
  }

  .tabs {
    margin: 12px 0;
    padding: 0 0 2px;
  }

  .tab {
    min-height: 38px;
    padding: 8px 13px;
  }

  .triplet {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .card-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .tag {
    max-width: 130px;
  }

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

  .compact-row .money {
    text-align: left;
  }

  .daily-chart {
    grid-auto-flow: column;
    grid-auto-columns: 44px;
    grid-template-columns: none;
    overflow-x: auto;
  }

  table {
    min-width: 760px;
  }
}

@media (max-width: 420px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    padding: 16px;
  }

  input {
    font-size: 13px;
  }

  .filters {
    padding: 10px;
  }

  .datetime-pair input {
    font-size: 13px;
  }

  .mini-stat strong {
    font-size: 14px;
  }
}
