/* ============================================================
   Avontus Cloud Portal — design tokens
   Palette sampled directly from avontus.com: indigo #0005EE (CTAs,
   footer), electric blue #0089FF (links/nav), black on white, Open Sans.
   ============================================================ */
:root {
  --indigo: #0005EE;
  --indigo-600: #0004BD;
  --indigo-100: #ECEDFE;
  --blue: #0089FF;
  --blue-100: #E5F3FF;
  --ink: #000000;
  --bg: #F4F5F7;
  --card: #ffffff;
  --text: #17181c;
  --text-soft: #52565f;
  --muted: #858992;
  --border: #e4e6ec;
  --red: #d9453f;
  --red-100: #fdeceb;
  --green: #1e9e5a;
  --green-100: #e8f8ef;
  --amber: #d98c1f;
  --amber-100: #fdf3e3;
  --radius: 12px;
  --pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 43, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 20, 43, 0.08);
  --shadow-lg: 0 24px 64px rgba(0, 2, 40, 0.35);
}

* { box-sizing: border-box; }

body {
  font-family: 'Open Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

.app-shell { display: flex; height: 100vh; }

/* ---------------- Auth gate ---------------- */
.auth-gate {
  position: fixed; inset: 0; z-index: 20000; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.auth-gate.hidden { display: none; }
.auth-gate-card {
  background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 44px 48px;
  width: 360px; text-align: center; box-shadow: var(--shadow-lg);
}
.auth-gate-mark { width: 52px; height: 52px; border-radius: 14px; font-size: 18px; margin: 0 auto 20px; }
.auth-gate-card h1 { font-size: 18px; margin: 0 0 10px; color: var(--ink); }
.auth-gate-card p { font-size: 13px; color: var(--text-soft); margin: 0 0 26px; display: flex; align-items: center; justify-content: center; gap: 9px; }
.auth-gate-btn { display: none; width: 100%; background: var(--indigo); }
.auth-gate-spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--indigo);
  animation: auth-spin .7s linear infinite; flex-shrink: 0;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  color: var(--text);
}
.sidebar-header { padding: 24px 22px 20px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(155deg, var(--indigo), var(--indigo-600));
  box-shadow: 0 6px 14px rgba(0,5,238,0.28);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  font-size: 14px; letter-spacing: 0.5px; color: #fff; flex-shrink: 0;
}
.brand-text { font-weight: 700; font-size: 16px; letter-spacing: -0.1px; color: var(--ink); }
.brand-text b { color: var(--indigo); font-weight: 800; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 14px 14px; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted);
  font-weight: 700; margin: 22px 10px 10px;
  padding-top: 18px; border-top: 1px solid var(--border);
}
.nav-group-label:first-child { margin-top: 6px; padding-top: 0; border-top: none; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin-bottom: 2px;
  border-radius: 9px; cursor: pointer; color: var(--text-soft); font-size: 13.5px;
  font-weight: 600; transition: all .15s;
}
.nav-icon { flex-shrink: 0; opacity: 0.7; width: 19px; height: 19px; transition: opacity .15s; }
.nav-item:hover { color: var(--indigo); background: var(--indigo-100); }
.nav-item:hover .nav-icon { opacity: 1; }
.nav-item.active { background: var(--indigo); color: #fff; box-shadow: 0 8px 18px rgba(0,5,238,0.3); }
.nav-item.active .nav-icon { opacity: 1; }

.tenant-filter-list { padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.tenant-filter-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px;
  font-size: 12.5px; color: var(--text-soft); cursor: pointer;
}
.tenant-filter-item:hover { background: var(--indigo-100); color: var(--indigo); }
.tenant-filter-item input { accent-color: var(--indigo); }
.tenant-filter-item .t-count {
  margin-left: auto; font-size: 10px; background: var(--bg); padding: 1px 7px; border-radius: 10px; color: var(--muted);
}
.filter-empty { padding: 6px 8px; font-size: 12px; color: var(--muted); font-style: italic; }

.tenant-select {
  width: 100%; margin: 0 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 12.5px; font-weight: 600; font-family: inherit;
  box-sizing: border-box; cursor: pointer;
}
.tenant-select:hover, .tenant-select:focus { border-color: var(--indigo); outline: none; }

.sidebar-footer { padding: 16px 20px 20px; border-top: 1px solid var(--border); }
.api-status-pill {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
  padding: 7px 12px; border-radius: var(--pill); display: flex; align-items: center; gap: 8px;
}
.api-status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.api-status-pill.offline { background: var(--red-100); color: var(--red); }
.api-status-pill.online { background: var(--green-100); color: var(--green); }
.api-status-pill.demo { background: var(--amber-100); color: #a56a13; }

/* ---------------- Main ---------------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: auto; scroll-behavior: smooth; background: var(--bg); }
header {
  background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
  padding: 14px 32px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  display: flex; justify-content: space-between; align-items: center; z-index: 100; gap: 20px;
}
.header-left { display: flex; align-items: center; gap: 20px; min-width: 0; }
.only-mobile { display: none; }
.view-label { font-weight: 700; color: var(--ink); font-size: 16px; white-space: nowrap; }
.search-box {
  display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--pill); padding: 8px 16px; min-width: 320px; color: var(--muted);
}
.search-box input { border: none; background: transparent; outline: none; font-size: 13px; width: 100%; color: var(--text); }

.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: #fff;
  color: var(--text-soft); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all .15s;
}
.icon-btn:hover { border-color: var(--indigo); color: var(--indigo); }
.portal-btn {
  background: var(--indigo); color: #fff; padding: 9px 18px; border-radius: var(--pill); text-decoration: none;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; transition: all .15s;
}
.portal-btn:hover { background: var(--indigo-600); }
.refresh-pill {
  font-size: 11px; color: var(--text-soft); font-family: 'Consolas', monospace; font-weight: 700;
  border: 1px solid var(--border); padding: 7px 12px; border-radius: var(--pill); white-space: nowrap;
}
.user-chip { display: flex; align-items: center; gap: 9px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--indigo); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.user-meta { line-height: 1.25; }
.user-name { font-size: 12.5px; font-weight: 700; color: var(--ink); }
.user-action { font-size: 11px; color: var(--blue); text-decoration: none; font-weight: 600; }
.user-action:hover { text-decoration: underline; }

.content { padding: 28px 32px 60px; }

/* ---------------- Banners ---------------- */
.banner {
  border-radius: var(--radius); padding: 12px 18px; margin-bottom: 18px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.banner-warn { background: var(--amber-100); color: #8a5a10; border: 1px solid #f2d8a1; }

/* ---------------- Stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
  background: var(--card); padding: 18px 20px; border-radius: var(--radius); border: 1px solid var(--border);
  cursor: pointer; transition: all .15s; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--indigo); opacity: 0;
  transition: opacity .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card:hover::before { opacity: 1; }
.stat-card b { display: block; font-size: 26px; color: var(--ink); font-weight: 800; line-height: 1.1; }
.stat-card small { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 700; }
.stat-card.stat-alert b { color: var(--red); }

/* ---------------- Tenant overview ---------------- */
.tenant-overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 26px; }
.tenant-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.tenant-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.tenant-card-name { font-weight: 700; color: var(--ink); font-size: 13.5px; }
.tenant-pill { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: var(--pill); text-transform: uppercase; letter-spacing: .5px; }
.tenant-pill.ok { background: var(--green-100); color: var(--green); }
.tenant-pill.warn { background: var(--red-100); color: var(--red); }
.tenant-card-meta { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }

/* ---------------- Alerts ---------------- */
.alert-container { margin-bottom: 26px; border: 1px solid #f3c9c7; border-radius: var(--radius); background: #fff; overflow: hidden; box-shadow: 0 8px 24px rgba(217,69,63,0.1); }
.alert-header { background: var(--red); color: #fff; padding: 11px 20px; font-weight: 700; font-size: 11.5px; letter-spacing: 0.8px; display: flex; align-items: center; gap: 10px; text-transform: uppercase; }
.alert-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.alert-table th { text-align: left; padding: 11px 20px; background: var(--red-100); color: var(--red); font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; }
.alert-table td { padding: 11px 20px; border-top: 1px solid #f9e1e1; color: var(--text); }

.status-badge { padding: 3px 9px; border-radius: var(--pill); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.status-healthy { background: var(--green-100); color: var(--green); }
.status-unhealthy { background: var(--red-100); color: var(--red); }
.status-unknown { background: #eef1f6; color: var(--muted); }
.power-badge { padding: 3px 9px; border-radius: var(--pill); font-size: 10px; font-weight: 700; text-transform: uppercase; background: #eef1f6; color: var(--text-soft); }
.power-badge.running { background: var(--green-100); color: var(--green); }
.power-badge.stopped { background: var(--red-100); color: var(--red); }

/* ---------------- Sections / tables ---------------- */
.section { background: var(--card); padding: 22px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 22px; scroll-margin-top: 90px; box-shadow: var(--shadow-sm); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section h2 { margin: 0; font-size: 15.5px; color: var(--ink); border-left: 3px solid var(--indigo); padding-left: 12px; font-weight: 700; }
.section-count { font-size: 11px; color: var(--muted); font-weight: 600; }
.tenant-text { color: var(--text) !important; font-weight: 600; }
.ip-text { color: var(--blue) !important; font-family: 'Consolas', monospace; font-weight: 700; font-size: 12px; }
.inspect-btn { cursor: pointer; background: var(--ink); color: #fff; border: none; padding: 6px 14px; border-radius: var(--pill); font-size: 10.5px; font-weight: 700; transition: background .15s; }
.inspect-btn:hover { background: var(--indigo); }
.row-actions { display: flex; gap: 6px; }
.mini-action { cursor: pointer; border: 1px solid var(--border); background: #fff; padding: 5px 11px; border-radius: var(--pill); font-size: 10px; font-weight: 700; color: var(--text-soft); transition: all .15s; }
.mini-action:hover { border-color: var(--indigo); color: var(--indigo); }
.mini-action.danger:hover { border-color: var(--red); color: var(--red); }
.mini-action:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------------- Modal ---------------- */
#modal { display: none; position: fixed; z-index: 9999; inset: 0; background: rgba(0,2,40,0.6); backdrop-filter: blur(4px); }
.modal-content { background: #fff; margin: 3vh auto; width: 90%; max-width: 1200px; height: 94vh; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-header { padding: 22px 34px; background: #fff; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; }
.modal-header small { color: var(--blue); font-weight: 800; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.modal-header h1 { margin: 4px 0 0; color: var(--ink); font-size: 20px; }
.modal-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--ink); }
.modal-body { display: grid; grid-template-columns: 380px 1fr; gap: 1px; background: var(--border); flex: 1; overflow: hidden; }
.drill-left { background: #fff; padding: 32px; overflow-y: auto; }
.drill-right { background: #0b0d17; padding: 20px; overflow-y: auto; position: relative; }
.prop-box { margin-bottom: 22px; }
.prop-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-weight: 700; margin-bottom: 6px; }
.json-label { margin-bottom: 15px; color: rgba(255,255,255,0.5); }
.prop-val { font-size: 15px; color: var(--ink); font-weight: 600; word-break: break-word; }
.json-viewer { font-family: 'Consolas', monospace; color: #8fd6ff; font-size: 12px; white-space: pre-wrap; background: #0b0d17; padding: 15px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.08); }

.device-tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.device-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 0 2px 10px; margin-right: 18px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; }
.device-tab:hover { color: var(--text); }
.device-tab.active { color: var(--indigo); border-bottom-color: var(--indigo); }
.device-tab-panel .prop-box:last-child { margin-bottom: 0; }
.action-bar { padding: 18px 34px; background: #fff; border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.action-bar-spacer { flex: 1; }

.btn-manage { text-decoration: none; padding: 11px 24px; border-radius: var(--pill); font-weight: 700; font-size: 12.5px; display: inline-flex; align-items: center; gap: 9px; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); padding: 11px 24px; border-radius: var(--pill); font-weight: 700; font-size: 12.5px; cursor: pointer; }
.btn-secondary:hover { background: var(--bg); border-color: var(--muted); }
.btn-action { border: none; padding: 11px 22px; border-radius: var(--pill); font-weight: 700; font-size: 12.5px; cursor: pointer; color: #fff; transition: opacity .15s; }
.btn-action:hover { opacity: 0.85; }
.btn-action:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-start { background: var(--green); }
.btn-restart { background: var(--amber); }
.btn-stop { background: var(--red); }

/* ---------------- Confirm dialog ---------------- */
.confirm-overlay { display: none; position: fixed; inset: 0; z-index: 10050; background: rgba(0,2,40,0.5); align-items: center; justify-content: center; }
.confirm-overlay.show { display: flex; }
.confirm-box { background: #fff; border-radius: 16px; padding: 28px 30px; width: 400px; box-shadow: var(--shadow-lg); }
.confirm-box h3 { margin: 0 0 10px; color: var(--ink); font-size: 16px; }
.confirm-box p { margin: 0 0 22px; color: var(--text-soft); font-size: 13.5px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.confirm-actions .btn-secondary { background: #fff; color: var(--text-soft); border: 1px solid var(--border); }
.confirm-actions .btn-secondary:hover { background: var(--bg); border-color: var(--muted); }
.confirm-actions .btn-action, .confirm-actions .btn-danger { padding: 9px 20px; border-radius: var(--pill); }
.btn-danger { background: var(--red); color: #fff; border: none; padding: 9px 20px; border-radius: var(--pill); font-weight: 700; font-size: 12.5px; cursor: pointer; }

/* ---------------- Toasts ---------------- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10001; display: flex; flex-direction: column; gap: 10px; }
.status-notification {
  background: var(--ink); color: #fff; padding: 14px 20px; border-left: 4px solid var(--indigo); border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13px; transition: all .4s ease; opacity: 0; transform: translateX(20px); max-width: 340px;
}
.status-notification.show { opacity: 1; transform: translateX(0); }
.status-notification.success { border-left-color: var(--green); }
.status-notification.error { border-left-color: var(--red); }

/* ---------------- DataTables overrides ---------------- */
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate { color: var(--text-soft) !important; font-size: 12px; }
table.dataTable.cell-border tbody tr th, table.dataTable.cell-border tbody tr td { border-color: #eef1f6 !important; color: var(--text); padding: 10px 12px !important; font-size: 12.5px; }
table.dataTable thead th { background: #fafafc; color: var(--ink); border-bottom: 2px solid var(--border) !important; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .sidebar { position: fixed; left: -280px; top: 0; bottom: 0; z-index: 500; transition: left .2s; width: 260px; }
  .sidebar.open { left: 0; }
  .only-mobile { display: flex; }
  .search-box { min-width: 160px; }
  .modal-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
}
