/*************************************************
 * Header
 *************************************************/

#app-header {
  height: 96px;
  background: linear-gradient(
    to bottom,
    #f0f2f4,
    #e3e6ea
  );
  border-bottom: 1px solid #c9ced6;

  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 0 32px;
}

/*************************************************
 * Body Wrapper (Centers Entire UI)
 *************************************************/

#app-body {
  display: flex;
  justify-content: center;
  width: 100%;
}

/*************************************************
 * Main Layout (Two-Column Grid)
 *************************************************/

#app-main {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 32px;

  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;

  align-items: stretch; /* CRITICAL */
}

.theme-card {
  aspect-ratio: 16 / 8.1;
}

#database-dropdown {
  margin-top: 8px;
}


/*************************************************
 * Left / Right Panes
 *************************************************/

#left-pane {
  display: flex;
  flex-direction: column;
  gap: 4px;  /* REVISED: was 24px - minimal spacing */
}

#right-pane {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

/*************************************************
 * File Library Alignment
 *************************************************/

#file-library {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#file-library .file-list {
  flex: 1;
  overflow-y: auto;
}

/*************************************************
 * Utility
 *************************************************/

.hidden {
  display: none !important;
}

/*************************************************
 * Modal Base
 *************************************************/

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

/*************************************************
 * Modal Content (Auth)
 *************************************************/

.modal-content {
  position: relative;
  background: #ffffff;

  width: 432px;
  min-height: 375px;

  margin: 10vh auto;
  padding: 32px 36px;

  border-radius: 14px;

  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.4);
}

/*************************************************
 * Modal Typography
 *************************************************/

#auth-title {
  margin-bottom: 24px;
  font-size: 22px;
  font-weight: 700;
  color: #0b2d4f;
}

/*************************************************
 * Modal Form Inputs
 *************************************************/

#auth-form input {
  width: 100%;
  height: 48px;
  font-size: 16px;

  padding: 0 14px;
  margin-bottom: 16px;

  border-radius: 6px;
  border: 1px solid #b8bec7;

  background: linear-gradient(
    to bottom,
    #f7f8fa,
    #e9ecf0
  );

  color: #0b2d4f;

  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

#auth-form input:focus {
  outline: none;
  border-color: #0b2d4f;
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(11, 45, 79, 0.15);
}

/*************************************************
 * Modal Primary Button
 *************************************************/

#auth-submit {
  width: 100%;
  height: 44px;
  margin-top: 12px;

  background: linear-gradient(
    to bottom,
    #f0f2f4,
    #e3e6ea
  );

  border: 1px solid #b8bec7;
  border-radius: 8px;

  font-size: 16px;
  font-weight: 700;
  color: #0b2d4f;

  cursor: pointer;

  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.25);

  transition:
    background 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.1s ease;
}

#auth-submit:hover {
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.3);
}

#auth-submit:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

/*************************************************
 * Auth Mode Switch
 *************************************************/

.auth-switch {
  margin-top: 18px;
  text-align: center;
  font-size: 14px;
  color: #4b5563;
}

.auth-switch a {
  margin-left: 6px;
  font-weight: 600;
  color: #0b2d4f;
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/*************************************************
 * Upload / Processing Spinner Overlay
 *************************************************/

#upload-spinner {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(255, 255, 255, 0.75);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#upload-spinner .spinner {
  width: 48px;
  height: 48px;

  border: 4px solid #cbd5e1;
  border-top-color: #0b2d4f;
  border-radius: 50%;

  animation: spinner-rotate 0.9s linear infinite;
}

#upload-spinner .spinner-label {
  margin-top: 14px;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

/*************************************************
 * Landscape Layout (Corrected + Deterministic)
 *
 * Row 1: Upload (col 1) + Filters/Search (col 2)
 * Row 2: Library (full width)
 * Row 3: Database dropdown (full width)
 * Row 4: Themes (full width)
 *************************************************/

body[data-layout="landscape"] #app-main {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* Flatten panes so children participate in grid */
body[data-layout="landscape"] #left-pane,
body[data-layout="landscape"] #right-pane {
  display: contents;
}

/* Row 1 */
body[data-layout="landscape"] #upload-area {
  grid-column: 1;
  grid-row: 1;
}

body[data-layout="landscape"] #library-filters {
  grid-column: 2;
  grid-row: 1;
}

/* Row 2: Library */
body[data-layout="landscape"] #file-library {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: 24px;
  min-height: 30vh;
}

/* Row 3: Database dropdown (EXPLICIT FIX) */
body[data-layout="landscape"] #database-dropdown {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-top: 16px;
}

/* Row 4: Themes */
body[data-layout="landscape"] #themes-section {
  grid-column: 1 / -1;
  grid-row: 4;
  margin-top: 24px;
}

/* Themes grid */
body[data-layout="landscape"] #themes-grid {
  grid-template-columns: repeat(4, 1fr);
  max-width: 1200px;
  margin: 0 auto;
  gap: 28px;
}

/* Constrain top row width */
body[data-layout="landscape"] #upload-area,
body[data-layout="landscape"] #library-filters {
  max-width: 1200px;
}

body[data-layout="landscape"] #upload-area {
  justify-self: start;
}

body[data-layout="landscape"] #library-filters {
  justify-self: end;
}

/*************************************************
 * App Mode Visibility Control
 *************************************************/

#admin-mode {
  display: none;
}

body.admin-active #admin-mode {
  display: block;
}

body.admin-active #user-mode {
  display: none;
}
