* { box-sizing:border-box; margin:0; padding:0; }
body { font-family:system-ui,sans-serif; background:#fff; color:#333; overflow-x:hidden; }
header { background:#f8f9fa; padding:1rem; border-bottom:1px solid #ddd; }
nav { max-width:960px; margin:0 auto; display:flex; justify-content:space-between; }
.logo { font-size:1.5rem; text-decoration:none; color:#222; }
.button { background:#007bff; color:#fff; padding:0.5em 1em; border-radius:4px; text-decoration:none; }
.button:hover { background:#0056b3; }
button {
  border: 1px solid #d1d5db;
  padding: 0.25rem 0.5rem;
  background-color: #f3f4f6;
  cursor: pointer;
}
button:hover {
  background-color: #e5e7eb;
}
main { max-width:960px; margin:2rem auto; padding:0 1rem; }
footer { text-align:center; padding:1rem; background:#f1f1f1; font-size:0.9rem; }

/* Styles for the floating OpenAI bar */
#openai-bar {
  position: fixed;
  bottom: 16px;
  left: 16px;
  width: 300px;
  max-height: 70vh;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  resize: vertical;
}
#openai-bar header {
  cursor: move;
  background: #f0f0f0;
  padding: 5px 30px 5px 5px;
  font-weight: bold;
  position: relative;
}
#openai-bar header button {
  position: absolute;
  right: 4px;
  top: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  color: #374151;
}
#openai-bar textarea {
  width: 100%;
  height: 60px;
  resize: vertical;
}
#openai-bar .close-btn {
  color: #374151;
  background: transparent;
  border: none;
  cursor: pointer;
}
#openai-bar .response {
  margin-top: 8px;
  max-height: 150px;
  overflow: auto;
}
#openai-bar button.send-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

#openai-toggle {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 50;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 1.1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

@media (max-width: 600px) {
  #openai-bar {
    width: 90vw;
    left: 5vw;
    bottom: 10px;
  }
  #openai-toggle {
    left: 10px;
    bottom: 10px;
  }
}

.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
}

.toast {
  background: #f8fafc;
  border: 1px solid #ddd;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  animation: fade-slide 0.3s ease;
  user-select: text;
}

.toast-success { color: #16a34a; }
.toast-error { color: #dc2626; }

@keyframes fade-slide {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Sticky layout helpers */
.sticky-header {
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}

.sticky-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
}

.table-container {
  max-height: 70vh;
  overflow-x: auto;
  overflow-y: auto;
}

/* Improve visibility for multi-select lists */
select[multiple] {
  min-height: 8rem;
  min-width: 12rem;
}

select[multiple] option:checked {
  background-color: #2563eb;
  color: #fff;
}

#sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

/* Sidebar container displays items vertically */
.sidebar {
  display: flex;
  flex-direction: column;
  width: 240px;
  height: 100vh;
  overflow-y: auto;
  background-color: #1f2937;
  color: white;
  gap: 0.5rem;
}

/* Top level menu items */
.sidebar > .menu-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #374151;
  cursor: pointer;
}

/* Submenus are always stacked vertically */
.submenu,
.subsubmenu {
  display: flex;
  flex-direction: column;
  padding-left: 1rem;
  gap: 0.25rem;
}

.submenu .menu-item,
.subsubmenu .menu-item {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

/* Force column layout at all levels */
.menu-container,
.menu-group,
.sidebar,
.submenu,
.subsubmenu {
  flex-direction: column !important;
  display: flex !important;
}

/* Account dropdown styling */
.account-menu {
  background-color: #1f2937; /* dark gray */
  color: #f9fafb; /* off-white text */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 0.75rem;
}
.account-menu li:hover {
  background-color: #374151; /* darker on hover */
}

/* Table cell behaviour */
td {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

th {
  white-space: normal;
  word-break: break-word;
  padding: 0.5rem;
  font-weight: 600;
  text-align: left;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.6);
  z-index: 1000;
  pointer-events: none;
}

.loading-spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #2563eb;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tab-button {
  padding: 0.25rem 0.5rem;
  margin-right: 0.5rem;
  border: 1px solid #ccc;
  background: #f0f0f0;
  cursor: pointer;
}

.tab-button.active {
  background: #d1d5db;
  font-weight: bold;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    position: fixed;
    top: 48px;
    left: 0;
    z-index: 30;
    height: calc(100vh - 48px);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 20;
  }
}

@media (max-width: 480px) {
  table td,
  table th {
    padding: 0.25rem;
    font-size: 0.75rem;
  }
}

/* Tooltip styles */
.tooltip-wrapper[data-tooltip] {
  position: relative;
  display: inline-block;
  overflow: visible;
}

.tooltip-wrapper[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  background: #333;
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 50;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
}
