* { box-sizing: border-box; }
:root {
  --bg: #070d18;
  --panel: #0d1626;
  --panel-2: #111d30;
  --border: #22324a;
  --text: #f4f7fb;
  --muted: #8ea0b8;
  --accent: #2e7cf6;
  --success: #12c889;
  --danger: #ff6b6b;
}
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
  border-right: 1px solid var(--border);
  background: #08101d;
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 32px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, #246ef0, #36a3ff);
}
.brand-title { font-weight: 800; letter-spacing: .3px; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
nav { display: grid; gap: 8px; }
.nav-item {
  width: 100%; text-align: left; border: 0; color: #a8b6c9;
  background: transparent; padding: 12px 14px; border-radius: 10px;
}
.nav-item:hover, .nav-item.active { color: white; background: #142035; }
.sidebar-note {
  margin-top: auto; border-top: 1px solid var(--border); padding-top: 18px;
  color: var(--muted); font-size: 13px; display: grid; gap: 4px;
}
.sidebar-note strong { color: var(--text); font-size: 16px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.content { padding: 28px 34px 44px; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 30px; }
h2 { margin-bottom: 4px; font-size: 18px; }
.topbar p, .panel-head p { color: var(--muted); margin-bottom: 0; }
.actions { display: flex; gap: 10px; }
.btn {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  color: white; background: var(--panel-2); font-weight: 650;
}
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.secondary:hover { background: #17253b; }
.filters { margin: 26px 0 18px; display: flex; justify-content: flex-end; }
.period-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; padding: 4px; background: var(--panel); }
.period-tabs button { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 7px; }
.period-tabs button.active { color: white; background: #1a2941; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card, .panel {
  background: linear-gradient(180deg, rgba(17,29,48,.98), rgba(11,20,34,.98));
  border: 1px solid var(--border); border-radius: 14px;
}
.metric-card { padding: 18px; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin: 8px 0 5px; font-size: 28px; letter-spacing: -.5px; }
.metric-card small { color: #7f91aa; }
.metric-card.profit strong { color: var(--success); }
.panel { padding: 18px; margin-bottom: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.chart-wrap { height: 320px; position: relative; }
#profit-chart { width: 100%; height: 100%; display: block; }
.empty-state { color: var(--muted); text-align: center; padding: 34px 12px; }
.chart-wrap .empty-state { position: absolute; inset: 0; display: grid; place-items: center; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 13px 10px; text-align: left; border-top: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 650; }
td { color: #dce5f0; }
td.profit-cell { color: var(--success); font-weight: 700; }
.delete-btn { border: 0; background: transparent; color: #7f91aa; padding: 5px 8px; border-radius: 7px; }
.delete-btn:hover { color: var(--danger); background: rgba(255,107,107,.08); }

dialog {
  border: 1px solid var(--border); border-radius: 16px;
  background: #0d1626; color: var(--text); width: min(520px, calc(100vw - 28px));
  padding: 0; box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
dialog::backdrop { background: rgba(2,7,14,.72); backdrop-filter: blur(4px); }
dialog form { padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.dialog-head p { color: var(--muted); margin-bottom: 0; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 28px; line-height: 1; }
label { display: grid; gap: 8px; color: #c8d3e2; font-size: 13px; margin: 14px 0; }
input {
  width: 100%; background: #08101d; color: white;
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46,124,246,.14); }
.preview {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin: 18px 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px;
  background: #09111e;
}
.preview div { display: grid; gap: 4px; }
.preview span { color: var(--muted); font-size: 12px; }
.preview strong { font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 20px; }
}
@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .filters { justify-content: flex-start; overflow-x: auto; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metric-card strong { font-size: 25px; }
  .preview { grid-template-columns: 1fr 1fr; }
}


/* ===== V2 microinteractions ===== */
.metric-card {
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.metric-card:hover {
  transform: translateY(-3px);
  border-color: #314a6d;
  box-shadow: 0 12px 28px rgba(0,0,0,.18);
}
.btn, .period-tabs button, .nav-item {
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:active, .period-tabs button:active {
  transform: scale(.98);
}
.panel {
  transition: border-color .18s ease;
}
.panel:hover {
  border-color: #2a3d59;
}
#profit-chart {
  cursor: crosshair;
}
.chart-tooltip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -115%) scale(.96);
  transition: opacity .12s ease, transform .12s ease;
  background: rgba(6, 12, 22, .96);
  border: 1px solid #2b405f;
  color: #fff;
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,.35);
  white-space: nowrap;
}
.chart-tooltip.show {
  opacity: 1;
  transform: translate(-50%, -115%) scale(1);
}
.chart-tooltip .date {
  color: #8ea0b8;
  margin-bottom: 3px;
}
.chart-tooltip .value {
  font-weight: 800;
  font-size: 14px;
}
.chart-tooltip .value.positive { color: #12c889; }
.chart-tooltip .value.negative { color: #ff6b6b; }
.chart-tooltip .value.neutral { color: #dce5f0; }

.metric-card.profit strong.negative,
.profit-cell.negative {
  color: var(--danger) !important;
}
.metric-card.profit strong.neutral,
.profit-cell.neutral {
  color: #dce5f0 !important;
}
.metric-card.profit strong.positive,
.profit-cell.positive {
  color: var(--success) !important;
}

@keyframes numberPop {
  0% { transform: translateY(3px); opacity: .4; }
  100% { transform: translateY(0); opacity: 1; }
}
.metric-card strong.animate-number {
  animation: numberPop .24s ease;
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
tbody tr {
  animation: rowIn .22s ease both;
}
tbody tr:hover td {
  background: rgba(255,255,255,.018);
}
