/* GLOBAL */
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f3f4f6;
  color: #222;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* SHARED HEADER (identical to home) */
#header {
  background: #1f2937;
  color: white;
  padding: 14px 20px;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
  margin-bottom: 2px;
  min-height: 30px;
}

.header-title {
  font-size: 22px;
  font-weight: bold;
}

.header-subtitle {
  font-size: 13px;
  font-weight: normal;
  margin-top: 2px;
  opacity: 0.85;
}

/* HOME BUTTON */
.home-button,
.home-button:link,
.home-button:visited,
.home-button:active {
  color: #ffffff !important;
  background: transparent !important;
  border: 1px solid #ffffff !important;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none !important;
  font-size: 14px;
  font-weight: bold;
  display: inline-block;
  transition: background 0.2s ease, color 0.2s ease;
}

.header-top .home-button {
  align-self: flex-end;
  margin-bottom: -10px;
}

.home-button:hover {
  background: #ffffff !important;
  color: #1f2937 !important;
}

/* GRID LAYOUT */
#container {
  display: grid;
  grid-template-columns: 320px 1fr 350px;
  flex: 1;
  overflow: hidden;
}

/* LEFT PANE */
#left-pane {
  background: #ffffff;
  border-right: 1px solid #ddd;
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
}

.pane-title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.3px;
  margin: 0 0 12px 0;
  color: #111827;
}

#left-pane label {
  font-weight: bold;
  margin-top: 10px;
  display: block;
  margin-bottom: 4px;
  color: #111827;
}

#left-pane input,
#left-pane textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: "Courier New", monospace;
  background: #f9fafb;
  margin-bottom: 10px;
  font-size: 14px;
}

#left-pane textarea {
  height: 140px;
  resize: vertical;
}

/* BUTTONS */
#left-pane button {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  font-weight: bold;
  color: white;
}

#btn-generate { background: #2563eb; }
#btn-generate:hover { background: #1d4ed8; }

#btn-rewrite { background: #059669; }
#btn-rewrite:hover { background: #047857; }

#btn-export { background: #d97706; }
#btn-export:hover { background: #b45309; }

#copy { background: #6b7280; }
#copy:hover { background: #4b5563; }

/* STATUS */
.status {
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 6px;
  text-align: center;
  font-weight: bold;
  font-size: 14px;
}

.status.ok   { background: #d1fae5; color: #065f46; }
.status.wait { background: #fef9c3; color: #92400e; }
.status.err  { background: #fee2e2; color: #991b1b; }

/* MIDDLE PANE */
#middle-pane {
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
}

#rendered {
  background: white;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid #ddd;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  font-size: 15px;
  line-height: 1.4;
}

#rendered table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Courier New", monospace;
  font-size: 14px;

  /* MOBILE FIX: allow horizontal scroll */
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}

#rendered th, #rendered td {
  border: 1px solid #ccc;
  padding: 6px 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 400px;
}

.row-selected {
  background: #dbeafe !important;
}

/* DIFF PANEL */
#diff-panel {
  margin-top: 20px;
  display: none;
}

#diff-panel table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Courier New", monospace;
}

#diff-panel th, #diff-panel td {
  border: 1px solid #ddd;
  padding: 6px 10px;
  white-space: pre-wrap;
}

.diff-changed {
  background: #ecfdf5;
}

#change-reason {
  margin-top: 12px;
  padding: 10px;
  background: #eef2ff;
  border-radius: 6px;
  border: 1px solid #c7d2fe;
  font-size: 14px;
  display: none;
  white-space: pre-wrap;
}

/* RIGHT PANE */
#right-pane {
  background: #ffffff;
  border-left: 1px solid #ddd;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* ACCORDIONS */
.accordion {
  border: 1px solid #ccc;
  margin-bottom: 10px;
  border-radius: 6px;
  overflow: hidden;
}

.accordion-header {
  background: #e5e7eb;
  padding: 10px;
  font-weight: bold;
  cursor: pointer;
}

.accordion-body {
  padding: 10px;
  display: block;
  overflow-x: hidden;
}

.accordion-body.collapsed {
  display: none;
}

/* SUMMARY TABLES */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.summary-table th,
.summary-table td {
  border: 1px solid #ccc;
  padding: 6px;
  word-wrap: break-word;
  white-space: normal;
}

/* FOOTER */
#footer {
  text-align: center;
  font-size: 12px;
  color: #555;
  padding: 8px 0;
  background: #f3f4f6;
  border-top: 1px solid #ddd;
}

/* ----------------------------------------------------------
   MOBILE BREAKPOINT (GRID-AWARE, HIGH-SPECIFICITY)
---------------------------------------------------------- */
@media (max-width: 900px) {

  /* Break the grid completely */
  #container {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Stack panes vertically */
  #left-pane,
  #middle-pane,
  #right-pane {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    border: none !important;
    border-bottom: 1px solid #ddd !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
  }

  /* Middle pane first */
  #middle-pane { order: 0 !important; }
  #left-pane   { order: 1 !important; }
  #right-pane  { order: 2 !important; }

  /* FORCE collapse of right-pane accordion bodies */
  #right-pane .accordion-body {
    display: none !important;
  }

  /* Keep accordion headers visible */
  #right-pane .accordion-header {
    display: block !important;
  }

  /* Table scrolls horizontally */
  #rendered {
    overflow-x: auto !important;
  }

  #rendered table {
    display: block !important;
    width: max-content !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
  }

  /* FORCE footer to appear */
  #footer {
    position: relative !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 9999 !important;
    display: block !important;
  }
}

}
