/* General styles */
body {
  font-family: "Kanit", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  font-size: 17px;
  background-color: #f2f4f8;
  color: #333;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto;
  padding: 2rem 3rem;
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border-radius: 10px;
}

.main {
  min-width: 0;
}

h1 {
  margin-top: 0;
  margin-bottom: 1rem;
  text-align: center;
  color: #00695c;
}

h2 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: #00695c;
}

p {
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

/* Input group */
.inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: end;
}

.input-group {
  flex: 1 1 250px;
  display: flex;
  flex-direction: column;
}

.input-group label {
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.input-group input {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

/* Mode Toggles Layout */
.mode-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.calculation-mode-selection, .method-selection {
  margin: 0;
  font-weight: 500;
}

.calculation-mode-selection label, .method-selection label {
  margin-left: 0.5rem;
  margin-right: 1rem;
  cursor: pointer;
}

button.secondary-toggle {
  margin: 0 0 0 auto; /* Push button to the right */
  background-color: #f0f7f5;
  color: #00796b;
  border: 1px solid #b2dfdb;
  padding: 0.5rem 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 6px;
  font-size: 0.95rem;
}

button.secondary-toggle:hover {
  background-color: #e0f2f1;
  border-color: #00796b;
}

/* Table styles */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

th, td {
  border: 1px solid #ddd;
  padding: 0.5rem;
  text-align: left;
  vertical-align: middle;
}

th {
  background-color: #f0f7f5;
  font-weight: 600;
}

td input, td select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.4rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95rem;
}

/* --- Styles for Management Column --- */
td.action-cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.cost-type-selector {
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.cost-type-selector label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}
.cost-type-selector input[type="radio"] {
    width: auto; /* Override default width for radio buttons */
    margin: 0;
}
/* By default, hide the radio buttons in basic mode */
body.basic-mode .cost-type-selector {
    display: none;
}
/* Show them in advanced mode */
body.advanced-mode .cost-type-selector {
    display: flex;
}

/* Controls & Buttons */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
}

button {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  font-family: 'Kanit', sans-serif;
}

button.primary { background-color: #009688; color: #fff; }
button.primary:hover { background-color: #00796b; }
button.secondary { background-color: #e0e0e0; color: #333; }
button.secondary:hover { background-color: #d5d5d5; }

.delete-btn {
  background-color: #e53935;
  color: #fff;
  padding: 0.4rem 0.8rem;
  margin-left: auto; /* Push to the right within the flex container */
  flex-shrink: 0; /* Prevent it from shrinking */
}
.delete-btn:hover { background-color: #c62828; }

/* Summary & Chart */
.main-summary { margin-top: 1.5rem; }
#summary { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
#summary .card { background-color: #f0f7f5; padding: 0.8rem 1.2rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); text-align: center; flex: 0 1 200px; min-width: 180px; }
#summary .card h3 { margin: 0 0 0.3rem 0; font-size: 1rem; color: #004d40; font-weight: 600; }
#summary .card p { margin: 0; font-size: 1.15rem; font-weight: 700; color: #00695c; }
#summary .card small { display: block; font-size: 0.8rem; color: #555; margin-top: 0.2rem; line-height: 1.2; }
.chart-container { width: 100%; margin: 1.5rem 0; height: 420px; }
canvas { width: 100% !important; height: auto !important; }

/* DYNAMIC COLUMN VISIBILITY (Simplified for method selection) */
.detailed-col { display: none; }
.simple-col { display: table-cell; }

/* Modal styles (for per-rai/total selection) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.modal.hidden { display: none; }
.modal-content { background: #fff; padding: 1.2rem 1.5rem; border-radius: 8px; max-width: 420px; width: 92%; box-shadow: 0 6px 20px rgba(0,0,0,0.15); text-align: center; }
.modal-content h3 { margin: 0 0 0.5rem 0; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: center; margin: 0.8rem 0; }
.modal .remember { display: block; font-size: 0.9rem; color: #666; margin-top: 0.6rem; }

/* Responsive Adjustments */
@media (max-width: 992px) {
  .mode-toggles {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  button.secondary-toggle {
    margin-left: 0;
    width: 100%;
    text-align: center;
  }
}

@media (max-width: 768px) {
  .container { padding: 1.5rem 1rem; }
}

/* Print styles */
@media print {
  body { background-color: #fff; font-size: 11pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .container { box-shadow: none; border: none; padding: 0; margin: 0; width: 100%; max-width: 100%; }
  
  /* Hide non-essential elements */
  .header-container, .mode-toggles, .controls, #toggleModeBtn, #addRowBtn, #resetBtn, #calculateBtn, #downloadPdfBtn, #printBtn, #managementHeader, .action-cell, #modeModal, h1 + p {
    display: none !important;
  }
  
  h1, h2 { text-align: left; margin-top: 1rem; padding-bottom: 0.5rem; border-bottom: 2px solid #ccc; }
  #reportArea, #results { display: block !important; }
  table, th, td { border: 1px solid #666; }
  th { background-color: #f0f0f0 !important; }
  tr { page-break-inside: avoid; }
  .cost-type-selector { display: none !important; } /* Hide radio buttons on print */
  #summary { justify-content: flex-start; }
  #summary .card { border: 1px solid #ccc; box-shadow: none; flex-basis: 220px; }
  
  /* Page break control */
  .main {
    page-break-after: always;
  }
  #results {
    page-break-inside: avoid;
  }
  .chart-container { 
    height: 500px !important; /* Further increased height for print */
    width: 100% !important; 
    max-width: 700px; 
    margin: 1rem auto 0 auto; /* Reduced top margin */
    /* The 'page-break-before: always' was removed from here */
  }
}