/* ============================================================================
   BCS-CONNECT operations panel — design system (refined dark, modern SaaS)
   App-shell layout: fixed left sidebar + sticky topbar + content.
   Class names are kept stable so existing templates render unchanged.
   ============================================================================ */

:root {
  /* Surfaces (deepest -> elevated) */
  --bg:          #0b0e14;
  --bg-sidebar:  #0c1018;
  --surface:     #131826;
  --surface-2:   #19202f;
  --surface-3:   #20293b;
  --hover:       #1c2434;

  /* Lines */
  --line:        #232c3d;
  --line-strong: #2f3a4f;

  /* Text */
  --fg:          #e8edf6;
  --muted:       #94a2b8;
  --dim:         #647288;

  /* Brand / accent */
  --accent:      #5b93ff;
  --accent-2:    #4079f2;
  --accent-soft: rgba(91, 147, 255, .14);
  --accent-line: rgba(91, 147, 255, .35);

  /* Status */
  --online:       #34d399;
  --online-soft:  rgba(52, 211, 153, .14);
  --offline:      #6b7a90;
  --offline-soft: rgba(107, 122, 144, .16);
  --danger:       #f87171;
  --danger-soft:  rgba(248, 113, 113, .14);
  --warning:      #fbbf24;
  --warning-soft: rgba(251, 191, 36, .14);
  --info:         #60a5fa;
  --info-soft:    rgba(96, 165, 250, .14);

  /* Radii */
  --r-sm: 7px;
  --r:    11px;
  --r-lg: 16px;
  --pill: 999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow:    0 4px 16px -4px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 18px 48px -12px rgba(0,0,0,.6);

  --t: 140ms cubic-bezier(.4,0,.2,1);
  --sidebar-w: 244px;
  --content-max: 1180px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color var(--t); }
a:hover { color: #8fb4ff; }

code, .mono {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--surface-3);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 6px;
  color: #c7d3e6;
}
.muted { color: var(--muted); }

h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0 0 4px; display: flex; align-items: center; gap: 12px; }
h2 {
  font-size: 12px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .08em;
  margin: 30px 0 12px;
}

/* Custom scrollbars (webkit) */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #3a475e; }

/* ============================================================================
   App shell
   ============================================================================ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 16px;
  font-weight: 700; font-size: 15px; letter-spacing: .2px; color: var(--fg);
}
.sidebar .brand .mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 4px 12px -2px var(--accent-line);
}
.sidebar .brand .mark svg { width: 16px; height: 16px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 500;
  transition: background var(--t), color var(--t);
}
.nav a svg { width: 17px; height: 17px; flex: none; stroke-width: 1.9; opacity: .85; }
.nav a:hover { background: var(--hover); color: var(--fg); }
.nav a.active { background: var(--accent-soft); color: #cfe0ff; }
.nav a.active svg { opacity: 1; color: var(--accent); }

.sidebar .side-foot { margin-top: auto; padding: 12px 11px 4px; border-top: 1px solid var(--line); color: var(--dim); font-size: 11px; }

/* Main column */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 26px; height: 56px;
  background: rgba(11,14,20,.78);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .crumb { color: var(--muted); font-weight: 500; font-size: 13px; }
.topbar .spacer { flex: 1; }
.topbar .live { display: inline-flex; align-items: center; gap: 7px; color: var(--dim); font-size: 12px; }
.topbar .live::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--online); box-shadow: 0 0 0 0 var(--online-soft);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.4); } 70% { box-shadow: 0 0 0 6px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } }

.topbar .who { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.topbar .who .role,
.badge.role {
  background: var(--accent-soft); color: #aecbff; border: 1px solid var(--accent-line);
  border-radius: var(--pill); padding: 2px 9px; font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.logout-form { margin: 0; }

.page { padding: 26px; max-width: var(--content-max); width: 100%; margin: 0 auto; }
.content { padding: 26px; max-width: var(--content-max); margin: 0 auto; } /* legacy alias */
.back { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.back:hover { color: var(--fg); }

/* ============================================================================
   Buttons
   ============================================================================ */
.btn, .btn-action {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--r-sm); padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  border: 1px solid transparent; transition: all var(--t);
}
.btn { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--accent-2); }
.btn:active { transform: translateY(1px); }

.btn-action { background: var(--surface-2); border-color: var(--line-strong); color: var(--fg); }
.btn-action:hover { border-color: var(--accent-line); background: var(--surface-3); color: #fff; }
.btn-action:active { transform: translateY(1px); }

.btn-link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font: inherit; font-weight: 600; padding: 4px 2px;
  transition: color var(--t);
}
.btn-link:hover { color: #8fb4ff; }
.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { color: #ff9b9b; }

:where(button, a, input, select):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm);
}

/* ============================================================================
   Page header (optional, used by templates with an explicit header)
   ============================================================================ */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head .ph-text { flex: 1; min-width: 0; }
.page-head .lede { color: var(--muted); font-size: 13px; margin: 0; max-width: 70ch; }

/* ============================================================================
   Summary / stat cards
   ============================================================================ */
.summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 24px; }
.summary .card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px 20px; min-width: 124px;
  box-shadow: var(--shadow-sm); transition: border-color var(--t), transform var(--t);
}
.summary .card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.summary .card .num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.summary .card .lbl { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; margin-top: 3px; }
.summary .card.online .num { color: var(--online); }
.summary .card.offline .num { color: var(--offline); }
.summary .versions { min-width: 220px; }
.summary .versions .lbl { margin-bottom: 6px; }
.summary .versions ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.summary .versions li { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.summary .versions li span { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ============================================================================
   Tables
   ============================================================================ */
table { width: 100%; border-collapse: collapse; }
table.devices, table.mini {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm);
}
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  background: var(--surface-2); color: var(--dim);
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
}
tbody tr { transition: background var(--t); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }
tbody tr.is-offline { color: var(--muted); }
tbody tr.is-offline:hover { color: var(--fg); }
td.empty {
  color: var(--dim); text-align: center; padding: 40px 16px; font-size: 13px;
}

.dev-link { display: inline-flex; flex-direction: column; gap: 1px; }
.dev-link strong { font-weight: 600; color: var(--fg); }
.dev-link .muted { font-size: 12px; font-variant-numeric: tabular-nums; }
td .mono, td code { font-variant-numeric: tabular-nums; }

/* ============================================================================
   Badges / status pills (with leading dot)
   ============================================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--pill);
  font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: capitalize;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.role::before, .badge.pending::before { display: none; }

.badge.online,  .badge.done,   .badge.active   { background: var(--online-soft);  color: var(--online);  border-color: rgba(52,211,153,.25); }
.badge.offline, .badge.disabled                { background: var(--offline-soft); color: #9aa8bd;        border-color: var(--line-strong); }
.badge.updating, .badge.sent                    { background: var(--info-soft);    color: var(--info);    border-color: rgba(96,165,250,.25); }
.badge.pending                                   { background: var(--surface-3);    color: var(--muted);   border-color: var(--line-strong); }
.badge.failed                                    { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(248,113,113,.28); }

.fail-count { color: var(--danger); font-weight: 600; }
.note { color: var(--dim); font-size: 12.5px; margin-top: 14px; }

/* ============================================================================
   Device detail grid
   ============================================================================ */
.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1px; background: var(--line); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm);
}
.detail-grid > div { background: var(--surface); padding: 13px 16px; display: flex; flex-direction: column; gap: 4px; }
.detail-grid .k { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.detail-grid .v { font-size: 14px; }
table.mini { margin-top: 10px; }

.actions-bar { margin: 22px 0 4px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ============================================================================
   Forms: card-form, inline edit forms, user-form
   ============================================================================ */
.card-form {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px 22px; margin: 18px 0 26px; box-shadow: var(--shadow-sm);
}
.card-form h2 { margin-top: 0; }

.user-form { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.user-form label, .login-card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .05em;
}
input, select, .user-form input, .user-form select {
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 9px 12px; color: var(--fg); font: inherit; min-width: 0;
  transition: border-color var(--t), box-shadow var(--t);
}
input::placeholder { color: var(--dim); }
input:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

td.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
form.inline { margin: 0; display: inline-flex; gap: 6px; align-items: center; }
form.inline select, form.inline input {
  padding: 6px 9px; font-size: 12.5px; border-radius: var(--r-sm);
}
form.inline.reset input { width: 130px; }

/* ============================================================================
   Login
   ============================================================================ */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(91,147,255,.10), transparent 70%),
    var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 34px 30px; width: 340px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand-row { display: flex; align-items: center; gap: 11px; margin-bottom: 2px; }
.login-card .mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px -3px var(--accent-line);
}
.login-card .mark svg { width: 19px; height: 19px; }
.login-card h1 { font-size: 19px; margin: 0; }
.login-card .sub { color: var(--muted); margin: -8px 0 10px; font-size: 13px; }
.login-card .btn { margin-top: 8px; padding: 11px; }

/* ============================================================================
   Alerts
   ============================================================================ */
.error {
  background: var(--danger-soft); border: 1px solid rgba(248,113,113,.4);
  color: #fecaca; border-radius: var(--r-sm); padding: 10px 13px; font-size: 13px;
}

/* ============================================================================
   Responsive: collapse sidebar into a top strip on narrow screens
   ============================================================================ */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; height: auto; width: 100%;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 8px 12px; overflow-x: auto;
  }
  .sidebar .brand { padding: 6px 8px; }
  .sidebar .brand .label { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav a span { display: none; }
  .nav a { padding: 9px; }
  .sidebar .side-foot { display: none; }
  .topbar { top: 0; padding: 0 16px; }
  thead th { top: 0; }
  .page, .content { padding: 18px 14px; }
}
