/* ─────────────────────────────────────────────────────────────
   PTT Panel v2 – layout and components on top of Bootstrap 5.3
   ───────────────────────────────────────────────────────────── */

:root {
  --ptt-sidebar-w: 264px;
  --ptt-topbar-h: 60px;
  --ptt-accent: #2563eb;
  --ptt-accent-soft: rgba(37, 99, 235, .1);
  --ptt-sidebar-bg: #0f172a;
  --ptt-sidebar-fg: #cbd5e1;
  --ptt-sidebar-muted: #64748b;
  --ptt-sidebar-hover: rgba(255, 255, 255, .06);
  --ptt-page-bg: #f4f6fa;
  --ptt-panel-bg: #ffffff;
  --ptt-border: #e5e7eb;
  --ptt-live: #16a34a;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-primary: var(--ptt-accent);
  --bs-primary-rgb: 37, 99, 235;
  --bs-link-color: var(--ptt-accent);
}

[data-bs-theme="dark"] {
  --ptt-sidebar-bg: #0b1120;
  --ptt-page-bg: #0f1522;
  --ptt-panel-bg: #161e2e;
  --ptt-border: #263042;
  --ptt-accent-soft: rgba(96, 165, 250, .14);
}

[hidden] { display: none !important; }
body { background: var(--ptt-page-bg); font-size: .925rem; }
.btn-primary { --bs-btn-bg: var(--ptt-accent); --bs-btn-border-color: var(--ptt-accent); --bs-btn-hover-bg: #1d4ed8; --bs-btn-hover-border-color: #1d4ed8; }
.min-w-0 { min-width: 0; }
[data-bs-theme="light"] .theme-dark-only, [data-bs-theme="dark"] .theme-light-only { display: none; }

/* ── Shell ─────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; margin-left: var(--ptt-sidebar-w); display: flex; flex-direction: column; }
.content { padding: 24px clamp(16px, 3vw, 32px) 48px; flex: 1; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--ptt-sidebar-w); z-index: 1040;
  background: var(--ptt-sidebar-bg); color: var(--ptt-sidebar-fg);
  display: flex; flex-direction: column; overflow-y: auto; transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff; text-decoration: none; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--ptt-accent); color: #fff; display: grid; place-items: center; font-size: 18px; flex: none; }

.company-switch { margin: 4px 14px 10px; padding: 12px 14px; border-radius: 10px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .07); }
.company-switch-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ptt-sidebar-muted); }
.company-switch-name { color: #fff; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-switch-link { display: inline-flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12.5px; color: #93c5fd; text-decoration: none; }
.company-switch-link:hover { color: #fff; }
.company-switch-empty { display: flex; gap: 10px; font-size: 13px; color: var(--ptt-sidebar-fg); }
.company-switch-empty .bi { font-size: 18px; color: #93c5fd; }

.sidebar-nav { padding: 4px 10px; display: flex; flex-direction: column; gap: 1px; }
.nav-label { padding: 14px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ptt-sidebar-muted); }
.sidebar .nav-link { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; color: var(--ptt-sidebar-fg); text-decoration: none; font-weight: 500; }
.sidebar .nav-link .bi { font-size: 16px; width: 18px; text-align: center; opacity: .85; }
.sidebar .nav-link:hover { background: var(--ptt-sidebar-hover); color: #fff; }
.sidebar .nav-link.active { background: var(--ptt-accent); color: #fff; }
.sidebar .nav-link.active .bi { opacity: 1; }
.sidebar-nav-admin { margin-top: 8px; border-top: 1px solid rgba(255, 255, 255, .07); padding-top: 4px; }
.sidebar-foot { margin-top: auto; padding: 16px 22px; font-size: 11px; color: var(--ptt-sidebar-muted); }
.sidebar-backdrop { display: none; }

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 1030; height: var(--ptt-topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 clamp(16px, 3vw, 32px);
  background: color-mix(in srgb, var(--ptt-panel-bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--ptt-border);
}
.topbar-crumbs { min-width: 0; }
.topbar-crumbs .breadcrumb { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; font-size: 13.5px; }
.topbar-crumbs a { text-decoration: none; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.btn-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; color: var(--bs-body-color); font-size: 18px; padding: 0; }
.btn-icon:hover { background: var(--ptt-accent-soft); }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; font-weight: 500; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--ptt-accent-soft); color: var(--ptt-accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.dropdown-item .bi { width: 20px; }
.env-banner { background: #fef3c7; color: #92400e; font-size: 13px; font-weight: 600; padding: 6px clamp(16px, 3vw, 32px); border-bottom: 1px solid #fde68a; }

/* ── Page header ───────────────────────────────────────────── */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-sub { margin: 4px 0 0; color: var(--bs-secondary-color); }
.page-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.search-box { width: min(320px, 100%); }

/* ── Panels, stats ─────────────────────────────────────────── */
.panel { background: var(--ptt-panel-bg); border: 1px solid var(--ptt-border); border-radius: 12px; padding: 18px 20px; }
.panel-head { display: flex; align-items: center; margin-bottom: 12px; }
.panel-head h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.panel-link { margin-left: auto; font-size: 13px; text-decoration: none; }
.panel .table { --bs-table-bg: transparent; }
.panel .table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--ptt-panel-bg); border: 1px solid var(--ptt-border); border-radius: 12px; padding: 16px 18px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, box-shadow .15s; }
.stat:hover { border-color: var(--ptt-accent); box-shadow: 0 2px 10px var(--ptt-accent-soft); }
.stat-label { font-size: 13px; color: var(--bs-secondary-color); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 1rem; color: var(--bs-secondary-color); font-weight: 500; }

.status-list { list-style: none; margin: 0; padding: 0; }
.status-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--ptt-border); }
.status-list li:last-child { border-bottom: 0; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; }
.status-in_progress { background: var(--ptt-accent); }
.status-completed { background: var(--ptt-live); }
.status-incomplete { background: #f59e0b; }
.status-failed, .status-missed { background: #dc2626; }

/* ── Company picker ────────────────────────────────────────── */
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.company-card { background: var(--ptt-panel-bg); border: 1px solid var(--ptt-border); border-radius: 14px; padding: 18px; color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 16px; transition: border-color .15s, box-shadow .15s, transform .15s; }
.company-card:hover { border-color: var(--ptt-accent); box-shadow: 0 4px 16px var(--ptt-accent-soft); transform: translateY(-1px); }
.company-card-head { display: flex; align-items: center; gap: 12px; }
.company-initial { width: 42px; height: 42px; border-radius: 10px; background: var(--ptt-accent-soft); color: var(--ptt-accent); font-weight: 700; font-size: 18px; display: grid; place-items: center; flex: none; }
.company-card-name { font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-card-city { font-size: 13px; color: var(--bs-secondary-color); }
.company-card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.company-card-stats > div { background: var(--ptt-page-bg); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--bs-secondary-color); font-variant-numeric: tabular-nums; }
.company-card-stats strong { font-size: 1.1rem; color: var(--bs-body-color); }
.company-card-stats span { display: block; }
.company-card-stats .is-live strong { color: var(--ptt-live); }

/* ── Empty states ──────────────────────────────────────────── */
.empty-state { text-align: center; padding: 64px 16px; color: var(--bs-secondary-color); }
.empty-state .bi { font-size: 44px; color: var(--ptt-accent); }
.empty-state h2 { font-size: 1.25rem; color: var(--bs-body-color); margin: 12px 0 6px; }
.empty-inline { padding: 24px 0; text-align: center; color: var(--bs-secondary-color); }

/* ── Auth pages ────────────────────────────────────────────── */
.auth-page { background: radial-gradient(1200px 600px at 10% -10%, var(--ptt-accent-soft), transparent), var(--ptt-page-bg); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
.auth-card { width: min(420px, 100%); background: var(--ptt-panel-bg); border: 1px solid var(--ptt-border); border-radius: 16px; padding: 32px; box-shadow: 0 10px 40px rgba(15, 23, 42, .08); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-brand .brand-name { font-weight: 700; font-size: 1.15rem; }
.brand-sub { font-size: 13px; color: var(--bs-secondary-color); }
.auth-env { font-size: 12px; font-weight: 600; color: #92400e; background: #fef3c7; padding: 4px 10px; border-radius: 99px; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--ptt-accent); }

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); }
  .sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 1035; background: rgba(15, 23, 42, .45); }
  .page-actions { margin-left: 0; width: 100%; }
}

/* ── Two-pane picker ───────────────────────────────────────── */
.dual-list { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.dual-pane { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.dual-title { font-size: 13px; font-weight: 600; color: var(--bs-secondary-color); }
.dual-select { min-height: 220px; }
.dual-buttons { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 575.98px) {
  .dual-list { grid-template-columns: 1fr; }
  .dual-buttons { flex-direction: row; justify-content: center; }
  .dual-buttons .bi { transform: rotate(90deg); }
}

/* ── Status summary ─────────────────────────────────────────── */
.status-table th { white-space: nowrap; }
.status-table tbody tr.status-row { cursor: pointer; }
.status-table tbody tr.status-row:focus-visible { outline: 2px solid var(--ptt-accent); outline-offset: -2px; }
.status-row.open > * { background: var(--ptt-accent-soft); }
.status-caret { display: inline-block; font-size: 11px; color: var(--bs-secondary-color); transition: transform .15s; }
.status-row.open .status-caret { transform: rotate(90deg); color: var(--ptt-accent); }
.status-filters th { padding-top: 0; font-weight: 400; }
.status-filters .form-control, .status-filters .form-select { min-width: 88px; font-size: 12px; }

/* Lights: oval; an unlit light has no border at all */
.led { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 18px; padding: 0 6px; border-radius: 9px;
       font-size: 11px; font-weight: 600; line-height: 1; vertical-align: middle; color: var(--bs-secondary-color);
       background: rgba(148,163,184,.22); border: 0; }   /* greyed-out placeholder when unlit, no border */
.led-pct   { min-width: 42px; height: 22px; border-radius: 11px; }
.led-pct.has-value { border: 1.5px solid var(--ptt-accent); background: transparent; color: var(--bs-body-color); }
.led-pct.has-value.led-amber { background: #f5b301; border-color: #f5b301; color: #1f2937; }
.led-green { background: var(--ptt-live); box-shadow: 0 0 8px rgba(22,163,74,.55); }
.led-amber { background: #f5b301; border-color: #f5b301; color: #1f2937; box-shadow: 0 0 8px rgba(245,179,1,.55); }
.led-red   { background: #dc2626; box-shadow: 0 0 8px rgba(220,38,38,.55); }
.led-blink { animation: led-blink 1s infinite; }
@keyframes led-blink { 50% { opacity: .35; } }
.led-link { display: inline-block; padding: 3px; line-height: 0; border-radius: 12px; }
.led-link:hover .led, .led-link:focus-visible .led { transform: scale(1.15); }
.status-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--bs-secondary-color); align-items: center; }
.status-legend .led { min-width: 22px; height: 12px; padding: 0; margin-right: 4px; box-shadow: none; }

.cell-amber { background: #f5b301 !important; color: #1f2937; font-weight: 600; }
.status-progress-cell { min-width: 140px; }
.status-progress { position: relative; height: 22px; background: var(--ptt-page-bg); border: 1px solid var(--ptt-border); border-radius: 4px; overflow: hidden; }
.status-progress > div { position: absolute; inset: 0 auto 0 0; background: rgba(22,163,74,.55); }
.status-progress > span { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 600; line-height: 20px; }

.status-table .status-detail > td { padding: 0; background: var(--ptt-page-bg); }
.status-detail-wrap { display: flex; justify-content: flex-end; padding: 14px 16px; }
.status-detail-card { width: min(820px, 100%); background: var(--ptt-panel-bg); border: 1px solid var(--ptt-border); border-radius: 10px; }
.status-detail-title { padding: 10px 14px; font-weight: 600; font-size: 14px; border-bottom: 1px solid var(--ptt-border); display: flex; gap: 8px; align-items: center; }
.status-detail-empty { padding: 18px 14px; color: var(--bs-secondary-color); display: flex; gap: 8px; align-items: center; }
.status-detail-meta { display: flex; flex-wrap: wrap; gap: 18px; padding: 10px 14px; font-size: 13px; color: var(--bs-secondary-color); border-top: 1px solid var(--ptt-border); }
.status-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--ptt-border); }

/* User permissions: a greyed-out (unavailable) item shows an empty grey box, no tick and no blue */
.perm-item:disabled, .perm-item:disabled:checked { opacity: 1; background-image: none; background-color: #e9ecef; border-color: #ced4da; }
.perm-item:disabled ~ .form-check-label { opacity: .55; }
[data-bs-theme="dark"] .perm-item:disabled, [data-bs-theme="dark"] .perm-item:disabled:checked { background-color: #2b3445; border-color: #3b4558; }
