:root {
    --bg-color: #f4f4f9;
    --text-color: #333;
    --border-color: #ccc;
    --accent-color: #5c4033;
    --grid-cols: 8;
    --grid-rows: 6;
    --cell-ratio: 1; 
  --gridline-thickness: 1px;
  --gridline-color: #00000059;
}

body {
    font-family: "Montserrat", sans-serif !important;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 20px;
    margin: 0;
}

h1 {
  margin: 0; 
  font-size: 1.5rem; 
}

.app-tagline {
  margin: 0;
  font-size: 0.8rem;
  color: #888;
  letter-spacing: 0.3px;
}

.header-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-bottom: 30px;
  background: #fff;
  padding: 20px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  width: 100%;
  max-width: 85%;
  border-radius: 0 0 20px 20px;
}

.config-bar {
  display: flex;
  gap: 15px;
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 12px;

  border-radius: 10px;
  background: #f8f4f4;
}

.config-section{
  display:flex;
  gap:15px;
  align-items:flex-end;
  flex-wrap:wrap;
  justify-content:center;
}

.config-bar input[type="number"],
.config-bar select {
  width: 90px;
  height: 32px;
}

.config-bar button {
  height: 32px;
  width: auto;
  display: inline-flex;
  align-items: center;
}

.btn.btn-active{
  background: var(--accent-color);
  color: #fff;
  border-color: #3a4a2a;
}

.btn.btn-active:hover{
  background: #4a332a;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.settings-row.hidden-control {
  display: none;
}

.btn-zone-remove {
  height: 100%;
  margin-left: 10px;
  font-size: 0.7rem !important;
  line-height: 1;
  min-width: 24px;
  color: #c62828;
  border-color: #ffcdd2;
  background: #ffebee;
  flex-shrink: 0;
}

.btn-zone-remove:hover {
  background: #ffdfe3;
}

#toggle-gridlines-btn {
  width: 105px;
}

.config-bar input[type="checkbox"]{
  width: 18px;
  height: 18px;
  margin-top: 6px;
}

.config-group { 
  display: flex; 
  flex-direction: 
  column; gap: 5px; 
}

.config-group label{
  font-size: 0.75rem;
  font-weight: 500;
  color: #777;
  letter-spacing: 0.8px;
}
.divider { 
  width: 1px; 
  background: #ddd; 
  height: 30px; 
  margin: 0 10px; 
}

.divider-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.divider-actions {
  display: flex;
  width: 100%;
}

.btn-center {
  width: 100%;
}

/* BUTTONS */
.btn {
  padding: 8px 16px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.btn:hover { 
  background: #eee; 
}

.btn-primary { 
  background-color: #5c4033; 
  color: white; 
  border-color: #4a332a; 
}

.btn-primary:hover { 
  background-color: #4a332a; 
}

.config-bar .btn-danger{
  background: #ffebee;
  border-color: #ffcdd2;
  color: #c62828;
}

.config-bar .btn-danger:hover{
  background: #ffdfe3;
}

.btn-sm { 
  padding: 4px 10px; 
  font-size: 0.8rem; 
}

/* BUTTON ROWS */
.btn-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 10px;
}

.btn-row .btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.btn-icon-delete {
  font-size: 0.8rem;
}

.btn-row-split {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.btn-row-split .btn-group {
  display: flex;
  gap: 8px;
  flex: 1;
}

.btn-row-split .btn-group .btn {
  flex: 1;
}

.btn-divider-vert {
  width: 1px;
  background: #ddd;
  align-self: stretch;
  margin: 0 2px;
}

/* WORKSPACE */
.workspace {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 40px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 1400px;
}

.grid-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.grid-label { font-weight: bold; color: #555; }

/* INPUT GRID */
.input-grid-wrapper {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 350px;
  min-height: 500px;
  flex-shrink: 0;
}

.input-container {
  display: grid;
  grid-template-columns: 30px repeat(var(--grid-cols), 1fr);
  grid-template-rows: 30px repeat(var(--grid-rows), 1fr);
  gap: 2px;
  max-width: 100%;
  width: 100%;
}

/* Headers */
.grid-header-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e0e0e0;
  font-weight: bold;
  font-size: 0.8rem;
  color: #555;
  border-radius: 2px;
  position: relative;
}

/* input cells */
.input-cell {
  width: 100%;
  aspect-ratio: var(--cell-ratio, 1);
  max-width: 100%; 
  min-width: 0;
  text-align: center;
  text-transform: uppercase;
  font-weight: bold;
  border: 1px solid #ccc;
  background: white;
  font-size: 1rem;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.input-cell:focus {
  border-color: #5c4033;
  outline: none;
  background-color: #fff8e1;
  z-index: 10;
}

/* ROW COPY DROPDOWN */
.row-header-content {
  display: flex;
  gap: 2px;
  align-items: center;
  width: 100%;
  justify-content: center;
  cursor: pointer;
}

.copy-select {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  opacity: 0;
  cursor: pointer;
}

.row-label-text { pointer-events: none; }
.copy-icon { 
  font-size: 0.6rem; 
  color: #888; 
  margin-left: 2px;
  pointer-events: none;
}
.grid-header-cell:hover .copy-icon { color: #333; }
.grid-header-cell:hover { background: #d0d0d0; }


/* VISUAL PREVIEW */
.visual-grid-wrapper {
  flex-grow: 1;
  max-width: 800px;
  min-width: 300px;
}

.preview-row {
  display: flex;
  gap: 20px;
  width: 100%;
  align-items: stretch; 
}

.preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.visual-container {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  grid-template-rows: repeat(var(--grid-rows), 1fr);
  background-color: var(--visual-gridline-color);
  border: 2px solid #333;
  aspect-ratio: 4 / 3;
  width: 100%;
  max-width: 600px;
}

.visual-cell {
  width: 100%;
  height: 100%;
  background-color: #fff;
}

.visual-container.show-gridlines::after{
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;

  /* draw vertical and horizontal lines */
  background-image:
    repeating-linear-gradient(
      to right,
      var(--gridline-color) 0,
      var(--gridline-color) var(--gridline-thickness),
      transparent var(--gridline-thickness),
      transparent calc(100% / var(--grid-cols))
    ),
    repeating-linear-gradient(
      to bottom,
      var(--gridline-color) 0,
      var(--gridline-color) var(--gridline-thickness),
      transparent var(--gridline-thickness),
      transparent calc(100% / var(--grid-rows))
    );
}

.visual-container.gridlines-invert::after {
  --gridline-color: white;
  mix-blend-mode: difference;
}

/* PRESET PANEL */
.preset-panel {
  width: 220px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  max-height: calc((600px * 3/4) + 30px);
  overflow: hidden;
}

.preset-tabs {
  display: flex;
  border-bottom: 2px solid #eee;
  flex-shrink: 0;
}


.preset-tab {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: #666;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.preset-tab.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

.preset-tab:hover {
  background: #f8f8f8;
}

.preset-tab-panel {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 15px;
  min-height: 0;
}

.preset-tab-panel.hidden {
  display: none;
}

.preset-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.preset-actions .btn {
  flex: 1;
  min-width: 0;
  font-size: 0.75rem;
  padding: 6px 8px;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* preset cards */
.preset-card {
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
  transition: box-shadow 0.2s;
  position: relative;
}

.preset-card:hover {
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.preset-card:hover::after {
  content: 'LOAD';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 1.2rem;
  letter-spacing: 2px;
}


/* CONTROLS SECTION */
.controls-section-header {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

.capacity-display {
  background: #eef;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: bold;
  color: #445;
  border: 1px solid #ccd;
  font-size: 0.9rem;
}
.pot-ok { background: #e8f5e9; color: #2e7d32; border-color: #c8e6c9; }
.pot-neg { background: #ffebee; color: #c62828; border-color: #ffcdd2; }

.controls-area {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1200px;
}

.block-control {
  border: 1px solid #ddd;
  padding: 15px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  border-bottom: 1px solid #eee;
  padding-bottom: 5px;
}

.block-name {
  font-size: 1.1rem;
  font-weight: bold;
  margin-left: 5px;
}

.block-preview {
  width: 60%;
  max-width: 150px;
  aspect-ratio: var(--cell-ratio, 1);
  border: 1px solid #333;
  margin: 0 auto;
  background: #eee;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  transition: aspect-ratio 0.3s ease;
}

.block-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.block-control .allocated-qty {
  margin-top: auto;
}

.allocated-qty {
  border-top: 1px dashed #eee;
  padding-top: 8px;
}

/* Zones */
.zones-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px dashed #eee;
  padding-top: 5px;
}

.zone-row {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #fafafa;
  padding: 4px;
  border-radius: 4px;
}

.zone-label { font-size: 0.75rem; font-weight: bold; width: 20px; text-align: center; color: #666; }
.wood-dropdown { flex-grow: 1; font-size: 0.8rem; padding: 4px; border: 1px solid #ccc; border-radius: 4px; }
input[type="color"] { width: 30px; height: 28px; border: none; cursor: pointer; padding: 0; background: none; }

/* Settings */
.settings-row {
  display: flex;
  gap: 15px;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  border-top: 1px dashed #eee;
  padding-top: 8px;
}

.setting-group { display: flex; flex-direction: column; width: 45%; }
.label-sm { font-size: 0.75rem; color: #666; font-weight: bold; margin-bottom: 4px;}
select, input[type="number"] { padding: 4px; border-radius: 4px; border: 1px solid #ccc; width: 100%; box-sizing: border-box; }

.settings-row.hidden-control {
  display: none;
}

.actions-row { 
  display: flex; 
  justify-content: space-between;
   margin-top: 5px; 
  }

.actions-row.hidden-control {
  display: none;
}
.status-over { 
  color: red; 
  font-weight: bold; 
}
.status-ok { 
  color: green; 
  font-weight: bold; 
}

/*  RADIAL CONTROL */
.radial-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.radial-dial {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #5c4033;
  background: #fff;
  position: relative;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.radial-dial:hover { background: #fdfdfd; transform: scale(1.05); }

.dial-pointer {
  position: absolute;
  top: 50%; left: 50%;
  width: 100%; height: 2px;
  background: transparent;
  transform: translate(-50%, -50%);
}
.dial-pointer::after {
  content: '';
  position: absolute;
  right: 4px; top: -3px; /* Center vertical */
  width: 8px; height: 8px;
  border-top: 2px solid #5c4033;
  border-right: 2px solid #5c4033;
  transform: rotate(45deg);
}
.dial-pointer::before {
    content: '';
    position: absolute;
    left: 4px; right: 4px; top: 0; height: 2px;
    background: #5c4033;
}

.control-disabled { opacity: 0.3; pointer-events: none; filter: grayscale(100%); }
.hidden-control { visibility: hidden; }

input[type="range"] {
    width: 100%;
}

.settings-row .btn { white-space: nowrap; }

/* BLOCK PALETTE */
.block-palette {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  gap: 4px;
  width: 100%;
}
.palette-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.palette-letter {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e0e0e0;
  font-weight: bold;
  font-size: 0.8rem;
  color: #555;
  border-radius: 2px;
}

.palette-swatch {
  width: 100%;
  aspect-ratio: var(--cell-ratio, 1);
  border: 1px solid #333;
  border-radius: 2px;
  background: #fff;
}

/* MOBILE RESPONSIVE STYLES */
@media (max-width: 768px) {
  body {
    padding-top: 10px;
    overflow-x: hidden;
  }

  .header-section {
    padding: 10px;
    margin-bottom: 15px;
  }

  .config-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px;
  }

  .config-bar .divider {
    display: none;
  }

  .config-section:nth-child(1) {
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .config-section:nth-child(1) .config-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    flex: 0 0 auto;
  }

  .config-section:nth-child(1) .config-group label {
    margin: 0;
    white-space: nowrap;
    font-size: 0.7rem;
  }

  .config-section:nth-child(1) input[type="number"] {
    width: 50px;
    height: 32px;
  }

  .config-section:nth-child(1) .btn {
    white-space: nowrap;
    height: 32px;
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  .config-section:nth-child(3) {
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .config-section:nth-child(3) #toggle-gridlines-btn {
    width: auto;
    height: 32px;
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .config-section:nth-child(3) .config-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    flex: 0 0 auto;
  }

  .config-section:nth-child(3) .config-group label {
    margin: 0;
    white-space: nowrap;
    font-size: 0.7rem;
  }

  .config-section:nth-child(3) select {
    width: 65px;
    height: 32px;
    font-size: 0.8rem;
  }

  .config-bar > .btn-danger {
    align-self: center;
    width: auto;
    height: 32px;
    padding: 8px 16px;
  }

  .controls-area {
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 0 10px;
  }

  .block-control {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .btn-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .btn-row .btn {
    font-size: 0.75rem;
    padding: 6px 8px;
    min-width: 0;
  }

  .btn-row-split {
    flex-direction: column;
    gap: 6px;
  }

  .btn-row-split .btn-group {
    width: 100%;
  }

  .btn-row-split .btn-group .btn {
    font-size: 0.75rem;
    padding: 6px 8px;
  }

  .btn-divider-vert {
    display: none;
  }

  .settings-row {
    flex-direction: column;
    gap: 10px;
  }

  .setting-group {
    width: 100%;
  }

  .radial-wrapper {
    width: 100%;
  }

  .hidden-control {
    display: none !important;
  }

  .settings-row:has(.hidden-control:only-child) {
    display: none;
  }

  .settings-row {
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
  }

  .settings-row:empty {
    display: none;
  }

  .divider-section {
    gap: 6px;
  }

  .block-content {
    gap: 8px;
  }

  .zones-container {
    padding-top: 8px;
  }

  .allocated-qty {
    padding-top: 8px;
    margin-top: 8px;
  }
  
  .input-grid-wrapper {
    width: 100%;
    max-width: 100%;
    min-height: auto;
    align-items: center;
    gap: 10px;
  }

  .workspace {
    gap: 15px;
    padding: 0 10px;
    align-items: center;
  }

  .visual-grid-wrapper {
    width: 100%;
    max-width: 100%;
    gap: 10px;
  }

  .grid-label {
    margin-bottom: 5px;
  }

  .preview-row {
    flex-direction: column;
    gap: 15px;
    width: 100%;
  }

  .preview-container {
    width: 100%;
  }

  .visual-container {
    max-width: 100%;
    width: 100%;
  }

  .preset-panel {
    width: 100%;
    max-width: 100%;
    max-height: none;
    height: auto;
  }

  .preset-tab-panel {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px;
  }

  .preset-list {
    flex-direction: row;
    gap: 10px;
    width: max-content;
  }

  .preset-card {
    width: 150px;
    flex-shrink: 0;
  }

  .preset-actions {
    flex-direction: column;
    gap: 6px;
  }

  .preset-actions .btn {
    width: 100%;
    font-size: 0.75rem;
    padding: 6px 8px;
  }
}

/* FOOTER */
.footer {
  width: 100%;
  max-width: 85%;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  padding: 20px;
  margin-top: 40px;
  box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
  border-radius: 20px 20px 0 0;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.footer-text {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}

.github-link {
  display: flex;
  align-items: center;
  gap: 15px;
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s;
}

.github-link:hover {
  color: #333;
}

.github-link strong {
  font-weight: 600;
}

.github-icon {
  display: inline-block;
  vertical-align: middle;
}

.footer-links {
  display: flex;
  gap: 15px;
  align-items: center;
}

.coffee-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  background: #FFDD00;
  color: #000;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.coffee-link:hover {
  background: #FFED4E;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-help {
  background: #fff;
  display: inline-flex;
  justify-content: center;
}

/* HELP MODAL */
.help-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.help-modal {
  background: #fff;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.help-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 15px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.help-modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.help-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #999;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.help-modal-close:hover {
  background: #f0f0f0;
  color: #333;
}

.help-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
}

.help-modal-body section {
  margin-bottom: 20px;
}

.help-modal-body section:last-child {
  margin-bottom: 0;
}

.help-modal-body h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.help-modal-body p {
  margin: 0 0 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #444;
}
