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

:root {
  --bg: #0f1117;
  --surface: #1a1d23;
  --surface2: #22262f;
  --border: #2d3139;
  --text: #e2e8f0;
  --muted: #64748b;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
}

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

/* ── Auth ── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 360px;
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 28px;
  text-align: center;
}

/* ── Form elements ── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 68px; }

/* ── Buttons ── */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  transition: opacity 0.15s;
}
button:hover:not(:disabled) { opacity: 0.82; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; font-weight: 500; }
.btn-primary-full { width: 100%; padding: 10px; }
.btn-danger  { background: var(--red);    color: #fff; }
.btn-ghost   { background: transparent;   color: var(--muted); border: 1px solid var(--border); }
.btn-sm      { padding: 4px 10px; font-size: 12px; }

/* ── Misc ── */
.error {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  color: var(--red);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.hidden { display: none !important; }

/* ── App layout ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 16px; font-weight: 600; }

.main { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar .field { margin-bottom: 0; min-width: 120px; flex: 1; }
.toolbar-right  { margin-left: auto; }

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface); }
th {
  text-align: left;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

.td-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-buy  { background: rgba(34,197,94,.15);  color: var(--green); }
.badge-sell { background: rgba(239,68,68,.15);  color: var(--red);   }

/* ── Result colors ── */
.result-pos { color: var(--green); font-weight: 500; }
.result-neg { color: var(--red);   font-weight: 500; }
.result-nil { color: var(--muted); }

/* ── Empty / loading ── */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty p { margin-top: 8px; font-size: 13px; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close { background: transparent; color: var(--muted); font-size: 18px; padding: 4px 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }

/* ── Sortable table headers ── */
.th-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.th-sortable:hover { color: var(--text); }
.th-sorted { color: var(--accent) !important; }
.sort-icon { font-size: 10px; color: var(--muted); margin-left: 2px; }
.th-sorted .sort-icon { color: var(--accent); }

/* ── Nav links ── */
.nav-links { display: flex; gap: 2px; align-items: center; }
.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--accent); }

/* ── Stats page ── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 16px;
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat-sub   { font-size: 12px; color: var(--muted); margin-top: 5px; }

.stat-section       { margin-bottom: 28px; }
.stat-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 10px;
}

.bar-cell { min-width: 80px; }
.bar-track {
  background: var(--surface2);
  border-radius: 3px;
  height: 6px;
  overflow: hidden;
}
.bar-pos { background: var(--green); height: 100%; border-radius: 3px; }
.bar-neg { background: var(--red);   height: 100%; border-radius: 3px; }
.bar-neu { background: var(--accent); height: 100%; border-radius: 3px; }

/* ── Stat link ── */
.stat-link { color: inherit; text-decoration: none; cursor: pointer; }

/* ── Day separator ── */
.day-sep td {
  background: var(--surface);
  padding: 5px 14px;
  border-top: 2px solid var(--border);
  width: 100%;
}
.day-sep:hover td { background: var(--surface); }
.day-sep-inner { display: flex; flex-direction: column; gap: 3px; width: 100%; }
.day-sep-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  min-width: 110px;
  flex-shrink: 0;
}
.day-sep-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text);
  opacity: 0.75;
  word-break: break-word;
  white-space: pre-wrap;
}
.day-sep-add {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 2px 6px;
}
.day-sep-add:hover { border-color: var(--accent); color: var(--accent); }
.day-sep-ta {
  flex: 1;
  min-height: 108px;
  max-height: 360px;
  resize: vertical;
  font-size: 13px;
  padding: 4px 8px;
}
.day-sep-actions { display: flex; gap: 6px; align-items: center; }

/* ── Trend matrix ── */
.trend-matrix th { text-align: center; }
.trend-matrix th:first-child { text-align: left; }
.trend-matrix .tm-group-header { background: var(--surface2); font-size: 10px; }
.trend-cell { text-align: center; vertical-align: middle; min-width: 90px; }
.trend-cell.trend-empty { color: var(--muted); text-align: center; }
.tc-count { font-size: 15px; font-weight: 600; line-height: 1.2; }
.tc-wr    { font-size: 12px; margin-top: 2px; }
.tc-avg   { font-size: 11px; color: var(--muted); margin-top: 1px; }
.trend-matrix .tm-row-label { white-space: nowrap; font-weight: 500; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}
