@import url("/static/css/fonts.css");

:root {
  --bg: #080a12;
  --bg-2: #0b0e19;
  --panel: rgba(22, 26, 41, 0.58);
  --panel-solid: #12151f;
  --panel-hover: rgba(30, 35, 54, 0.7);
  --border: rgba(150, 160, 205, 0.12);
  --border-strong: rgba(150, 160, 205, 0.24);
  --text: #eceef7;
  --muted: #868fac;
  --muted-2: #5c6482;

  --accent: #7c6fff;
  --accent-soft: rgba(124, 111, 255, 0.14);
  --accent-2: #34e7c4;
  --accent-2-soft: rgba(52, 231, 196, 0.14);
  --danger: #ff5c7c;
  --danger-soft: rgba(255, 92, 124, 0.14);
  --warning: #ffb454;
  --warning-soft: rgba(255, 180, 84, 0.14);

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, sans-serif;

  --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}
body::before {
  width: 640px; height: 640px;
  top: -220px; left: -160px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
}
body::after {
  width: 560px; height: 560px;
  bottom: -240px; right: -160px;
  background: radial-gradient(circle, var(--accent-2), transparent 70%);
  opacity: 0.22;
}

a { color: inherit; }
::selection { background: var(--accent); color: white; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

.layout { display: flex; min-height: 100vh; position: relative; z-index: 1; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  background: rgba(10, 12, 20, 0.6);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 24px rgba(124, 111, 255, 0.45);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand h1 { font-family: var(--font-display); font-size: 15.5px; font-weight: 700; margin: 0; letter-spacing: -0.01em; line-height: 1.2; }
.brand .brand-sub { font-size: 11px; color: var(--muted-2); letter-spacing: 0.04em; text-transform: uppercase; }

.signal-strip { margin: 4px 4px 20px; padding: 12px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); }
.signal-strip .signal-top { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--accent-2); margin-bottom: 8px; font-weight: 500; }
.signal-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); animation: signal-pulse 2.2s ease-out infinite; }
@keyframes signal-pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 231, 196, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(52, 231, 196, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 231, 196, 0); }
}
.signal-strip svg { display: block; width: 100%; height: 28px; }
.signal-strip .signal-path {
  fill: none; stroke: url(#signalGradient); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(124, 111, 255, 0.5));
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  position: relative;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--panel-hover); color: var(--text); }
.nav-link.active { background: linear-gradient(90deg, var(--accent-soft), transparent); color: var(--text); }
.nav-link.active::before {
  content: ""; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.nav-link.active svg { opacity: 1; color: var(--accent-2); }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-footer .nav-link { font-size: 12.5px; color: var(--muted-2); }

.main { flex: 1; padding: 26px 34px 60px; max-width: 1320px; min-width: 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.topbar h1 { font-family: var(--font-display); font-size: 25px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.topbar .topbar-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--accent-2-soft); border: 1px solid rgba(52, 231, 196, 0.25);
  color: var(--accent-2); font-size: 12px; font-weight: 500; white-space: nowrap;
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; backdrop-filter: blur(16px); box-shadow: var(--shadow-glass);
  transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
  position: relative; overflow: hidden;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.card .card-icon {
  position: absolute; top: 16px; right: 16px; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.card .card-icon svg { width: 15px; height: 15px; }
.card .label { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; font-weight: 500; }
.card .value { font-family: var(--font-display); font-size: 27px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.card .value.income { color: var(--accent-2); }
.card .value.expense { color: var(--danger); }
.card .value.warn { color: var(--warning); }
.card .delta { font-size: 12px; margin-top: 6px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.card .delta.up { color: var(--accent-2); }
.card .delta.down { color: var(--danger); }
.card.runway-ok { border-color: rgba(52, 231, 196, 0.3); }
.card.runway-warn { border-color: rgba(255, 180, 84, 0.35); }
.card.runway-danger { border-color: rgba(255, 92, 124, 0.35); }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px; margin-bottom: 18px; backdrop-filter: blur(16px); box-shadow: var(--shadow-glass);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.panel h2 { font-family: var(--font-display); margin: 0; font-size: 15.5px; font-weight: 600; letter-spacing: -0.005em; }
.panel .panel-note { font-size: 12px; color: var(--muted-2); }

.grid-2 { display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted-2); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; user-select: none; white-space: nowrap; }
th.sortable { cursor: pointer; transition: color 0.15s; }
th.sortable:hover { color: var(--text); }
th.sortable .sort-arrow { margin-left: 4px; opacity: 0.5; font-size: 10px; }
th.sortable.active { color: var(--accent-2); }
th.sortable.active .sort-arrow { opacity: 1; }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
td.num { font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500; }
.badge.income { background: var(--accent-2-soft); color: var(--accent-2); }
.badge.expense { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }

.empty-state { text-align: center; padding: 42px 20px; color: var(--muted-2); font-size: 13px; }
.empty-state svg { width: 34px; height: 34px; margin-bottom: 10px; opacity: 0.5; }

.btn {
  background: linear-gradient(135deg, var(--accent), #6355e8); color: white; border: none;
  padding: 10px 18px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 600;
  font-family: var(--font-body); display: inline-flex; align-items: center; gap: 6px;
  transition: filter 0.15s, transform 0.1s; box-shadow: 0 4px 14px rgba(124, 111, 255, 0.25);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.98); }
.btn svg { width: 14px; height: 14px; }
.btn.secondary { background: var(--panel-hover); border: 1px solid var(--border-strong); box-shadow: none; color: var(--text); }
.btn.danger { background: linear-gradient(135deg, var(--danger), #e14563); box-shadow: 0 4px 14px rgba(255, 92, 124, 0.22); }
.btn.small { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); padding: 6px 8px; }
.btn.ghost:hover { color: var(--text); background: var(--panel-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

form.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 9px 11px; color: var(--text); font-size: 13.5px;
  font-family: var(--font-body); transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field input::placeholder { color: var(--muted-2); }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filter-bar .field { min-width: 140px; }
.filter-bar .field.search { flex: 1; min-width: 180px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(4, 5, 10, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity 0.18s var(--ease);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-box {
  background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  padding: 24px; width: 440px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); transform: translateY(8px) scale(0.98);
  transition: transform 0.18s var(--ease);
}
.modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
.modal-box h3 { font-family: var(--font-display); margin: 0 0 16px; font-size: 17px; }
.modal-box .field { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; z-index: 1; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 38px 36px; width: 340px; backdrop-filter: blur(20px); box-shadow: var(--shadow-glass);
}
.login-box .brand { justify-content: center; padding: 0 0 24px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 6px; }
.error-msg { color: var(--danger); font-size: 12.5px; margin-top: 10px; }

.renewal-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; gap: 10px; }
.renewal-item:last-child { border-bottom: none; }
.renewal-item .renewal-name { display: flex; align-items: center; gap: 8px; }
.renewal-item .urgency-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.renewal-item .renewal-meta { color: var(--muted); text-align: right; }

.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.server-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; transition: border-color 0.15s; }
.server-card:hover { border-color: var(--border-strong); }
.server-card .sc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.server-card .sc-name { font-weight: 600; font-size: 14px; }
.server-card .sc-provider { font-size: 12px; color: var(--muted); margin-top: 2px; }
.server-card .sc-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); padding: 4px 0; }
.server-card .sc-row span:last-child { color: var(--text); }
.server-card .sc-actions { display: flex; gap: 6px; margin-top: 12px; }

.text-muted { color: var(--muted); }
.mono-num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.mb-0 { margin-bottom: 0 !important; }
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-solid); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent-2);
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-glass);
  animation: toast-in 0.25s var(--ease);
}
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Page header (используется на страницах) ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 14px; flex-wrap: wrap; }
.page-header h1 { font-family: var(--font-display); font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* Карточка со смещённым акцентом */
.card.accent-rose { border-color: rgba(255, 92, 124, 0.18); }
.card.accent-amber { border-color: rgba(255, 180, 84, 0.22); }

.edit-hint {
  font-size: 11px; color: var(--accent-2); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; margin-left: 6px; font-weight: 500;
}
.edit-hint:hover { color: var(--accent); }

/* Индикатор уровня runway (4 полоски-сигнала) */
.signal-bars { display: inline-flex; gap: 2px; margin-left: 6px; vertical-align: middle; }
.signal-bars i { display: inline-block; width: 3px; border-radius: 2px; background: var(--border-strong); }
.signal-bars i:nth-child(1) { height: 6px; }
.signal-bars i:nth-child(2) { height: 9px; }
.signal-bars i:nth-child(3) { height: 12px; }
.signal-bars i:nth-child(4) { height: 15px; }
.signal-bars.level-1 i:nth-child(1) { background: var(--danger); }
.signal-bars.level-2 i:nth-child(1), .signal-bars.level-2 i:nth-child(2) { background: var(--warning); }
.signal-bars.level-3 i:nth-child(1), .signal-bars.level-3 i:nth-child(2), .signal-bars.level-3 i:nth-child(3) { background: var(--accent-2); }
.signal-bars.level-4 i { background: var(--accent-2); }

.forecast-narrative { font-size: 13.5px; color: var(--muted); line-height: 1.7; }
.forecast-narrative b { color: var(--text); font-weight: 600; }
.forecast-narrative b.bad { color: var(--danger); }
.forecast-narrative b.good { color: var(--accent-2); }

.renewal-item .rname { font-weight: 500; }
.renewal-item .rmeta { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.rdays { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.rdays.soon { background: var(--danger-soft); color: var(--danger); }
.rdays.mid { background: var(--warning-soft); color: var(--warning); }
.rdays.far { background: var(--accent-2-soft); color: var(--accent-2); }

.badge.muted { background: rgba(150, 160, 205, 0.12); color: var(--muted); }

/* Алиас стрелки сортировки, чтобы совпадать с готовыми таблицами */
.arrow { margin-left: 4px; opacity: 0.5; font-size: 10px; }
th.sortable.active .arrow { opacity: 1; color: var(--accent-2); }

/* Тост-контейнер создаётся JS с id, а не классом */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }

.modal-box h2 { font-family: var(--font-display); margin: 0 0 16px; font-size: 17px; font-weight: 600; }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .main { padding: 18px; }
}
