/* Responsive and accessibility refinements for the Obsidian Control portal.
   Load after theme.css. */

/* Keep keyboard users oriented and make the existing click targets easier to use. */
:root { --muted: #a0a8b5; --dim: #858e9e; }
:where(a, button, [role="button"], .nav, .toggle, input, select, textarea):focus-visible {
  outline: 2px solid var(--teal, #2dd4bf);
  outline-offset: 3px;
}

button, .nav, .toggle { touch-action: manipulation; }
button, .nav { min-height: 42px; }

/* Wide tables should scroll inside their own panel instead of widening the page. */
table { min-width: 600px; }
#mainContent { min-width: 0; }
#mobileNavToggle { display: none; }
#sidebarBackdrop { display: none; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 10px 14px; border-radius: 8px; background: var(--panel-solid); color: var(--text); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }

@media (max-width: 1023px) {
  html, body { min-width: 320px; }
  #app:not(.hidden) { display: flex; min-height: 100dvh; }

  /* Keep the full navigation available in a compact, touch-friendly drawer. */
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(86vw, 310px);
    min-width: 0;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform .24s ease;
    box-shadow: 18px 0 48px rgba(0,0,0,.48);
    background: rgba(9, 11, 15, .96) !important;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  #sidebar.mobile-open { transform: translateX(0); }
  #sidebar > div:first-child { display: flex; min-height: 64px; }
  #sidebar nav {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 10px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  #sidebar nav .sec { display: block; }
  #sidebar .nav {
    min-height: 46px;
    padding: 10px 13px;
  }
  #sidebar .nav .lbl { display: inline; }
  #sidebar .nav .kbd { display: none; }
  #sidebar > div:last-child {
    display: flex;
    flex: 0 0 auto;
    gap: 3px;
    padding: 7px 10px max(10px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
  }
  #sidebar > div:last-child .nav {
    flex: 1;
    min-height: 44px;
    padding: 8px 10px;
  }
  #sidebarBackdrop { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.58); backdrop-filter: blur(2px); }
  #sidebarBackdrop[hidden] { display: none !important; }
  #mobileNavToggle { display: inline-flex !important; flex: 0 0 auto; width: 42px; min-width: 42px; align-items: center; justify-content: center; }
  #sidebarToggle { display: none !important; }

  #app > main {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #app > main > header {
    position: sticky;
    top: 0;
    flex-wrap: wrap;
    gap: 9px 12px;
    padding: 12px 14px;
  }
  #app > main > header > div:first-child { padding-left: 2px; }
  #app > main > header > div:first-child { flex: 1 1 120px; min-width: 0; }
  #paletteTrigger {
    order: 3;
    flex: 1 1 100%;
    min-width: 0 !important;
    margin-left: 0;
  }
  #mobileNavToggle { order: 0; }
  #app > main > header > div:last-child {
    gap: 6px;
  }
  #app > main > header > div:last-child .chip:first-child { display: none; }
  #app > main > header > div:last-child #clock { font-size: 10px; padding: 3px 7px; }
  #app > main > header > div:last-child > div:last-child { display: none; }
  #app > main > .p-6 { padding: 14px; }

  .glass { border-radius: 14px; }
  .glass-hover:hover { transform: none; }
  .btn { min-height: 42px; }

  /* Constrain wide operational tables to their card and preserve readable columns. */
  table { display: block; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
  th, td { white-space: nowrap; }
  .admin-terminal { min-height: 320px; }
  .ollama-app { min-height: 380px; }
}

@media (max-width: 420px) {
  #view-dashboard > .grid:first-child { gap: 10px; }
  #view-dashboard > .grid:first-child > .glass { padding: 14px; }
  #view-dashboard .statnum { font-size: 1.55rem; }
  #view-dashboard .sect { font-size: 9px; letter-spacing: .7px; }
  #view-dashboard > .grid:last-child > .glass { padding: 16px; }
  #palette { padding: 8vh 12px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (min-width: 1024px) and (max-width: 1200px) {
  #mainContent > header { flex-wrap: wrap; gap: 12px; }
  #paletteTrigger { order: 3; flex: 1 1 100%; margin-left: 0; }
}
#viewTitle:focus { outline: none; }
#viewTitle:focus-visible { outline: 2px solid var(--teal); outline-offset: 4px; }

/* Keep Grafana inside the portal workspace while preserving its own controls. */
.grafana-embed {
  width: 100%;
  height: calc(100dvh - 136px);
  min-height: 400px;
  overflow: hidden;
  border: 1px solid var(--border, #334155);
  border-radius: 12px;
  background: #101923;
}
.grafana-embed-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #101923;
}
@media (max-width: 1023px) {
  .grafana-embed { height: calc(100dvh - 150px); min-height: 360px; border-radius: 9px; }
}
@media (max-width: 420px) {
  .grafana-embed { height: calc(100dvh - 162px); min-height: 340px; }
}
