/* Basic layout structure */
html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.d-flex {
  display: flex;
  flex: 1;
}

/* ─── Top Bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  height: 56px;
  background-color: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #dee2e6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topbar-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  border: none;
  transition: box-shadow 0.2s ease, transform 0.2s ease, background-color 0.3s ease;
}

.topbar-toggle:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}

/* Left toggle — tinted with the current section's color */
.topbar-toggle-section {
  background-color: var(--section-color, #001738);
  color: #ffffff;
}

.topbar-toggle-section:hover,
.topbar-toggle-section:focus {
  background-color: color-mix(in srgb, var(--section-color, #001738) 88%, black);
  color: #ffffff;
}

.topbar-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.topbar-breadcrumbs {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar-breadcrumbs::-webkit-scrollbar { display: none; }

.topbar-breadcrumbs .breadcrumb {
  flex-wrap: nowrap;
  white-space: nowrap;
  font-size: 0.9rem;
}

.topbar-breadcrumbs .breadcrumb-item a {
  color: #6c757d;
}
.topbar-breadcrumbs .breadcrumb-item a:hover {
  color: var(--section-color, #0d6efd);
}
.topbar-breadcrumbs .breadcrumb-item.active {
  color: #001738;
  font-weight: 500;
}
.topbar-breadcrumbs .breadcrumb-item i {
  color: var(--section-color, #6c757d);
}

/* Section-tinted accent bar under the topbar */
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--section-color, transparent);
  opacity: 0.7;
  transition: background 0.3s ease;
  pointer-events: none;
}

/* ─── Left Sidebar (section sub-pages) ──────────────────────── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background-color: rgba(248, 249, 250, 0.98);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  transition: transform 0.3s ease, visibility 0.3s ease;
  position: fixed;
  top: 68px;
  left: 12px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 1030;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.sidebar-hidden {
  transform: translateX(calc(-100% - 24px));
  visibility: hidden;
}

.sidebar-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: rgba(248, 249, 250, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #dee2e6;
  min-height: 56px;
  border-radius: 16px 16px 0 0;
}

.sidebar-title {
  color: #001738;
  font-size: 1.25rem;
}

.sidebar-body {
  flex-grow: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

.sidebar-body::-webkit-scrollbar {
  width: 5px;
}

.sidebar-body::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.sidebar-body::-webkit-scrollbar-thumb {
  background: #888;
}

.sidebar-footer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background-color: rgba(248, 249, 250, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid #dee2e6;
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 1rem 0;
  border-radius: 0 0 16px 16px;
}

.sidebar .nav-link {
  color: #475569;
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.1rem;
  font-size: 0.9rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link:hover {
  background-color: rgba(0, 0, 0, 0.04);
  color: #001738;
}

.sidebar .nav-link.active {
  color: var(--section-color, #001738);
  font-weight: 600;
  background-color: color-mix(in srgb, var(--section-color, #0d6efd) 10%, transparent);
}

.sidebar-title i {
  color: var(--section-color, #001738);
}

.sidebar h5 {
  color: var(--section-color, #001738);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  padding: 0 0.9rem;
}

/* ─── Right Sidebar (Section Switcher — Google Apps grid) ───── */
.section-switcher {
  width: 320px;
  flex-shrink: 0;
  background-color: rgba(255, 255, 255, 0.99);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  max-height: 560px;
  transition: transform 0.3s ease, visibility 0.3s ease, opacity 0.3s ease;
  position: fixed;
  top: 68px;
  right: 12px;
  border-radius: 20px;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.16),
    0 4px 12px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  z-index: 1030;
  overflow: hidden;
}

.section-switcher-hidden {
  transform: translateX(calc(100% + 24px)) scale(0.96);
  opacity: 0;
  visibility: hidden;
}

.section-switcher-header {
  padding: 1.25rem 1.25rem 0.75rem;
  display: flex;
  align-items: flex-start;
  background: transparent;
  border: none;
}

.section-switcher-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #001738;
  letter-spacing: -0.01em;
}

.section-switcher-subtitle {
  font-size: 0.7rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.section-switcher-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0.25rem 0.75rem 1.25rem;
}

/* ─── Apps Grid ──────────────────────────────────────────────── */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
}

.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0.25rem 0.85rem;
  border-radius: 14px;
  text-decoration: none;
  color: #334155;
  position: relative;
  transition: background-color 0.18s ease, transform 0.18s ease;
  --tile-color: #001738;
}

.app-tile:hover {
  background-color: rgba(0, 0, 0, 0.035);
  transform: translateY(-1px);
}

.app-tile:active {
  transform: translateY(0) scale(0.98);
}

.app-tile-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: color-mix(in srgb, var(--tile-color) 12%, transparent);
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.app-tile:hover .app-tile-icon-wrap {
  background-color: color-mix(in srgb, var(--tile-color) 18%, transparent);
  transform: scale(1.05);
}

.app-tile-icon-wrap i {
  font-size: 1.5rem;
  color: var(--tile-color);
  line-height: 1;
}

.app-tile-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: #475569;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Active app: subtle indicator dot below the icon */
.app-tile-active .app-tile-label {
  color: var(--tile-color);
  font-weight: 600;
}

.app-tile-active::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--tile-color);
}

/* ─── Content area (always full width; sidebars are overlays) ─ */
.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 0px);
  width: 100%;
  margin-left: 0;
}

body:not(:has(.sidebar)) .content-wrapper {
  margin-left: auto;
  margin-right: auto;
  max-width: 1200px;
}

.container {
  flex: 1 0 auto;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
}

/* ─── Page header (section-themed) ───────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 0 1rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}

.page-header-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background-color: color-mix(in srgb, var(--section-color, #001738) 12%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.page-header-icon i {
  font-size: 1.4rem;
  color: var(--section-color, #001738);
}

.page-header-text {
  flex: 1;
  min-width: 0;
}

.page-header-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: #001738;
  margin: 0;
  letter-spacing: -0.01em;
}

.page-header-subtitle {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 2px 0 0;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

/* ─── Subtle button (for Back / Cancel) ──────────────────────── */
/* More visible than btn-outline-secondary, less heavy than btn-secondary. */
.btn-subtle {
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #374151;
  font-weight: 500;
}
.btn-subtle:hover {
  background-color: #e5e7eb;
  border-color: #9ca3af;
  color: #111827;
}
.btn-subtle:active,
.btn-subtle:focus {
  background-color: #d1d5db;
  border-color: #6b7280;
  color: #111827;
  box-shadow: 0 0 0 0.2rem rgba(107, 114, 128, 0.25);
}

.card-hover:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
  transition: all 0.2s ease;
}

/* Field group for dl-style key/value pairs */
.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

.detail-list dt {
  color: #6b7280;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  align-self: center;
}

.detail-list dd {
  margin: 0;
  color: #111827;
  font-size: 0.95rem;
  align-self: center;
}

/* User avatar */
.user-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
}

.user-avatar-lg {
  width: 72px;
  height: 72px;
  font-size: 1.6rem;
  border-radius: 20px;
}

/* ─── Permission level segmented control ─────────────────────── */
.perm-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #f3f4f6;
}

.perm-row:last-child {
  border-bottom: none;
}

.perm-row-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 180px;
  flex: 0 0 auto;
}

.perm-row-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: color-mix(in srgb, var(--perm-color, #64748b) 12%, transparent);
  flex-shrink: 0;
}

.perm-row-icon i {
  color: var(--perm-color, #64748b);
  font-size: 1.05rem;
}

.perm-row-label {
  font-weight: 500;
  color: #1f2937;
  font-size: 0.9rem;
}

.perm-segments {
  display: inline-flex;
  background-color: #f3f4f6;
  border-radius: 10px;
  padding: 3px;
  margin-left: auto;
}

.perm-segments input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.perm-segments label {
  position: relative;
  padding: 0.35rem 0.85rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  margin: 0;
}

.perm-segments label:hover {
  color: #374151;
}

.perm-segments input[type="radio"]:checked + .perm-seg-label {
  background-color: white;
  color: var(--perm-color, #001738);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

.footer {
  margin-top: auto;
  width: 100%;
  background-color: rgba(248, 249, 250, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid #dee2e6;
  padding: 0.25rem 0;
  min-height: 56px;
  align-items: center;
}

.footer .container-fluid,
.sidebar-footer .p-3 {
  padding: 0 1rem !important;
}

/* ─── Backdrop overlay (shared, used by both sidebars) ───────── */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 1025;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-backdrop.show {
  opacity: 1;
  visibility: visible;
}

/* ─── Mobile adjustments ─────────────────────────────────────── */
@media (max-width: 991px) {
  .container {
    padding: 1rem 15px;
  }

  .topbar {
    padding: 0.5rem 0.75rem;
  }

  .topbar-logo img {
    height: 28px !important;
  }

  .sidebar {
    left: 8px;
    top: 64px;
    height: calc(100vh - 72px);
    width: min(280px, calc(100vw - 16px));
  }

  .section-switcher {
    right: 8px;
    top: 64px;
    height: calc(100vh - 72px);
    width: min(240px, calc(100vw - 16px));
  }
}

/* Recipe tree — selected row highlight */
.tree-row-selected {
  background-color: rgba(13, 110, 253, 0.08) !important;
  border-left: 3px solid #0d6efd;
}

/* RM link button on tree rows */
.rm-link {
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
}

/* Turbo frame loading indicator */
turbo-frame[busy] {
  opacity: 0.6;
}
