body {
  font-family: sans-serif;
  margin: 0px;
}

/* Toast notifications */

#toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 16px;
  border-radius: 6px;
  font-size: 88%;
  min-width: 320px;
  max-width: 620px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  pointer-events: all;
  animation: toast-in 0.18s ease;
  transition: opacity 0.3s ease;
  background: #1e1e1e;
  color: #eee;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast-message {
  border-left: 3px solid #4a9;
}

.toast-error {
  border-left: 3px solid #c44;
}

.toast-body {
  flex: 1;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #888;
  font-size: 105%;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.toast-close:hover {
  color: #eee;
}

/* Login */

.login-page {
  display: flex;
  justify-content: center;
  padding-top: 5em;
}

.login-card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 2em 2.5em 1.8em;
  min-width: 280px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.08);
}

.login-card .form-row label:first-child {
  width: 90px;
}

.login-card .form-row input[type="text"],
.login-card .form-row input[type="password"] {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 95%;
  width: 180px;
}

.login-error {
  color: #b22222;
  margin: 0 0 1em;
  font-size: 0.9em;
}

.timestamp {
  font-family: monospace;
}

.code {
  font-family: monospace;
}

#header {
  background-color: #1a1a1a;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 1.5em;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.header-appname {
  font-size: 115%;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: white;
}

.header-sep {
  color: #555;
}

.header-page {
  font-size: 90%;
  color: #999;
}

.header-nav {
  display: flex;
  align-items: stretch;
  height: 48px;
}

.nav-link,
.nav-user {
  display: flex;
  align-items: center;
  padding: 0 1.1em;
  border-left: 1px solid #2e2e2e;
  font-size: 82%;
  white-space: nowrap;
}

.nav-link {
  color: #bbb;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.nav-link:hover {
  background-color: #2a2a2a;
  color: white;
}

.nav-logout {
  color: #d88;
}

.nav-logout:hover {
  background-color: #2a1a1a;
  color: #fcc;
}

.nav-user {
  color: #666;
  cursor: default;
}

#content {
  width: 90%;
  margin: 0 auto;
}

.buttons {
  text-align: right;
}

.buttons input {
  background: #eee;
  border: 1px solid #ccc;
  border-radius: .3em;
  padding: .3em;
  margin: .3em;
  cursor: pointer;
}

.positions {
  display: flex;
  flex-direction: column;
}

.positions th {
  padding: 8px 15px;
  margin: 5px;
  text-align: left;
  color: white;
  background-color: black;
}

.positions td {
  padding: 0 15px;
  text-align: left;
}

.positions a {
  text-decoration: none;
  color: black
}

.positions tbody tr:hover {
  background-color: #e0e0e0;
}

.positions .controls {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.space {
  flex-grow: 1;
}

.positions .control {
  padding: 8px 15px;
  margin: 5px;
  text-decoration: none;
  color: #333;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 5px;
  transition: background-color 0.2s;
}

.positions .control.active {
  background-color: black;
  color: white;
  border-color: black;
  font-weight: bold;
}

.positions .control:hover {
  background-color: #e0e0e0;
}

.positions .control.active:hover {
  background-color: #333;
}

.chart .parameters {
  display: flex;
  flex-direction: row;
  justify-content: left;
}

.chart .control {
  padding: 8px 15px;
  margin: 1em;
  accent-color: black;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 5px;
  transition: background-color 0.2s;
}

.chart .market {
  margin: 1em;
  padding: 0.2em 1em;
  border: 1px solid black;
  border-radius: 1em;
}

.chart .exchange {
  font-size: 110%;
}

.chart .symbol {
  font-weight: bold;
  font-size: 150%;
}

/* Systems ──────────────────────────────────────────────────────────────────── */

/* Selettore sistema */

.system-selector {
  margin: 1.5em 0 0.5em;
}

.system-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.system-btn {
  padding: 6px 14px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background-color: #f0f0f0;
  color: #333;
  text-decoration: none;
  font-size: 90%;
  cursor: pointer;
  transition: background-color 0.15s;
}

.system-btn:hover {
  background-color: #ddd;
}

.system-btn.active {
  background-color: black;
  color: white;
  border-color: black;
  font-weight: bold;
}

.system-btn.new-btn {
  border-style: dashed;
  color: #555;
}

.new-system-form {
  margin-top: 0.6em;
}

.new-system-form input[type="text"] {
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 90%;
}

.new-system-form button {
  padding: 5px 12px;
  margin-left: 4px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #f0f0f0;
  cursor: pointer;
}

/* System detail */

.system-detail {
  margin-top: 1.5em;
}

.system-title {
  margin: 0 0 0.8em;
  font-size: 130%;
}

.system-title-row {
  display: flex;
  align-items: baseline;
  gap: 1.2em;
  margin-bottom: 0.8em;
}

.system-title-row .system-title {
  margin: 0;
}

.delete-btn {
  padding: 4px 14px;
  background-color: white;
  color: #b00020;
  border: 1px solid #b00020;
  border-radius: 4px;
  cursor: pointer;
  font-size: 85%;
  transition: background-color 0.15s, color 0.15s;
}

.delete-btn:hover {
  background-color: #b00020;
  color: white;
}

.section-heading {
  margin: 1.6em 0 0.5em;
  font-size: 100%;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #555;
  border-bottom: 1px solid #ddd;
  padding-bottom: 3px;
}

.empty-note {
  color: #666;
  font-style: italic;
}

.options-table {
  border-collapse: collapse;
  margin-bottom: 1.5em;
}

.options-table th {
  padding: 6px 20px 6px 0;
  text-align: left;
  color: white;
  background-color: black;
  padding: 6px 20px;
}

.options-table td {
  padding: 5px 20px 5px 0;
  border-bottom: 1px solid #e8e8e8;
  padding: 5px 20px;
}

.options-table tbody tr:hover {
  background-color: #f5f5f5;
}

/* Form inserimento riga */

.add-option-form {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1.2em 1.5em;
  background: #fafafa;
  display: inline-block;
  min-width: 380px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 1em;
  margin-bottom: 0.8em;
}

.form-row label:first-child {
  width: 80px;
  font-weight: bold;
  font-size: 90%;
  flex-shrink: 0;
}

.form-row input[type="text"],
.form-row input[type="datetime-local"] {
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 90%;
}

.form-row input.code-input {
  font-family: monospace;
}

.options-table th.num,
.options-table td.num {
  text-align: right;
  font-family: monospace;
}

.trading-radios {
  display: flex;
  gap: 12px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.radio-label input[type="radio"] {
  accent-color: black;
}

.form-buttons {
  margin-top: 0.4em;
  justify-content: flex-end;
}

.add-btn {
  padding: 6px 18px;
  background-color: #222;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 90%;
  transition: background-color 0.15s;
}

.add-btn:hover {
  background-color: #444;
}

/* Account mode badge */

.account-mode-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 75%;
  font-weight: bold;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

.account-mode-live {
  background-color: #c8efc8;
  color: #1a6b1a;
}

.account-mode-paper {
  background-color: #e0e8ff;
  color: #1a3a8b;
}

/* Badge stato trading */

.trading-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 85%;
  font-weight: bold;
  letter-spacing: 0.05em;
}

.trading-enable {
  background-color: #c8efc8;
  color: #1a6b1a;
}

.trading-reduce {
  background-color: #ffeeba;
  color: #8a6000;
}

.trading-disable {
  background-color: #f5c6cb;
  color: #8b0000;
}

.trading-unknown {
  background-color: #e8e8e8;
  color: #666;
}

/* Positions ────────────────────────────────────────────────────────────────── */

.snapshot-label {
  font-size: 78%;
  font-weight: normal;
  color: #999;
  margin-left: 0.5em;
}

.snapshot-reset {
  font-size: 78%;
  font-weight: normal;
  margin-left: 0.8em;
  color: #888;
}

.snapshot-reset:hover {
  color: #333;
}

.pos-table td.bar-cell {
  padding-right: 0;
}

.pos-bar-container {
  width: 200px;
  height: 13px;
  background: #ebebeb;
  border-radius: 2px;
  position: relative;
}

.pos-bar-center {
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: #bbb;
}

.pos-bar {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 2px;
}

.pos-bar-long {
  left: 50%;
  background: #4a9a4a;
}

.pos-bar-short {
  right: 50%;
  background: #c44;
}

.pos-long {
  color: #1a6b1a;
}

.pos-short {
  color: #8b0000;
}

.pos-closed {
  color: #aaa;
  font-style: italic;
}

.dir-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 78%;
  font-weight: bold;
  letter-spacing: 0.04em;
}

.dir-long {
  background: #c8efc8;
  color: #1a6b1a;
}

.dir-short {
  background: #f5c6cb;
  color: #8b0000;
}

.dir-flat {
  background: #e8e8e8;
  color: #888;
}

.log-active {
  background-color: #f0f4ff !important;
}

.log-link {
  color: inherit;
  text-decoration: none;
}

.log-link:hover {
  text-decoration: underline;
  color: #334;
}

/* Pager */

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0.5em 0;
  font-size: 86%;
}

.pager-btn {
  padding: 3px 11px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f0f0f0;
  color: #333;
  text-decoration: none;
  transition: background-color 0.15s;
}

.pager-btn:hover:not(.disabled) {
  background: #ddd;
}

.pager-btn.disabled {
  color: #bbb;
  cursor: default;
}

.pager-info {
  color: #777;
}

/* Account summary */

.title-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.balance-card {
  display: flex;
  gap: 2.5em;
  align-items: flex-end;
  margin-bottom: 0.75em;
  flex-wrap: wrap;
}

.balance-label {
  font-size: 80%;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.balance-value {
  font-size: 200%;
  font-weight: bold;
  font-family: monospace;
}

.balance-value-secondary {
  font-size: 140%;
  color: #555;
}

.balance-asset {
  font-size: 90%;
  color: #666;
  margin-left: 0.3em;
}

.last-updated {
  font-size: 82%;
  color: #888;
  margin-bottom: 1em;
}

.ledger-table {
  width: auto;
}

.ledger-pos {
  color: #2a7a2a;
}

.ledger-neg {
  color: #b22222;
}

/* Dashboard metric cards */

.metric-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 1.2em;
}

.metric-card {
  background: #f7f7f7;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 8px 14px;
  min-width: 120px;
}

.metric-label {
  font-size: 75%;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}

.metric-value {
  font-size: 115%;
  font-weight: bold;
  font-family: monospace;
  white-space: nowrap;
}

.metric-asset {
  font-size: 80%;
  font-weight: normal;
  color: #777;
}

.metric-sub {
  font-size: 78%;
  color: #aaa;
  font-family: monospace;
  margin-top: 1px;
}

.metric-pos {
  border-left: 3px solid #2a7a2a;
}

.metric-pos .metric-value {
  color: #2a7a2a;
}

.metric-neg {
  border-left: 3px solid #b22222;
}

.metric-neg .metric-value {
  color: #b22222;
}

.chart-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 1.2em;
}

.chart-box {
  flex: 1 1 300px;
  min-width: 0;
  height: 200px;
  background: #fafafa;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  padding: 10px 12px 8px;
  box-sizing: border-box;
}

.chart-label {
  font-size: 75%;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.chart-box canvas {
  width: 100% !important;
  height: calc(100% - 18px) !important;
}