/* App Shell & Layout */

.app-root {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-root--login {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 24px 16px;
}

.app-root--shell {
  display: block;
}

/* Main menu container - full height layout */
.main-menu-container {
  display: flex;
  width: 100%;
  min-width: 100%;
  height: 100vh;
  min-height: 100dvh;
  background-color: #135909;
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-sizing: border-box;
}

/* Sidebar styling */
.sidebar {
  width: 250px;
  background-color: #135909;
  color: #fff;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  position: relative;
  border-right: 2.8px solid #8b4513;
}

.sidebar-footer {
  padding: 20px;
  text-align: center;
}

.logout-button {
  background-color: transparent;
  border: 1px solid #d9534f;
  color: #d9534f;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
}

.logout-button:focus,
.logout-button:focus-visible,
.expand-btn:focus,
.expand-btn:focus-visible {
  outline: 2px solid #f0ad4e;
  outline-offset: 2px;
}

.sidebar .logo-section {
  padding: 15px 20px 10px;
  text-align: center;
}

.sidebar .logo-section h2 {
  margin: 5px 0 10px 0;
  font-size: 1.2em;
}

.sidebar-logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
}

/* Navigation menu */
.nav-menu {
  padding: 10px 0;
  flex-grow: 1;
}

.nav-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  margin: 5px 15px;
}

.nav-item a {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.8);
  border-radius: 5px;
  transition: all 0.3s ease;
}

.nav-item a:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-item a:focus,
.nav-item a:focus-visible {
  outline: 2px solid #f0ad4e;
  outline-offset: 2px;
}

.nav-item.active a {
  background-color: rgba(240, 173, 78, 0.2);
  color: #fff;
}

.nav-icon {
  margin-right: 12px;
  font-size: 1.2em;
  width: 24px;
  text-align: center;
}

.nav-text {
  flex-grow: 1;
}

/* Main content area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: auto;
  background-color: #1a6b10;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: rgba(0, 0, 0, 0.1);
  position: relative;
  border-bottom: 2.8px solid #8b4513;
  margin-bottom: 0;
  padding-bottom: 15px;
}

.main-header h1 {
  margin: 0;
  font-size: 1.5em;
  color: #fff;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mode-badge-readonly {
  color: #f0ad4e;
  border: 1px solid rgba(240, 173, 78, 0.7);
  background: rgba(240, 173, 78, 0.12);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.header-primary {
  display: flex;
  align-items: center;
  min-width: 0;
}

.refresh-btn {
  background: transparent;
  border: 1px solid #f0ad4e;
  color: #f0ad4e;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  margin-left: 15px;
}

.mobile-menu-backdrop {
  display: none;
}

.refresh-btn:hover {
  background-color: #f0ad4e;
  color: #fff;
}

.refresh-btn:focus,
.refresh-btn:focus-visible {
  outline: 2px solid #f0ad4e;
  outline-offset: 2px;
}

.content-wrapper {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

/* Error Banner */
.error-banner {
  background-color: #d9534f;
  color: #fff;
  padding: 10px 20px;
  margin-bottom: 20px;
  border-radius: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: slideDown 0.3s ease;
}

.error-banner-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5em;
  cursor: pointer;
  line-height: 1;
}

@keyframes slideDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Tab content styling */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
  position: relative;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Responsive design */
:root {
  --header-height: 75px;
}

@media (max-width: 1024px) {
  :root {
    --header-height: 64px;
    --mobile-menu-gap: 12px;
  }

  .main-menu-container {
    flex-direction: column;
    position: relative;
    width: 100%;
    min-width: 100%;
    /* Ensure container doesn't overflow improperly */
    overflow-x: hidden;
  }

  /* Make Main Content fill the screen and sit at the top */
  .main-content {
    width: 100%;
    min-width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh; /* Force full height */
    min-height: 100dvh;
  }

  /* Sidebar: The Hidden Dropdown */
  .sidebar {
    position: absolute;
    top: calc(var(--header-height) + var(--mobile-menu-gap));
    left: var(--mobile-menu-gap);
    right: var(--mobile-menu-gap);
    width: auto;
    height: auto;
    max-height: calc(
      100vh - var(--header-height) - (var(--mobile-menu-gap) * 2)
    );
    z-index: 1003;
    transform: translateY(-18px) scale(0.98);
    transform-origin: top center;
    visibility: hidden;
    opacity: 0;
    transition:
      transform 0.22s ease,
      opacity 0.22s ease,
      visibility 0.22s ease;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid rgba(240, 173, 78, 0.35);
    border-right: 1px solid rgba(240, 173, 78, 0.35);
    border-bottom: 1px solid rgba(240, 173, 78, 0.35);
    border-radius: 18px;
    background: linear-gradient(
      180deg,
      rgba(19, 89, 9, 0.98),
      rgba(16, 72, 10, 0.98)
    );
  }

  .main-menu-container.mobile-menu-open .sidebar {
    transform: translateY(0);
    visibility: visible;
    opacity: 1;
  }

  .mobile-menu-backdrop {
    position: absolute;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    left: 0;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(7, 33, 4, 0.32);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 1002;
  }

  .main-menu-container.mobile-menu-open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Adjust Nav Items for Dropdown */
  .nav-menu {
    padding: 12px 0 8px;
  }

  .nav-menu ul {
    display: flex;
    flex-direction: column; /* Stack vertically in dropdown */
  }

  .nav-item {
    margin: 4px 12px;
  }

  .nav-item a {
    padding: 11px 14px;
    font-size: 1rem;
    justify-content: flex-start; /* Align left */
    border-radius: 12px;
  }

  .sidebar-footer {
    padding: 14px 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .logout-button {
    width: 100%;
    min-height: 40px;
    border-radius: 12px;
  }

  .nav-icon {
    display: inline-block; /* Show icons in dropdown */
  }

  /* Header Controls */
  .expand-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(240, 173, 78, 0.35);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    margin-right: 12px;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
  }

  .title-group {
    min-width: 0;
  }

  /* Ensure Header stays visible */
  .main-header {
    position: relative;
    z-index: 1002; /* Above the content and backdrop */
    background-color: #135909; /* Match brand color */
    height: var(--header-height);
    box-sizing: border-box;
    /* Reset padding to vertical center with flex */
    padding-top: 0;
    padding-bottom: 0;
    /* We keep left/right padding from global rule (20px) but remove top/bottom 
       to ensure the 75px height is strictly respected with flex alignment */
  }
}

@media (max-width: 768px) {
  /* Refinements for smaller phones */
  :root {
    --header-height: 58px;
    --mobile-menu-gap: 10px;
  }

  .main-header {
    padding-left: var(--mobile-shell-padding);
    padding-right: var(--mobile-shell-padding);
  }

  .header-content {
    gap: var(--mobile-header-gap);
  }

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

  .title-group {
    flex: 1;
    min-width: 0;
  }

  .title-row {
    gap: var(--mobile-header-gap);
    min-width: 0;
    flex-wrap: wrap;
  }

  .main-header h1 {
    font-size: 1.2rem;
    line-height: 1.1;
  }

  #page-title {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mode-badge {
    padding: 3px 8px;
    font-size: 0.68rem;
  }

  .refresh-btn {
    width: 34px;
    height: 34px;
    margin-left: 0;
    flex-shrink: 0;
  }

  .expand-btn {
    margin-right: 10px;
  }

  .content-wrapper {
    padding: var(--mobile-shell-padding);
  }

  .error-banner {
    padding: 10px 12px;
    margin-bottom: var(--mobile-section-gap);
  }

  .main-content .secondary-btn,
  .main-content .view-toggle-btn,
  .main-content .action-btn,
  .main-content
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  .main-content select,
  .main-content textarea {
    min-height: var(--mobile-control-height);
    padding: var(--mobile-control-padding-y) var(--mobile-control-padding-x);
    box-sizing: border-box;
  }

  .main-content .secondary-btn,
  .main-content .view-toggle-btn,
  .main-content .action-btn {
    line-height: 1.2;
  }

  .main-content .timeframe-selector select {
    padding-right: 30px;
  }

  .sidebar .logo-section {
    display: none; /* Hide logo to save space on small phones */
  }
}
