:root {
  --md-bg: #f3f6fb;
  --md-surface: #ffffff;
  --md-text: #0f172a;
  --md-border: #dce3ee;
  --md-primary: #0b4aa6;
  --md-primary-ink: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #ffffff;
  color: var(--md-text);
  font-family: "Roboto", "Noto Sans", system-ui, -apple-system, sans-serif;
}

.d-none { display: none !important; }

/* Shared loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.22);
  display: grid;
  place-items: center;
  z-index: 99999;
}
.loading-card {
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}
.md-spinner {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 3px solid #d1d5db;
  border-top-color: var(--md-primary);
  animation: md-spin 0.8s linear infinite;
}
@keyframes md-spin { to { transform: rotate(360deg); } }

/* Material toast */
.krp-toast-container {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1100;
  display: grid;
  gap: 10px;
  width: min(420px, calc(100vw - 28px));
}

.krp-toast {
  display: none;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid var(--md-border);
  border-left: 4px solid var(--md-primary);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.6);
  padding: 10px 12px;
}

.krp-toast-body {
  display: grid;
  gap: 2px;
}

.krp-toast-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--md-text);
}

.krp-toast-text {
  font-size: 13px;
  color: var(--md-text);
  line-height: 1.35;
}

.krp-toast-sub {
  display: block;
  margin-top: 3px;
  color: #334155;
  font-size: 12px;
}

.krp-toast--info {
  border-left-color: #0284c7;
}

.krp-toast--success {
  border-left-color: var(--md-primary);
}

.krp-toast--warning {
  border-left-color: #d97706;
}

.krp-toast--danger {
  border-left-color: #dc2626;
}

/* Index shell */
.app-index-shell { min-height: 100vh; display: block; }
#app-main {
  min-height: calc(100vh - 1px);
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

#app-main > * {
  position: relative;
  z-index: 1;
}

body.app-index #app-main::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60vmax;
  height: 60vmax;
  background: url("../img/compass-rose.svg") center center / contain no-repeat;
  opacity: 0.20;
  pointer-events: none;
  z-index: 0;
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  will-change: transform;
  transform: translate3d(-50%, -50%, 0) scale(1.78) rotateZ(-8deg) rotateX(22deg) rotateY(-16deg);
  animation: compass-flow-3d 140s cubic-bezier(0.45, 0.03, 0.25, 0.98) infinite;
}

body.app-pg #app-main::before {
  content: none;
}

@keyframes compass-flow-3d {
  0% {
    transform: translate3d(-49%, -54%, 12px) scale(1.70) rotateZ(-18deg) rotateX(26deg) rotateY(-18deg);
  }
  18% {
    transform: translate3d(-56%, -47%, -16px) scale(1.86) rotateZ(10deg) rotateX(12deg) rotateY(20deg);
  }
  37% {
    transform: translate3d(-45%, -58%, 20px) scale(1.76) rotateZ(28deg) rotateX(30deg) rotateY(-10deg);
  }
  58% {
    transform: translate3d(-58%, -50%, -10px) scale(1.90) rotateZ(46deg) rotateX(9deg) rotateY(15deg);
  }
  79% {
    transform: translate3d(-46%, -44%, 18px) scale(1.73) rotateZ(64deg) rotateX(27deg) rotateY(-13deg);
  }
  100% {
    transform: translate3d(-53%, -56%, -14px) scale(1.82) rotateZ(84deg) rotateX(14deg) rotateY(17deg);
  }
}

@media (max-width: 992px) {
  body.app-index #app-main::before {
    animation: none;
    opacity: 0.16;
    transform: translate3d(-50%, -50%, 0) scale(2.05) rotate(-10deg);
  }
}

/* PG shell */
html, body {
  height: 100%;
}

body.app-pg {
  background: #f5f5f5;
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 60px 1fr;
  overflow: hidden;
}

#sidebar {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #00B4DB;
  border-right: 1px solid rgba(255, 255, 255, 0.18);
  position: relative;
  z-index: 20;
}

.sidebar-logo-wrap {
  padding: 10px 4px 10px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sidebar-logo {
  width: 100%;
  max-width: 44px;
  height: auto;
  display: block;
  filter: brightness(0) invert(1);
}

#app-sidebar {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}

.sidebar-fixed {
  padding: 6px 0 0;
}

.sidebar-fixed .nav,
.sidebar-fixed .nav-item {
  margin: 0;
  padding: 0;
  list-style: none;
}

#app-sidebar .sidebar-nav,
#app-sidebar .sidebar-nav .nav {
  margin: 0;
  padding: 0;
  list-style: none;
}

#app-sidebar .sidebar-nav .nav {
  min-height: 100%;
}

#app-sidebar .nav-item {
  margin: 0;
  padding: 0;
  list-style: none;
}

#app-sidebar .nav-item-exit {
  margin-top: auto;
  padding-top: 8px;
}

#sidebar .nav-link {
  position: relative;
  width: 46px;
  margin: 5px auto;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #eaf8ff;
  text-decoration: none;
  background: transparent;
  transition: background-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
  line-height: 1;
  padding: 5px 0;
}

#sidebar .nav-link .material-symbols-outlined {
  line-height: 1;
}

#sidebar .nav-link:hover {
  background: #ffffff;
  color: #00B4DB;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

#sidebar .nav-link.active {
  background: #ffffff;
  color: #00B4DB;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.16);
}

.app-main-host {
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-topbar {
  display: none;
}

.mobile-topbar__logo {
  display: none;
}

.mobile-menu-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.22);
}

body.app-pg #app-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

#app-sidebar::-webkit-scrollbar,
body.app-pg #app-main::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#app-sidebar::-webkit-scrollbar-thumb,
body.app-pg #app-main::-webkit-scrollbar-thumb {
  background: rgba(47, 139, 255, 0.52);
  border-radius: 99px;
}

#app-sidebar::-webkit-scrollbar-track,
body.app-pg #app-main::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
}

#app-sidebar,
body.app-pg #app-main {
  scrollbar-width: thin;
  scrollbar-color: rgba(47, 139, 255, 0.52) rgba(255, 255, 255, 0.08);
}

.sidebar-backdrop {
  display: none;
}

.sidebar-hover-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
  color: #0f172a;
  font-size: 12px;
  line-height: 1.3;
  white-space: normal;
  opacity: 0;
  transform: translate3d(0, -6px, 0);
  transition: opacity .12s ease, transform .12s ease;
  pointer-events: none;
  z-index: 5000;
}

.sidebar-hover-tooltip.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

/* Minimal generic panel style */
#confirm-modal,
#sidepanel-info {
  display: none;
  background: rgba(255, 255, 255, 0.44);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid var(--md-border);
  border-radius: 12px;
  padding: 12px;
}

button {
  border: 1px solid var(--md-border);
  background: rgba(255, 255, 255, 0.22);
  color: var(--md-text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
button#confirm-yes {
  background: var(--md-primary);
  border-color: var(--md-primary);
  color: var(--md-primary-ink);
}

article {
  background: rgba(255, 255, 255, 0.52);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, 0.42);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.10);
}

.version-block {
  position: static;
  text-align: center;
  padding: 8px 4px 10px;
  font-size: 10px;
  line-height: 1.2;
  color: #ffffff;
  font-weight: 500;
  letter-spacing: 0.01em;
  pointer-events: none;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

body.app-index .version-block {
  position: fixed;
  left: 10px;
  bottom: 10px;
  padding: 0;
  border-top: 0;
  color: #000000;
  z-index: 2500;
}

@media (max-width: 992px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 320px);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
  }

  body.sidebar-collapsed #sidebar {
    transform: translateX(0);
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(11, 74, 166, 0.18);
    background: rgba(255, 255, 255, 0.42);
    backdrop-filter: blur(8px) saturate(115%);
    -webkit-backdrop-filter: blur(8px) saturate(115%);
  }

  .mobile-topbar__logo {
    display: block;
    width: auto;
    height: 34px;
    object-fit: contain;
  }

  body.app-pg #app-main {
    height: calc(100vh - 52px);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 15;
  }

  body.sidebar-collapsed .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
    display: block;
  }

  #app-sidebar .nav-link {
    width: calc(100% - 16px);
    margin: 6px 8px;
    justify-content: flex-start;
    gap: 10px;
    padding: 0 12px;
    border-radius: 12px;
  }

  #app-sidebar .nav-link::after {
    content: none;
  }

  #app-sidebar .nav-link::before {
    content: attr(data-bs-content);
    color: #ffffff;
    font-size: 13px;
    line-height: 1;
    letter-spacing: .01em;
  }
}

/* Global AI chat (Material-style, shared in pg shell) */
.home-ai-fab[hidden],
.home-ai-chat[hidden] {
  display: none !important;
}

.home-ai-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2700;
  width: 42px;
  height: 42px;
  border: 1px solid var(--md-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  color: var(--md-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.home-ai-fab .material-symbols-outlined {
  font-size: 22px;
}

.home-ai-chat {
  position: fixed;
  right: 18px;
  bottom: 68px;
  z-index: 2701;
  width: min(380px, calc(100% - 36px));
  height: min(520px, calc(100% - 110px));
  border: 1px solid var(--md-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.6);
}

.home-ai-chat__head {
  border-bottom: 1px solid var(--md-border);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.home-ai-chat__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--md-text);
}

.home-ai-chat__close {
  width: 26px;
  height: 26px;
  border: 1px solid var(--md-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.22);
  color: var(--md-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.home-ai-chat__messages {
  padding: 10px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.home-ai-msg {
  max-width: 88%;
  border-radius: 10px;
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.35;
}

.home-ai-msg--user {
  justify-self: end;
  background: var(--md-primary);
  color: var(--md-primary-ink);
}

.home-ai-msg--bot {
  justify-self: start;
  background: rgba(255, 255, 255, 0.52);
  color: var(--md-text);
  border: 1px solid var(--md-border);
}

.home-ai-chat__foot {
  border-top: 1px solid var(--md-border);
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.home-ai-chat__foot[hidden] {
  display: none !important;
}

.home-ai-chat__foot input {
  border: 1px solid var(--md-border);
  border-radius: 8px;
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--md-text);
  background: rgba(255, 255, 255, 0.22);
}

.home-ai-chat__foot button {
  height: 34px;
  border: 1px solid var(--md-primary);
  border-radius: 8px;
  background: var(--md-primary);
  color: var(--md-primary-ink);
  font-size: 12px;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
}

.home-history__toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.home-history__search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--md-border);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.34);
}

.home-history__search input {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--md-text);
  font-size: 12px;
}

.home-history__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.home-history__typebtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--md-border);
  border-radius: 999px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.28);
  color: var(--md-text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: transform 120ms ease, opacity 120ms ease, background-color 120ms ease;
}

.home-history__typebtn:hover {
  transform: translateY(-1px);
}

.home-history__typebtn:not(.is-active) {
  opacity: 0.45;
}

.home-history__empty {
  grid-column: 1 / -1;
  padding: 18px 12px;
  border: 1px dashed var(--md-border);
  border-radius: 14px;
  color: color-mix(in srgb, var(--md-text) 60%, transparent);
  text-align: center;
  background: rgba(255, 255, 255, 0.18);
}

.home-combo {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.home-combo__row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.home-combo__search {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--md-border);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--md-text);
  font-size: 13px;
  outline: none;
}

.home-combo__search:focus {
  border-color: color-mix(in srgb, var(--md-accent) 55%, var(--md-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-accent) 16%, transparent);
}

.home-combo__add {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--md-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--md-text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.home-combo__add[hidden] {
  display: none;
}

.home-combo__select {
  position: absolute;
  width: 1px;
  height: 1px;
  min-width: 0;
  padding: 0;
  margin: -1px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.krp-svg-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
}
