/* ========================================================================
   MUNI SUITE - LAYOUT.CSS (Mobile-First)
   ------------------------------------------------------------------------
   This file contains only the structural and layout-related styles for
   the MUNI application. It is intended to be the foundational layer,
   free of color, typography, or other aesthetic styling.
   ======================================================================== */

/* ========================================================================
   1. CSS RESET
   ======================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 12pt;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden; 
}

svg {
  display: block;
  max-width: 100%;
  height: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  margin: 0;
  padding: var(--space-xs) var(--space-sm);
  border: none;
  background: none;
}

button {
  cursor: pointer;
}

p,
h1,
h2,
h3 {
  overflow-wrap: break-word;
  margin: 0;
}

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

hr {
  margin: var(--space-lg) 0;
}

/* ========================================================================
   2. UTILITY & BEHAVIORAL CLASSES
   ======================================================================== */
.hidden {
  display: none !important;
}

:disabled,
[disabled] {
  cursor: not-allowed !important; 
}

body.modal-open {
  overflow: hidden;
}


/* ========================================================================
   3. CORE APP LAYOUT
   ======================================================================== */
body {
  display: flex;
  flex-direction: column;
}

#app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-md);
}

#header-left,
#header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

header .pill {
  padding: 0 var(--space-xs);
}

#main-content {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--space-md);
  padding-top: 0;
}


/* ========================================================================
   4. DASHBOARD
   ======================================================================== */
#dashboard-view {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.dashboard-controls,
.dashboard-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
}

#project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
  padding-top: var(--space-md);
}

#project-filter-pills {
  display: flex;
  gap: var(--space-xs);
}

.project-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-md);
}

.project-card .pill {
  padding: var(--space-xs) var(--space-sm);
}

.project-card-footer {
  margin-top: auto;
  padding: var(--space-sm) 0;
}

.project-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}


/* ========================================================================
   5. EDITOR (SHARED COMPONENTS)
   ======================================================================== */
#editor-view {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: var(--space-md);
}

#editor-content-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-view-panel {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: var(--space-md);
}

.table-wrapper {
    overflow-x: auto;
    flex-grow: 1;
}

/* --- Mobile-First Generic Table Layout --- */
table {
    width: 100%;
    border-collapse: collapse;
}

#quest-edit-table thead,
#events-table thead,
#lace-deck-table thead {
  display: none;
}

#quest-edit-table tr,
#events-table tr,
#lace-deck-table tr {
  display: block;
  vertical-align: top;
  margin-bottom: var(--space-md);
}

#quest-edit-table td,
#events-table td,
#lace-deck-table td {
  display: flex;
  width: 100%;
  text-align: left;
  padding: var(--space-xs);
}

#quest-edit-table td input,
#quest-edit-table td textarea,
#events-table td input,
#lace-deck-table td input,
#lace-deck-table td select,
#lace-deck-table td textarea {
  width: 100%;
  max-height: 8rem;
}

.quest-actions-cell,
.lace-actions-cell {
  justify-content: flex-end;
  gap: var(--space-xs);
  padding-right: var(--space-xs) !important;
}

.quest-input-num,
.deck-input-pip {
  text-align: center;
}

/* --- Generic Preview Pane --- */
.quest-preview-passage { margin: var(--space-xl) 0; }
.prose-preview-container h1 { margin: var(--space-lg) 0; }
.prose-preview-container h2 { margin: var(--space-lg) 0; }
.prose-preview-container h3 { margin: var(--space-md) 0; }
.prose-preview-container p { margin: var(--space-md) 0; }


/* ========================================================================
   6. PROJECT-SPECIFIC STYLES
   ======================================================================== */

/* --- 6.1 NOTE --- */
#note-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.note-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-md);
}

.card-content p:not(:first-child) { 
  margin: var(--space-md) 0; 
}

.card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#note-add-form {
  padding: var(--space-md);
}

#note-add-form textarea {
  width: 100%;
  height: 8rem;
  margin-bottom: var(--space-sm);
}

/* --- 6.2. BOOK --- */
.book-editor-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: var(--space-sm);
}

.book-editor-main {
    flex-grow: 1;
    resize: none;
    width: 100%;
}

.chapter-list-item {
  display: flex;
  justify-content: space-between;
}

/* --- 6.3. QUEST --- */
#quest-edit-table-id {
  width: 4rem;
}

/* --- 6.4. LACE --- */
.view-header {
  display: flex;
  justify-content: space-between;
}

.event-balancer-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.event-balancer-header {
  flex-shrink: 0;
  padding-bottom: var(--space-md);
}

.event-balancer-totals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  text-align: center;
}

.event-balancer-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
  flex-grow: 1;
  overflow-y: auto;
}

.event-card {
  padding: var(--space-xs);
}

.event-card input,
.event-card textarea {
  width: 100%;
}

.event-card-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.event-card-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-card-text {
  font-family: var(--font-content);
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

.event-input-playorder {
  width: 120px;
  text-align: center;
  font-family: var(--font-content);
}

.event-card-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  text-align: center;
  padding: var(--space-sm) 0;
}

.event-req-label {
  padding-right: var(--space-xs);
}

/* play view  */

.play-area {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.play-table {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
    padding: var(--space-xs);
}

.drawn-card-area {
    flex-shrink: 0;
}

.events-display-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.story-log {
    height: 300px;
    overflow-y: auto;
    padding: var(--space-sm);
}

.play-controls,
.play-info-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
}

.play-table-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0; /* Prevents flex overflow */
}

.play-card-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  text-align: center;
  gap: var(--space-xs);
}

.event-stack {
  padding: var(--space-sm);
}

.event-stack-header {
  margin-bottom: var(--space-sm);
}

.event-stack-cards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
}

/* preview view */

#lace-preview-deck {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.lace-preview-card {
  padding: var(--space-sm);
}

.lace-preview-pills {
  display: flex;
  justify-content: space-between;
}

.lace-preview-card .pill {
  padding: 0 var(--space-sm);
}

/* ========================================================================
   7. MODALS & OVERLAYS
   ======================================================================== */
.modal {
  position: fixed;
  z-index: 900;
  inset: 0;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-md);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin-top: 2rem;
  margin-left: auto;
  margin-right: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

#project-type-selector,
#import-type-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}
.project-type-option {
    cursor: pointer;
    padding: var(--space-sm);
}
.project-type-option p {
  margin-top: var(--space-xs);
}
.project-type-option .pill {
  padding: 0 var(--space-xs);
}

.data-viewer-content {
  max-height: 60vh;
  overflow-y: auto;
}

.data-viewer-content pre {
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

#file-drop-zone {
  padding: var(--space-lg) 0;
  text-align: center;
}

#toast-notification {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  padding: var(--space-xs) var(--space-sm);
  text-align: center;
}

#toast-notification.show {
  opacity: 1;
  visibility: visible;
}

/* ========================================================================
   8. DESKTOP OVERRIDES
   ======================================================================== */
@media (min-width: 769px) {
  /* --- Revert Modals to Centered on Desktop --- */
  .modal {
    align-items: center;
    padding: var(--space-lg);
  }
  .modal-content {
    margin-top: 0;
    width: 90%;
  }

  /* --- Revert Tables to Traditional Layout on Desktop --- */
  #quest-edit-table thead,
  #events-table thead,
  #lace-deck-table thead {
    display: table-header-group;
  }

  #quest-edit-table tr,
  #events-table tr,
  #lace-deck-table tr {
    display: table-row;
    margin-bottom: 0;
  }

  #quest-edit-table td,
  #events-table td,
  #lace-deck-table td {
    display: table-cell;
    width: auto;
    padding: var(--space-sm);
  }

  /* --- Revert LACE Play View to Side-by-Side on Desktop --- */
  .play-table {
    flex-direction: row;
    align-items: flex-start;
  }
  .play-table-side {
    flex-shrink: 0;
    width: 200px;
  }
}