/* public/css/main.css — Grey-White Theme Design System */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Grey-White Theme Design Tokens ────────────────────────────── */
:root {
  /* Surfaces */
  --bg-main:         #ffffff;       /* Pure white main content */
  --bg-sidebar:      #eef1f5;       /* Grey background for sidebars */
  --bg-topbar:       #eef1f5;       /* Grey background for top menu bar */
  --bg-subtle:       #f4f6f9;       /* Light neutral grey */
  --bg-input-focus:  #eceff4;       /* Light grey for input in focus */
  --bg-hover:        #e2e6ec;       /* Grey hover */
  --bg-card:         #ffffff;

  /* Borders */
  --border-color:    #d5dbe3;
  --border-light:    #e5e9f0;
  --border-dark:     #4b5563;

  /* Typography */
  --text-main:       #111827;       /* Dark slate / black */
  --text-muted:      #4b5563;       /* Slate grey */
  --text-subtle:     #6b7280;       /* Lighter slate */
  --text-inverse:    #ffffff;

  /* Accent & Status Colors (Sleek monochrome with subtle status accents) */
  --accent:          #1f2937;       /* Deep slate accent */
  --accent-hover:    #111827;
  --accent-light:    #e5e7eb;

  --success:         #059669;
  --success-bg:      #ecfdf5;
  --warning:         #d97706;
  --warning-bg:      #fffbeb;
  --danger:          #dc2626;
  --danger-bg:       #fef2f2;
  --info:            #2563eb;
  --info-bg:         #eff6ff;

  /* Layout dimensions */
  --sidebar-width:   240px;
  --topbar-height:   52px;
  --radius-sm:       4px;
  --radius-md:       8px;
  --radius-lg:       12px;

  /* Transitions & Shadows */
  --shadow-sm:       0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md:       0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg:       0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --transition:      0.15s ease-in-out;
}

/* ── Base & Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ── Form Inputs (Light Grey on Focus) ─────────────────────────── */
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.875rem;
  transition: background-color var(--transition), border-color var(--transition);
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  background-color: var(--bg-input-focus); /* Light grey for input in focus */
  border-color: var(--border-dark);
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-group {
  margin-bottom: 0.9rem;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: #d8dde5;
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-dark);
}

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

/* ── Fixed Horizontally Scrollable Top Menu Bar with Fade Gradient */
.top-menu-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background-color: var(--bg-topbar); /* Grey background */
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  z-index: 40;
  padding: 0 1rem;
}

.top-menu-scroll-container {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
  height: 100%;
}

.top-menu-items {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  padding-right: 3rem; /* space for gradient */
  height: 100%;
}
.top-menu-items::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Fade Gradient at right end */
.top-menu-fade-gradient {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50px;
  background: linear-gradient(to right, rgba(238, 241, 245, 0), rgba(238, 241, 245, 1));
  pointer-events: none;
}

.top-menu-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all var(--transition);
}
.top-menu-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}
.top-menu-item.active {
  background-color: #ffffff;
  color: var(--text-main);
  border-color: var(--border-color);
  font-weight: 600;
}

/* ── Layout Framework ─────────────────────────────────────────── */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--bg-sidebar); /* Grey background */
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
  position: relative;
}

/* Sidebar Edge Hover Zone (shows on mouse hover on left edge when collapsed) */
.sidebar-edge-zone {
  position: fixed;
  top: 0;
  left: 0;
  width: 14px;
  height: 100vh;
  z-index: 60;
  background: transparent;
  display: none;
}

body.sidebar-is-collapsed .sidebar-edge-zone {
  display: block;
}

/* Collapsed state styling */
body.sidebar-is-collapsed .sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  transform: translateX(-100%);
  box-shadow: none;
}

body.sidebar-is-collapsed .sidebar.sidebar-hover-reveal {
  transform: translateX(0);
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.12);
}

body.sidebar-is-collapsed .top-menu-bar {
  left: 0;
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-menu-bar {
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  height: var(--topbar-height);
  padding: 0 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 0.95rem;
}

.sidebar-brand-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-sidebar-collapse {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-sidebar-collapse:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-dark);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background-color var(--transition), color var(--transition);
}
.sidebar-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}
.sidebar-btn.active {
  background-color: #ffffff;
  color: var(--text-main);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

#sidebar-user-trigger:hover {
  background-color: var(--bg-hover);
}
#sidebar-user-trigger.active {
  background-color: #ffffff;
  box-shadow: var(--shadow-sm);
}
#sidebar-user-trigger:focus-visible {
  outline: 2px solid var(--border-dark);
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 0.75rem;
  background-color: var(--bg-sidebar);
}

/* Main Content Area (Pure White Background) */
.main-wrapper {
  flex: 1;
  margin-top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  background-color: var(--bg-main); /* White background */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 0; /* ensures flex:1 doesn't overflow beyond sidebar boundary */
}

/* Page pane fills parent width */
.page-pane {
  width: 100%;
  flex: 1;
}

/* External iframe pane: fills full height, no padding */
#pane-external {
  padding: 0;
  flex: 1;
  display: none; /* overridden to flex by navigateTo */
  flex-direction: column;
  min-height: 0;
}

#pane-external iframe {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
}

/* ── Back Arrow Button ─────────────────────────────────────────── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: all var(--transition);
}
.btn-back:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-dark);
}

/* ── Config Tiles ──────────────────────────────────────────────── */
.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.tile-card {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.tile-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-dark);
  box-shadow: var(--shadow-md);
}

.tile-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background-color: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.tile-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}
.tile-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Users Management View ─────────────────────────────────────── */
.users-view-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height) - 6rem);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #ffffff;
}

.users-list-sidebar {
  width: 280px;
  background-color: var(--bg-sidebar); /* Grey sub-sidebar */
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.users-list-controls {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.users-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.user-group-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 0.4rem 0.5rem 0.2rem;
  letter-spacing: 0.05em;
}

.user-card-item {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: all var(--transition);
}
.user-card-item:hover {
  background-color: #f8fafc;
  border-color: var(--border-dark);
}
.user-card-item.selected {
  background-color: #e5e7eb;
  border-color: var(--accent);
  font-weight: 600;
}

.user-details-main {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  background-color: #ffffff;
}

/* ── Bottom-Right Tooltip Notifications ────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 260px;
  max-width: 380px;
  background-color: #1f2937;
  color: #f9fafb;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.84rem;
  animation: toastSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 4px solid #9ca3af;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger  { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--info); }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-no-perm {
  background-color: #fee2e2;
  color: #b91c1c;
}
.badge-admin {
  background-color: #e0e7ff;
  color: #3730a3;
}
.badge-user {
  background-color: #f3f4f6;
  color: #4b5563;
}

/* Responsive */
/* ── Admin Management View (Integrated into main.html) ────────── */
.admin-view-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height) - 4rem);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #ffffff;
}

.admin-sub-sidebar {
  width: 290px;
  min-width: 260px;
  background-color: var(--bg-sidebar); /* Grey sub-sidebar */
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.admin-filter-box {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-search-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.admin-search-input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.admin-search-clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.75rem;
  line-height: 1;
  border-radius: var(--radius-sm);
}

.admin-search-clear-btn:hover {
  color: var(--text-main);
}


.btn-add-item {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  background: #ffffff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
  font-size: 0.9rem;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-add-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.admin-item-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.admin-list-item {
  padding: 0.65rem 0.85rem;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.admin-list-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-dark);
}

.admin-list-item.selected {
  border-left: 4px solid var(--accent);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.admin-content-area {
  flex: 1;
  background: #ffffff;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
}

.section-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.85rem;
  margin-bottom: 1.25rem;
}

.section-nav-arrows {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-arrow {
  padding: 0.4rem 0.75rem;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  transition: all var(--transition);
}

.btn-arrow:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.admin-form-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  max-width: 800px;
}

.admin-form-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .top-menu-bar {
    left: 0;
  }
}
