/* =============================================
   Anlap IoT Portal – Custom overrides (Bootstrap 5 base)
   Only styles that Bootstrap cannot cover natively
   ============================================= */

/* ---------- Color tokens ---------- */
:root {
  --anlap-bg:      #0d1117;
  --anlap-sidebar: #161b22;
  --anlap-card:    #161b22;
  --anlap-border:  #30363d;
  --anlap-txt:     #e6edf3;
  --anlap-muted:   #8b949e;
  --anlap-primary: #58a6ff;
  --anlap-ok:      #3fb950;
  --anlap-danger:  #f85149;
  --anlap-warn:    #d29922;
}

/* ---------- Base ---------- */
body {
  background-color: var(--anlap-bg);
  color: var(--anlap-txt);
  min-height: 100vh;
}

/* ---------- Topbar / Navbar override ---------- */
.navbar-anlap {
  background-color: var(--anlap-sidebar) !important;
  border-bottom: 1px solid var(--anlap-border);
}

/* ---------- Sidebar ---------- */
.sidebar-anlap {
  width: 240px;
  min-height: 100vh;
  background-color: var(--anlap-sidebar);
  border-right: 1px solid var(--anlap-border);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  padding-top: 0;
}
.sidebar-anlap .sidebar-brand {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--anlap-border);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--anlap-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar-anlap .nav-link {
  color: var(--anlap-muted);
  padding: .6rem 1.25rem;
  border-radius: 6px;
  margin: 2px 8px;
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .92rem;
  transition: background .15s, color .15s;
}
.sidebar-anlap .nav-link:hover,
.sidebar-anlap .nav-link.active {
  background: rgba(88, 166, 255, .12);
  color: var(--anlap-primary);
}
.sidebar-anlap .nav-link.active {
  font-weight: 600;
}

/* ---------- Main wrapper with sidebar ---------- */
.main-with-sidebar {
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.main-topbar {
  background-color: var(--anlap-sidebar);
  border-bottom: 1px solid var(--anlap-border);
  padding: .6rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.main-content {
  padding: 1.5rem;
  flex: 1;
}

/* ---------- Bottom navbar (mobile only) ---------- */
.bottom-navbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--anlap-sidebar);
  border-top: 1px solid var(--anlap-border);
  z-index: 1050;
}
.bottom-navbar .bottom-nav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: .5rem .25rem;
  color: var(--anlap-muted);
  text-decoration: none;
  font-size: .68rem;
  gap: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: color .15s;
}
.bottom-navbar .bottom-nav-link i {
  font-size: 1.25rem;
}
.bottom-navbar .bottom-nav-link.active,
.bottom-navbar .bottom-nav-link:hover {
  color: var(--anlap-primary);
}

/* ---------- Cards ---------- */
.card-anlap {
  background-color: var(--anlap-card);
  border: 1px solid var(--anlap-border);
  border-radius: 10px;
  color: var(--anlap-txt);
}
.card-anlap .card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--anlap-border);
  font-weight: 600;
  font-size: .9rem;
}

.device-tile {
  background: linear-gradient(180deg, rgba(88, 166, 255, .08), rgba(22, 27, 34, 1));
  border: 1px solid var(--anlap-border);
  border-radius: 14px;
  padding: 1rem;
  height: 100%;
}

.device-tile.is-offline {
  opacity: .72;
}

.device-tile .device-title {
  font-size: 1rem;
  font-weight: 700;
}

.device-tile .device-meta {
  color: var(--anlap-muted);
  font-size: .82rem;
}

.avatar-profile {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, #1f6feb, #3fb950);
  border: 2px solid rgba(255,255,255,.08);
}

.avatar-fallback {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #1f6feb, #8250df);
  border: 2px solid rgba(255,255,255,.08);
}

/* ---------- Stat card ---------- */
.stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
}
.stat-label {
  font-size: .78rem;
  color: var(--anlap-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ---------- Forms ---------- */
.form-control-anlap,
.form-select-anlap {
  background-color: #0d1117;
  border: 1px solid var(--anlap-border);
  color: var(--anlap-txt);
  border-radius: 8px;
}
.form-control-anlap:focus,
.form-select-anlap:focus {
  background-color: #0d1117;
  border-color: var(--anlap-primary);
  color: var(--anlap-txt);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .2);
}

/* ---------- Tables ---------- */
.table-anlap {
  color: var(--anlap-txt);
  font-size: .85rem;
}
.table-anlap thead th {
  background-color: #0d1117;
  color: var(--anlap-muted);
  border-color: var(--anlap-border);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.table-anlap tbody td {
  border-color: var(--anlap-border);
  vertical-align: middle;
  white-space: nowrap;
}
.table-anlap tbody tr:hover td {
  background-color: rgba(88, 166, 255, .05);
}

/* ---------- Status Badges (used by JS) ---------- */
.badge.ok {
  background-color: rgba(63, 185, 80, .18) !important;
  color: #3fb950 !important;
  border: 1px solid rgba(63, 185, 80, .3);
  font-size: .72rem;
  font-weight: 700;
  padding: .25em .65em;
  border-radius: 999px;
}
.badge.off {
  background-color: rgba(248, 81, 73, .18) !important;
  color: #f85149 !important;
  border: 1px solid rgba(248, 81, 73, .3);
  font-size: .72rem;
  font-weight: 700;
  padding: .25em .65em;
  border-radius: 999px;
}

/* ---------- Pre / output ---------- */
pre#out {
  white-space: pre-wrap;
  background: #010409;
  border: 1px solid var(--anlap-border);
  border-radius: 8px;
  padding: 1rem;
  min-height: 80px;
  color: var(--anlap-txt);
  font-size: .8rem;
}

/* ---------- Landing hero ---------- */
.hero-section {
  background: radial-gradient(ellipse at 20% -10%, #1f2d50 0%, transparent 60%),
              radial-gradient(ellipse at 80% 110%, #1a2940 0%, transparent 60%),
              var(--anlap-bg);
  padding: 5rem 0 4rem;
}

/* ---------- Cockpit editor ---------- */
.cockpit-editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
  align-items: start;
}

.cockpit-stage,
.cockpit-sidebar {
  padding: 1rem;
}

.cockpit-stage-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.cockpit-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-rows: 90px;
  gap: .85rem;
  min-height: 380px;
}

.cockpit-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--anlap-border);
  border-radius: 14px;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--anlap-muted);
  background: rgba(88, 166, 255, .04);
}

.cockpit-widget {
  min-width: 0;
}

.cockpit-widget-frame {
  height: 100%;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.08);
  background:
    linear-gradient(180deg, rgba(88, 166, 255, .08), rgba(13, 17, 23, .96)),
    linear-gradient(135deg, rgba(31, 111, 235, .08), transparent 55%);
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.cockpit-widget.is-offline .cockpit-widget-frame {
  opacity: .76;
}

.cockpit-widget.is-selected .cockpit-widget-frame {
  border-color: rgba(88, 166, 255, .65);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, .2);
}

.cockpit-widget-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .85rem;
}

.cockpit-widget-title {
  font-size: 1rem;
  font-weight: 700;
}

.cockpit-widget-body {
  min-height: 0;
}

.widget-drag-handle {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: var(--anlap-muted);
  cursor: grab;
}

.widget-drag-handle:active {
  cursor: grabbing;
}

.widget-resize-handle {
  position: absolute;
  border: none;
  background: transparent;
  opacity: .8;
}

.widget-resize-handle::after {
  content: "";
  position: absolute;
  background: rgba(88, 166, 255, .85);
  border-radius: 999px;
}

.widget-resize-e {
  top: 50%;
  right: 2px;
  width: 16px;
  height: 52px;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.widget-resize-e::after {
  top: 10px;
  right: 4px;
  width: 4px;
  height: 32px;
}

.widget-resize-s {
  left: 50%;
  bottom: 2px;
  width: 52px;
  height: 16px;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.widget-resize-s::after {
  left: 10px;
  bottom: 4px;
  width: 32px;
  height: 4px;
}

.widget-resize-se {
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
}

.widget-resize-se::after {
  right: 2px;
  bottom: 2px;
  width: 12px;
  height: 12px;
}

.cockpit-sidebar {
  display: grid;
  gap: 1rem;
}

.cockpit-sidebar.is-disabled {
  opacity: .72;
}

.cockpit-sidebar-section {
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px;
  padding: 1rem;
  background: rgba(13, 17, 23, .55);
}

.utility-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.utility-label {
  font-size: .75rem;
  color: var(--anlap-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.utility-value {
  font-size: 1.6rem;
  font-weight: 800;
}

.clock-widget {
  display: grid;
  gap: .35rem;
  align-content: center;
  min-height: 120px;
}

.clock-time {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
  font-weight: 900;
}

.cockpit-mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  padding: .75rem;
  background: rgba(255,255,255,.02);
}

.cockpit-editing .cockpit-widget-frame {
  box-shadow: inset 0 0 0 1px rgba(88, 166, 255, .12);
}

/* ---------- Responsive: mobile ---------- */
@media (max-width: 1199.98px) {
  .cockpit-editor-shell {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 767.98px) {
  .sidebar-anlap        { display: none !important; }
  .main-with-sidebar    { margin-left: 0 !important; }
  .main-topbar          { display: none !important; }
  .bottom-navbar        { display: flex !important; }
  .main-content         { padding: 1rem; padding-bottom: 5rem; }
  .cockpit-grid         { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  .cockpit-widget       { grid-column: 1 / -1 !important; grid-row: auto !important; }
  .cockpit-stage,
  .cockpit-sidebar      { padding: .85rem; }
  .cockpit-sidebar      { display: none; }
}
@media (min-width: 768px) {
  .bottom-navbar        { display: none !important; }
}
