/* ============================================================================
   FiniteManager Web Console — cockpit dark theme
   Shared design system. Feature pages should use these tokens/classes and NOT
   hard-code colors, so the console reads as one surface.
   ============================================================================ */

:root {
  /* base surfaces */
  --bg:            #0a0e14;
  --bg-elev:       #111721;
  --panel:         #141b26;
  --panel-2:       #1a2230;
  --panel-3:       #202b3b;
  --line:          #26303f;
  --line-soft:     #1d2634;

  /* text */
  --fg:            #e6edf6;
  --fg-dim:        #9fb0c3;
  --fg-faint:      #6b7c91;
  --fg-invert:     #0a0e14;

  /* brand + accents */
  --accent:        #4da3ff;
  --accent-2:      #7c5cff;
  --accent-soft:   rgba(77,163,255,0.14);
  --ok:            #3fd08a;
  --ok-soft:       rgba(63,208,138,0.14);
  --warn:          #f5b544;
  --warn-soft:     rgba(245,181,68,0.14);
  --danger:        #ff5d6c;
  --danger-soft:   rgba(255,93,108,0.14);
  --info:          #4da3ff;

  /* geometry */
  --radius:        10px;
  --radius-sm:     7px;
  --radius-lg:     14px;
  --gap:           16px;
  --sidebar-w:     232px;
  --topbar-h:      54px;

  --shadow:        0 8px 30px rgba(0,0,0,0.45);
  --shadow-sm:     0 2px 10px rgba(0,0,0,0.35);

  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124,92,255,0.08), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, rgba(77,163,255,0.07), transparent 55%),
    var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: 0 0 .8em; }
code, kbd, pre { font-family: var(--mono); }

/* ---- scrollbars ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #2b3a4f; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================ app shell */
#fm-app { min-height: 100%; display: flex; flex-direction: column; }

.fm-topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: rgba(17,23,33,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.fm-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; }
.fm-brand .fm-logo {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800;
  box-shadow: 0 2px 12px rgba(77,163,255,0.4);
}
.fm-brand small { color: var(--fg-faint); font-weight: 500; font-size: 11px; }
.fm-topbar-spacer { flex: 1; }
.fm-topbar .fm-status-pills { display: flex; gap: 8px; align-items: center; }

.fm-shell { flex: 1; display: flex; min-height: 0; }

.fm-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.fm-nav-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-faint); padding: 12px 10px 5px; }
.fm-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--fg-dim); cursor: pointer; user-select: none;
  font-weight: 500; font-size: 13.5px;
  border: 1px solid transparent;
}
.fm-nav-item:hover { background: var(--panel); color: var(--fg); text-decoration: none; }
.fm-nav-item.active { background: var(--accent-soft); color: var(--fg); border-color: rgba(77,163,255,0.28); }
.fm-nav-item .fm-nav-icon { width: 18px; text-align: center; font-size: 15px; opacity: .9; }

.fm-main { flex: 1; min-width: 0; overflow-y: auto; }
.fm-page { max-width: 1180px; margin: 0 auto; padding: 22px 26px 60px; }
.fm-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.fm-page-head .fm-page-title h1 { margin-bottom: 2px; }
.fm-page-head .fm-page-sub { color: var(--fg-faint); font-size: 13px; }
.fm-page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================ cards / grid */
.fm-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-elev));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.fm-card.pad-lg { padding: 22px; }
.fm-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.fm-grid { display: grid; gap: var(--gap); }
.fm-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.fm-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.fm-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.fm-stack { display: flex; flex-direction: column; gap: var(--gap); }
.fm-row { display: flex; gap: 10px; align-items: center; }
.fm-row.wrap { flex-wrap: wrap; }
.fm-spacer { flex: 1; }

/* stat tile */
.fm-stat { display: flex; flex-direction: column; gap: 3px; }
.fm-stat .fm-stat-label { color: var(--fg-faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.fm-stat .fm-stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.fm-stat .fm-stat-hint { color: var(--fg-dim); font-size: 12px; }

/* ============================================================ buttons */
.fm-btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--fg);
  border: 1px solid var(--line);
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
  white-space: nowrap; text-decoration: none;
}
.fm-btn:hover { background: var(--panel-3); text-decoration: none; }
.fm-btn:active { transform: translateY(1px); }
.fm-btn:disabled { opacity: .5; cursor: not-allowed; }
.fm-btn.primary { background: linear-gradient(180deg, var(--accent), #3f8fe6); border-color: transparent; color: #fff; }
.fm-btn.primary:hover { filter: brightness(1.07); }
.fm-btn.danger { background: var(--danger-soft); border-color: rgba(255,93,108,0.4); color: #ffb3ba; }
.fm-btn.danger:hover { background: rgba(255,93,108,0.22); }
.fm-btn.ghost { background: transparent; }
.fm-btn.ghost:hover { background: var(--panel); }
.fm-btn.sm { padding: 5px 10px; font-size: 12px; }
.fm-btn.icon { padding: 7px 9px; }

/* ============================================================ forms */
.fm-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.fm-field label { font-size: 12.5px; color: var(--fg-dim); font-weight: 600; }
.fm-field .fm-hint { font-size: 11.5px; color: var(--fg-faint); }
.fm-input, .fm-select, .fm-textarea {
  width: 100%; padding: 9px 11px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 13.5px;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.fm-input:focus, .fm-select:focus, .fm-textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.fm-textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
.fm-input.mono { font-family: var(--mono); }
select.fm-select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--fg-faint) 50%), linear-gradient(135deg, var(--fg-faint) 50%, transparent 50%); background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

/* ============================================================ badges / pills */
.fm-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--panel-2); color: var(--fg-dim);
  border: 1px solid var(--line);
}
.fm-badge.ok { background: var(--ok-soft); color: #7fe6b4; border-color: rgba(63,208,138,0.3); }
.fm-badge.warn { background: var(--warn-soft); color: #ffd489; border-color: rgba(245,181,68,0.3); }
.fm-badge.danger { background: var(--danger-soft); color: #ffb3ba; border-color: rgba(255,93,108,0.3); }
.fm-badge.info { background: var(--accent-soft); color: #a8d3ff; border-color: rgba(77,163,255,0.3); }
.fm-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex-shrink: 0; }
.fm-dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(63,208,138,0.6); }
.fm-dot.warn { background: var(--warn); }
.fm-dot.danger { background: var(--danger); }
.fm-dot.pulse { animation: fm-pulse 1.6s ease-in-out infinite; }
@keyframes fm-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ============================================================ tables */
.fm-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.fm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.fm-table th, table.fm-table td { text-align: left; padding: 10px 13px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.fm-table th { color: var(--fg-faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: var(--bg-elev); position: sticky; top: 0; }
table.fm-table tbody tr:hover { background: var(--panel); }
table.fm-table tbody tr:last-child td { border-bottom: none; }
table.fm-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* ============================================================ terminal / logs */
.fm-terminal {
  background: #05080d; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  color: #c7d3e0; white-space: pre-wrap; word-break: break-word;
  overflow-y: auto; max-height: 60vh; min-height: 120px;
}
.fm-terminal .fm-cursor { display: inline-block; width: 8px; height: 15px; background: var(--accent); animation: fm-blink 1s step-start infinite; vertical-align: text-bottom; }
@keyframes fm-blink { 50% { opacity: 0; } }
.fm-terminal .marker { color: var(--accent); font-weight: 600; }

/* ============================================================ toasts */
#fm-toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, 90vw); }
.fm-toast {
  background: var(--panel-2); border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius-sm); padding: 11px 14px; box-shadow: var(--shadow);
  font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
  animation: fm-toast-in .22s ease;
}
.fm-toast.ok { border-left-color: var(--ok); }
.fm-toast.error { border-left-color: var(--danger); }
.fm-toast.warn { border-left-color: var(--warn); }
.fm-toast.info { border-left-color: var(--accent); }
.fm-toast .fm-toast-close { color: var(--fg-faint); cursor: pointer; margin-left: auto; }
@keyframes fm-toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ============================================================ states */
.fm-empty, .fm-loading, .fm-error-box { text-align: center; padding: 40px 20px; color: var(--fg-faint); }
.fm-empty .fm-empty-icon { font-size: 34px; opacity: .5; margin-bottom: 8px; }
.fm-error-box { color: #ffb3ba; }
.fm-spinner { width: 22px; height: 22px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: fm-spin .7s linear infinite; display: inline-block; }
.fm-spinner.lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes fm-spin { to { transform: rotate(360deg); } }
.fm-skeleton { background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 50%, var(--panel) 75%); background-size: 200% 100%; animation: fm-shimmer 1.3s infinite; border-radius: 6px; }
@keyframes fm-shimmer { to { background-position: -200% 0; } }

/* ============================================================ login */
.fm-login-wrap { flex: 1; display: grid; place-items: center; padding: 24px; }
.fm-login-card { width: 100%; max-width: 380px; }
.fm-login-card .fm-brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }
.fm-login-card .fm-logo { width: 34px; height: 34px; font-size: 17px; }

/* ============================================================ misc utils */
.fm-mono { font-family: var(--mono); }
.fm-dim { color: var(--fg-dim); }
.fm-faint { color: var(--fg-faint); }
.fm-small { font-size: 12px; }
.fm-xs { font-size: 11px; }
.fm-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-nowrap { white-space: nowrap; }
.fm-tag { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--panel-3); color: var(--fg-dim); font-size: 11px; font-family: var(--mono); }
.fm-divider { height: 1px; background: var(--line-soft); margin: 14px 0; border: none; }
.fm-kbd { font-family: var(--mono); font-size: 11px; background: var(--panel-3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; }
.fm-hidden { display: none !important; }

/* ============================================================ responsive */
@media (max-width: 900px) {
  .fm-grid.cols-3, .fm-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .fm-sidebar {
    position: fixed; left: 0; top: var(--topbar-h); bottom: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .fm-sidebar.open { transform: translateX(0); }
  .fm-menu-toggle { display: inline-flex !important; }
  .fm-page { padding: 16px 14px 50px; }
}
@media (max-width: 560px) {
  .fm-grid.cols-2, .fm-grid.cols-3, .fm-grid.cols-4 { grid-template-columns: 1fr; }
  .fm-topbar .fm-status-pills .fm-hide-sm { display: none; }
}
.fm-menu-toggle { display: none; }
