/* ============================================================
   GLOBAL SIDEBAR — Cardinal Energy Solar CRM
   Shared by home.html and project.html
   ============================================================ */

/* App shell: sidebar + main content side by side */
.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.g-sidebar {
  width: 256px;
  min-width: 256px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, min-width 0.2s ease;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

.g-sidebar.collapsed {
  width: 48px;
  min-width: 48px;
}

/* ── Sidebar header / brand ─────────────────────────────── */
.g-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  min-height: 57px;
  flex-shrink: 0;
}

.g-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  overflow: hidden;
  cursor: pointer;
}

.g-sidebar-logo {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: linear-gradient(135deg, #327dff, #0f58ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
:root[data-theme="light"] .g-sidebar-logo {
  background: linear-gradient(135deg, #4299e1, #3182ce);
}
.g-sidebar-logo svg {
  width: 18px;
  height: 18px;
  color: white;
}

.g-sidebar-brand-text {
  overflow: hidden;
  white-space: nowrap;
}
.g-sidebar-brand-text strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}
.g-sidebar-brand-text span {
  font-size: 11px;
  color: var(--muted);
}

.g-sidebar-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.g-sidebar-toggle:hover {
  background: var(--hover-bg);
  color: var(--ink);
}
.g-sidebar-toggle svg {
  width: 16px;
  height: 16px;
}

/* ── Scrollable body ─────────────────────────────────────── */
.g-sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}
.g-sidebar-body::-webkit-scrollbar { width: 4px; }
.g-sidebar-body::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }

/* ── Section labels ─────────────────────────────────────── */
.g-sidebar-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.g-sidebar-section-label svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.g-sidebar-section-label.collapsed-section svg {
  transform: rotate(-90deg);
}

/* ── Menu items ─────────────────────────────────────────── */
.g-sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  transition: background 0.15s;
  border: none;
  background: none;
  width: calc(100% - 12px);
  text-align: left;
}
.g-sidebar-item:hover {
  background: var(--hover-bg);
}
.g-sidebar-item.active {
  background: rgba(59, 130, 246, 0.12);
  color: #3b82f6;
  font-weight: 600;
}
.g-sidebar-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Portfolio group dot ────────────────────────────────── */
.g-sidebar-dot {
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Badge (count) ──────────────────────────────────────── */
.g-sidebar-badge {
  font-size: 11px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
  white-space: nowrap;
}
:root[data-theme="light"] .g-sidebar-badge {
  background: rgba(49, 130, 206, 0.12);
}

/* ── Status dot (project open/closed) ───────────────────── */
.g-status-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.g-status-dot.open   { background: #3b82f6; }
.g-status-dot.closed { background: var(--muted); opacity: 0.5; }

/* ── Manage portfolios link ─────────────────────────────── */
.g-manage-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin: 2px 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  border: none;
  background: none;
  width: calc(100% - 12px);
  text-align: left;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.g-manage-link:hover {
  background: var(--hover-bg);
  color: var(--ink);
}
.g-manage-link svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Divider ────────────────────────────────────────────── */
.g-sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}

/* ── Footer ─────────────────────────────────────────────── */
.g-sidebar-footer {
  padding: 10px 12px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Collapsed state: hide text elements ────────────────── */
.g-sidebar.collapsed .g-sidebar-brand-text,
.g-sidebar.collapsed .g-sidebar-section-label span,
.g-sidebar.collapsed .g-sidebar-section-label svg,
.g-sidebar.collapsed .g-sidebar-item-label,
.g-sidebar.collapsed .g-sidebar-badge,
.g-sidebar.collapsed .g-manage-link span,
.g-sidebar.collapsed .g-sidebar-footer span,
.g-sidebar.collapsed .g-sidebar-divider {
  display: none;
}

/* In collapsed mode show the dot instead of the badge */
#disc-sidebar-dot { display: none; }
.g-sidebar.collapsed #disc-sidebar-badge { display: none !important; }
.g-sidebar.collapsed #disc-sidebar-dot.has-unread { display: block !important; }
.g-sidebar.collapsed .g-sidebar-item {
  justify-content: center;
  padding: 8px;
  margin: 1px 4px;
}
.g-sidebar.collapsed .g-sidebar-section-label {
  justify-content: center;
  padding: 8px 4px;
}
.g-sidebar.collapsed .g-manage-link {
  justify-content: center;
  padding: 8px 4px;
}

/* ============================================================
   MANAGE PORTFOLIOS MODAL
   ============================================================ */
.g-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.g-modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.g-modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
}
.g-modal-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.g-modal-header p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.g-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.g-modal-close:hover { color: var(--ink); background: var(--hover-bg); }

.g-modal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left pane: group list */
.g-modal-left {
  width: 220px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.g-modal-left-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}
.g-modal-left-header button {
  background: none;
  border: 1px solid var(--border-dark);
  color: var(--ink);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.g-modal-left-header button:hover { background: var(--hover-bg); }

.g-modal-group-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.g-modal-group-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  transition: background 0.15s;
}
.g-modal-group-item:hover { background: var(--hover-bg); }
.g-modal-group-item.selected {
  background: rgba(59,130,246,0.12);
  color: #3b82f6;
  font-weight: 600;
}
.g-modal-group-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.g-modal-group-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.g-modal-group-item:hover .g-modal-group-actions { opacity: 1; }
.g-modal-group-actions button {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted);
}
.g-modal-group-actions button:hover { background: var(--border); color: var(--ink); }

/* Right pane: project checklist */
.g-modal-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.g-modal-right-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.g-modal-right-header h3 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.g-modal-right-header p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.g-modal-project-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
}
.g-modal-project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.g-modal-project-item:hover { background: var(--hover-bg); }
.g-modal-project-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: #3b82f6;
}
.g-modal-project-info { flex: 1; overflow: hidden; }
.g-modal-project-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.g-modal-project-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-modal-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.g-modal-footer button {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border-dark);
  background: var(--card);
  color: var(--ink);
  transition: background 0.15s;
}
.g-modal-footer button:hover { background: var(--hover-bg); }
.g-modal-footer button.primary-btn {
  background: linear-gradient(180deg, #327dff, #0f58ff);
  border-color: #0f58ff;
  color: white;
}
:root[data-theme="light"] .g-modal-footer button.primary-btn {
  background: linear-gradient(180deg, #4299e1, #3182ce);
  border-color: #3182ce;
}
.g-modal-footer button.primary-btn:hover { opacity: 0.92; }

/* Rename input inside group item */
.g-group-rename-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid #3b82f6;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
  padding: 3px 8px;
  outline: none;
}
