/* ===========================================
   INSTAPANEL — Layout
   Sidebar, Topbar, Content area
   =========================================== */

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

html, body {
  height: 100%;
  font-family: var(--font-family);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===========================================
   APP LAYOUT — Grid
   =========================================== */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ===========================================
   SIDEBAR
   =========================================== */
.sidebar {
  grid-area: sidebar;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--primary);
  color: var(--white);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--transition-base);
  overflow: hidden;
}

/* --- Brand / Logo --- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1.2rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: var(--topbar-height);
}

.sidebar-brand img {
  height: 28px;
  width: auto;
  filter: brightness(0) invert(1);
}

.sidebar-brand-text {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* --- Navigation --- */
.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.7rem 1.25rem;
  margin: 2px 0.6rem;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
}

.sidebar-item.active {
  background: var(--accent);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-item.active .sidebar-icon svg {
  stroke: var(--primary);
}

.sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.sidebar-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Badge --- */
.sidebar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

.sidebar-item.active .sidebar-badge {
  background: var(--primary);
  color: var(--white);
}

/* --- Footer --- */
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
}

.sidebar-footer-version {
  opacity: 0.5;
}

/* --- Toggle button (mobile/tablet) --- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--white);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===========================================
   TOPBAR
   =========================================== */
.topbar {
  grid-area: topbar;
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 90;
  box-shadow: var(--shadow-sm);
  transition: left var(--transition-base);
}

/* --- Search --- */
.topbar-search {
  position: relative;
  flex: 0 1 360px;
}

.topbar-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-search-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-search input {
  width: 100%;
  padding: 0.55rem 1rem 0.55rem 2.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  font-family: var(--font-family);
  font-size: 0.88rem;
  color: var(--text);
  outline: none;
  transition: all var(--transition-fast);
}

.topbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 176, 204, 0.15);
}

.topbar-search input::placeholder {
  color: var(--text-muted);
}

/* --- Right section --- */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* --- Notifications --- */
.topbar-notifications {
  position: relative;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.topbar-notifications:hover {
  background: var(--bg);
}

.topbar-notifications svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-light);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-notifications .notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-white);
}

/* --- User --- */
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  transition: background var(--transition-fast);
}

.topbar-user:hover {
  background: var(--bg);
}

.topbar-user-name {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.topbar-user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

/* ===========================================
   MAIN CONTENT
   =========================================== */
.main-content {
  grid-area: content;
  margin-top: var(--topbar-height);
  padding: 2rem;
  background: var(--bg);
  min-height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
}

/* --- Page Header --- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===========================================
   RESPONSIVE — Sidebar collapse < 1024px
   =========================================== */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 60px;
  }

  .sidebar-brand-text,
  .sidebar-label,
  .sidebar-badge,
  .sidebar-footer {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity var(--transition-fast);
  }

  .sidebar-brand {
    justify-content: center;
    padding: 1.2rem 0.5rem;
  }

  .sidebar-item {
    justify-content: center;
    padding: 0.7rem;
    margin: 2px 0.4rem;
  }

  .sidebar-toggle {
    display: flex;
  }

  .topbar {
    left: 60px;
    padding: 0 1rem;
  }

  .topbar-search {
    flex: 0 1 200px;
  }

  .topbar-user-name,
  .topbar-user-role {
    display: none;
  }

  /* Expanded state */
  .sidebar.expanded {
    width: 250px;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.expanded .sidebar-brand-text,
  .sidebar.expanded .sidebar-label,
  .sidebar.expanded .sidebar-badge,
  .sidebar.expanded .sidebar-footer {
    opacity: 1;
    width: auto;
  }

  .sidebar.expanded .sidebar-brand {
    justify-content: flex-start;
    padding: 1.2rem 1.25rem;
  }

  .sidebar.expanded .sidebar-item {
    justify-content: flex-start;
    padding: 0.7rem 1.25rem;
    margin: 2px 0.6rem;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    width: 0;
    transform: translateX(-100%);
  }

  .sidebar.expanded {
    width: 250px;
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .topbar {
    left: 0;
    padding: 0 1rem 0 3.5rem;
  }

  .main-content {
    padding: 1.5rem 1rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ===========================================
   SIDEBAR OVERLAY (mobile)
   =========================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

.sidebar-overlay.show {
  display: block;
}
