/* App Layout */

/* Loading Screen */
#app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  z-index: 9999;
}

/* Login Screen */
#app-login {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

#app-login.active {
  display: flex;
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.login-card h1 {
  font-size: var(--text-xl);
  text-align: center;
}

.login-card .login-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-align: center;
  margin-top: calc(-1 * var(--space-4));
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.login-error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  text-align: center;
  display: none;
}

.login-error.visible {
  display: block;
}

/* App Shell */
#app-shell {
  display: none;
  height: 100vh;
}

#app-shell.active {
  display: flex;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--color-primary);
  border-right: none;
  display: flex;
  flex-direction: column;
  padding: var(--space-6);
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: block;
  max-width: 160px;
  margin: 0 auto var(--space-6);
}

.sidebar-greeting {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: var(--space-1);
}

.sidebar-username {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-white);
  margin-bottom: var(--space-8);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer;
}

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

.sidebar-nav-item.active {
  background: rgba(255, 255, 255, 0.14);
  color: var(--color-white);
}

.sidebar-nav-item img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
  opacity: 0.45;
  transition: opacity var(--transition-fast);
}

.sidebar-nav-item:hover img,
.sidebar-nav-item.active img {
  opacity: 1;
}

.sidebar-spacer {
  flex: 1;
}

.sidebar-signout {
  margin-top: auto;
}

/* Main Content */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8);
  min-width: 0;
}

.view-container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.view-title {
  font-size: var(--text-2xl);
  font-weight: 700;
}

/* Responsive */
@media (max-width: 800px) {
  #app-shell.active {
    flex-direction: column-reverse;
  }

  #sidebar {
    width: 100%;
    flex-direction: row;
    padding: var(--space-2) var(--space-4);
    border-right: none;
    border-top: none;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .sidebar-logo,
  .sidebar-greeting,
  .sidebar-username,
  .sidebar-spacer {
    display: none;
  }

  .sidebar-nav {
    flex-direction: row;
    gap: var(--space-1);
    flex: 1;
    justify-content: space-around;
    margin-bottom: 0;
  }

  .sidebar-nav-item {
    flex-direction: column;
    font-size: 10px;
    padding: var(--space-2);
    gap: var(--space-1);
  }

  .sidebar-signout {
    margin-top: 0;
  }

  #main-content {
    padding: var(--space-4);
    height: calc(100vh - 64px);
  }
}
