/* ---------------------------------------------------------------------------
   finam-trade-ui — оформление интерфейса.
   Без внешних зависимостей и CDN: строгий CSP запрещает сторонние ресурсы,
   а на VPS не должно быть обращений наружу ради стилей.
   --------------------------------------------------------------------------- */

:root {
  --bg: #10141c;
  --bg-elevated: #161c27;
  --bg-input: #0d111a;
  --border: #263041;
  --border-strong: #35415a;
  --text: #e6ecf5;
  --text-muted: #93a1b8;
  --accent: #4b8dff;
  --accent-hover: #3d7bea;
  --buy: #35c07a;
  --sell: #ff6b6b;
  --warn: #f3b23f;
  --danger: #e5484d;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

/* ------------------------------------------------------------------ шапка --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 58px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-weight: 650;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topbar nav a {
  padding: 7px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}

.topbar nav a:hover {
  background: #1d2534;
  color: var(--text);
}

.topbar nav a.active {
  background: #22304a;
  color: var(--text);
}

.topbar .spacer {
  flex: 1;
}

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

h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

h2 {
  font-size: 17px;
  margin: 0 0 12px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 22px;
  font-size: 14px;
}

/* ------------------------------------------------------------------ блоки --- */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.card.tight {
  padding: 14px 20px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 900px) {
  .grid.cols-4,
  .grid.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat .label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.stat .value {
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- элементы --- */

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

textarea {
  font-family: var(--mono);
  font-size: 13px;
  min-height: 220px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}

button.secondary:hover:not(:disabled) {
  background: #1d2534;
}

button.danger {
  background: var(--danger);
}

button.danger:hover:not(:disabled) {
  background: #c93b40;
}

button.link {
  background: none;
  border: 0;
  color: var(--sell);
  padding: 4px 8px;
  font-size: 13px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row > * {
  flex: 0 0 auto;
}

.field-inline {
  width: 190px;
}

/* ------------------------------------------------------------------ табли --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px;
  border-bottom: 1px solid #1c2432;
  vertical-align: middle;
}

tbody tr:hover {
  background: #18202d;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tr.has-error td {
  background: rgba(229, 72, 77, 0.08);
}

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

/* ------------------------------------------------------------------ метки --- */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.buy {
  background: rgba(53, 192, 122, 0.16);
  color: var(--buy);
}

.badge.sell {
  background: rgba(255, 107, 107, 0.16);
  color: var(--sell);
}

.badge.neutral {
  background: #22304a;
  color: var(--text-muted);
}

.badge.ok {
  background: rgba(53, 192, 122, 0.16);
  color: var(--buy);
}

.badge.warn {
  background: rgba(243, 178, 63, 0.16);
  color: var(--warn);
}

.badge.err {
  background: rgba(229, 72, 77, 0.16);
  color: var(--danger);
}

.badge.pending {
  background: rgba(75, 141, 255, 0.16);
  color: var(--accent);
}

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

.small {
  font-size: 12px;
}

.mono {
  font-family: var(--mono);
}

.pos {
  color: var(--buy);
}

.neg {
  color: var(--sell);
}

/* -------------------------------------------------------------- сообщения --- */

.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid;
}

.alert.error {
  background: rgba(229, 72, 77, 0.1);
  border-color: rgba(229, 72, 77, 0.4);
  color: #ffb3b5;
}

.alert.warn {
  background: rgba(243, 178, 63, 0.1);
  border-color: rgba(243, 178, 63, 0.4);
  color: #f8d79a;
}

.alert.info {
  background: rgba(75, 141, 255, 0.1);
  border-color: rgba(75, 141, 255, 0.4);
  color: #bcd4ff;
}

.alert.ok {
  background: rgba(53, 192, 122, 0.1);
  border-color: rgba(53, 192, 122, 0.4);
  color: #a5e9c6;
}

.alert ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.alert li {
  margin-bottom: 4px;
}

.hidden {
  display: none !important;
}

/* -------------------------------------------------------------- модальное --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  max-width: 620px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h2 {
  margin-top: 0;
}

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

.confirm-list {
  list-style: none;
  padding: 0;
  margin: 14px 0;
}

.confirm-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #1c2432;
  font-variant-numeric: tabular-nums;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 16px;
  font-size: 14px;
}

.checkbox-row input {
  margin-top: 3px;
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.checkbox-row label {
  margin: 0;
  color: var(--text);
  font-size: 14px;
}

/* ---------------------------------------------------------------- статусы --- */

.status-strip {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot.on {
  background: var(--buy);
}

.dot.off {
  background: var(--danger);
}

.dot.warn {
  background: var(--warn);
}

/* --------------------------------------------------------------------- вход --- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px;
}

.login-card h1 {
  font-size: 19px;
  margin-bottom: 6px;
}

.login-card .field {
  margin-bottom: 16px;
}

.login-card button {
  width: 100%;
  padding: 12px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
