/* ===================================================================
   HydroComplete Pro — Professional Stylesheet
   =================================================================== */

/* General Layout */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f4f4;
  min-height: 100vh;
}

/* ===================================================================
   Utility Classes — Replace common inline styles
   =================================================================== */

/* Workspace action buttons */
.hc-btn {
  padding: 8px 16px;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: opacity 0.2s, transform 0.1s;
}
.hc-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.hc-btn:active { transform: translateY(0); }
.hc-btn-green { background: #5a9a6e; }
.hc-btn-blue { background: #3498db; }
.hc-btn-teal { background: #17a2b8; }
.hc-btn-purple { background: #6f42c1; }
.hc-btn-red { background: #a85462; }
.hc-btn-dark { background: linear-gradient(135deg, #2c3e50, #34495e); }
.hc-btn-coral { background: #c97070; }

/* Section panels */
.hc-section {
  background: #f8f9fa;
  padding: 12px 16px;
  border-radius: 6px;
  margin: 10px 0;
}
.hc-section-blue { border-left: 4px solid #3498db; }
.hc-section-teal { border-left: 4px solid #17a2b8; }
.hc-section-red { border-left: 4px solid #e74c3c; }

/* Collapsible panels using <details> */
.hc-panel {
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin: 12px 0;
  border: 1px solid #e1e8ed;
  overflow: hidden;
}
.hc-panel > summary {
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  color: #2c3e50;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  background: #f8f9fa;
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}
.hc-panel > summary:hover { background: #eef1f5; }
.hc-panel[open] > summary { border-bottom-color: #e1e8ed; }
.hc-panel > summary::-webkit-details-marker { display: none; }
.hc-panel > summary::before {
  content: '\25B6';
  font-size: 0.65rem;
  transition: transform 0.2s;
  color: #7f8c8d;
}
.hc-panel[open] > summary::before { transform: rotate(90deg); }
.hc-panel-body { padding: 16px 18px; }

/* Action toolbar */
.hc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 12px;
  border: 1px solid #e1e8ed;
}
.hc-toolbar .hc-ctrl-btn {
  padding: 8px 14px;
  font-size: 12px;
  min-width: auto;
  border-radius: 6px;
}
.hc-toolbar .hc-toolbar-sep {
  width: 1px;
  height: 24px;
  background: #dee2e6;
  margin: 0 4px;
}

/* Help trigger */
.hc-help-btn {
  background: none;
  border: 1px solid #dee2e6;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  color: #6c757d;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  transition: all 0.15s;
}
.hc-help-btn:hover { background: #f8f9fa; color: #2c3e50; border-color: #adb5bd; }

/* Methods grid inside settings panel */
.hc-methods-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.hc-methods-grid label {
  font-weight: 600;
  color: #2c3e50;
  font-size: 0.85rem;
  margin-bottom: 3px;
  display: block;
}
.hc-methods-grid select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
}

/* Tools grid inside panel */
.hc-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}
.hc-tools-grid .hc-ctrl-btn {
  width: 100%;
  text-align: center;
  padding: 10px 12px;
  font-size: 12px;
  min-width: auto;
}

.hc-section-title {
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
}
.hc-section-title.blue { color: #3498db; }
.hc-section-title.teal { color: #17a2b8; }
.hc-section-title.red { color: #e74c3c; }

/* Form inputs */
.hc-input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}
.hc-input:focus {
  border-color: #3498db;
  outline: none;
  box-shadow: 0 0 0 2px rgba(52,152,219,0.15);
}

.hc-label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: #2c3e50;
  font-size: 13px;
}

/* Grid layouts */
.hc-grid { display: grid; gap: 10px; }
.hc-grid-2 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* Flex utilities */
.hc-flex { display: flex; align-items: center; gap: 15px; }
.hc-flex-wrap { flex-wrap: wrap; }
.hc-flex-between { justify-content: space-between; }

/* Text utilities */
.hc-muted { color: #6c757d; font-size: 0.9rem; }
.hc-small { font-size: 0.85rem; }

/* Control bar gradient buttons */
.hc-ctrl-btn {
  padding: 12px 20px;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
  min-width: 100px;
  font-size: 13px;
}
.hc-ctrl-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.hc-ctrl-btn:active { transform: translateY(0); }
.hc-ctrl-btn:disabled { background: #6c757d !important; cursor: not-allowed; opacity: 0.7; }
/* --- Toolbar: action group (slate blue) --- */
.hc-ctrl-btn.primary { background: linear-gradient(135deg, #4a6fa5, #3d5a8c); font-weight: 700; font-size: 1rem; min-width: 140px; box-shadow: 0 2px 8px rgba(74,111,165,0.3); }
.hc-ctrl-btn.validate { background: linear-gradient(135deg, #5a7fb5, #4a6fa5); }
/* --- Toolbar: file group (neutral) --- */
.hc-ctrl-btn.save { background: linear-gradient(135deg, #6b7b8d, #5a6a7c); }
.hc-ctrl-btn.load { background: linear-gradient(135deg, #6b7b8d, #5a6a7c); }
.hc-ctrl-btn.clear { background: linear-gradient(135deg, #8b7b7b, #7a6a6a); }
/* --- Toolbar: utility (light gray) --- */
.hc-ctrl-btn.settings { background: linear-gradient(135deg, #78869b, #697a8d); }
.hc-ctrl-btn.sample { background: linear-gradient(135deg, #78869b, #697a8d); }
/* --- Results & Reports (cool blue-gray) --- */
.hc-ctrl-btn.report { background: linear-gradient(135deg, #4a6fa5, #3d5a8c); }
/* --- Sediment & Erosion (earth tones) --- */
.hc-ctrl-btn.sediment { background: linear-gradient(135deg, #8b7355, #7a6345); }
.hc-ctrl-btn.erosion { background: linear-gradient(135deg, #8b7355, #7a6345); }
.hc-ctrl-btn.train { background: linear-gradient(135deg, #9b8365, #8b7355); color: #fff; }
.hc-ctrl-btn.sequence { background: linear-gradient(135deg, #9b8365, #8b7355); }
.hc-ctrl-btn.sed-report { background: linear-gradient(135deg, #8b7355, #7a6345); }
/* --- Design & sizing (muted teal) --- */
.hc-ctrl-btn.design { background: linear-gradient(135deg, #5a8a8a, #4a7a7a); }
.hc-ctrl-btn.stage { background: linear-gradient(135deg, #5a8a8a, #4a7a7a); }
.hc-ctrl-btn.pond { background: linear-gradient(135deg, #5a8a8a, #4a7a7a); }
/* --- Reference & workspace (muted slate) --- */
.hc-ctrl-btn.equations { background: linear-gradient(135deg, #6b7b8d, #5a6a7c); }
.hc-ctrl-btn.workspace { background: linear-gradient(135deg, #6b7b8d, #5a6a7c); }

/* Palette background — visual feedback for which category tab is active.
   The single palette div swaps these classes to match the selected tab. */
.palette.palette-bg-bmp      { background-color: #f0f4f8 !important; border-color: #8aa4c0 !important; }
.palette.palette-bg-sediment { background-color: #faf6e8 !important; border-color: #b0a070 !important; }
.palette.palette-bg-conduit  { background-color: #eceff1 !important; border-color: #607d8b !important; }

/* Workspace button group — segmented control with subdued styling.
   Buttons share borders so they read as a single grouped control. */
.hc-workspace-group {
  display: inline-flex;
  border: 1px solid #b0bec5;
  border-radius: 6px;
  overflow: hidden;
  background: #f5f7fa;
}
.hc-workspace-btn {
  padding: 6px 14px;
  background: transparent;
  color: #455a64;
  border: none;
  border-right: 1px solid #cfd8dc;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.hc-workspace-btn:last-child { border-right: none; }
.hc-workspace-btn:hover { background: #eceff1; color: #263238; }
.hc-workspace-btn:active { background: #cfd8dc; }
.hc-workspace-btn-danger:hover { background: #fbe9e9; color: #a85462; }

/* Tool group visual separator */
.hc-tool-group {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e9ecef;
}
.hc-tool-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.hc-tool-group-label {
  font-size: 11px;
  font-weight: 700;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  padding-left: 2px;
}

/* Rainfall status badge in toolbar */
.hc-rainfall-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  background: #fff3cd;
  color: #8d6e00;
  border: 1px solid #e0c96b;
  white-space: nowrap;
}
.hc-rainfall-badge.hc-rainfall-set {
  background: #e8f5e9;
  color: #3a6b4a;
  border-color: #a5d6a7;
}

/* Spectacular section */
.hc-spectacular {
  margin: 20px 0;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 15px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.hc-spectacular h3 {
  color: white;
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.5rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

header nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 20px;
  background-color: #333;
  padding: 10px;
  border-radius: 4px;
}

header nav ul li a {
  color: white;
  text-decoration: none;
  font-weight: bold;
}

header nav ul li a:hover {
  text-decoration: underline;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
}

h1 {
  text-align: center;
  color: #333;
}

/* Diagram Section */
.diagram-section {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.palette {
  width: 200px;
  height: 600px;
  border: 1px solid #ccc;
  background-color: white;
}

.diagram {
  flex: 1;
  height: 600px;
  border: 1px solid #ccc;
  background-color: white;
}

/* Controls Section */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.controls button {
  padding: 10px 15px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.controls button:hover {
  background-color: #0056b3;
}

.controls button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

/* Chart Section */
.chart-section {
  margin-bottom: 20px;
}

.chart-container {
  position: relative;
  height: 400px;
  background-color: white;
  border: 1px solid #ccc;
  padding: 10px;
  border-radius: 4px;
}

.chart-container.water-quality-mode {
  background-color: #f0f8ff;
}

/* Info Section */
.info-section {
  position: relative;
}

#infoDraggable {
  width: 300px;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#infoDraggableHandle {
  background-color: #007bff;
  color: white;
  padding: 8px;
  font-weight: bold;
  cursor: move;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

#myInfo {
  padding: 10px;
  min-height: 100px;
}

#myInfo label {
  display: block;
  margin: 5px 0;
  font-size: 14px;
}

#myInfo input,
#myInfo select {
  width: calc(100% - 10px);
  padding: 5px;
  margin-top: 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

#myInfo input.error {
  border: 1px solid red;
}

#myInfo h4 {
  margin: 10px 0 5px;
  font-size: 16px;
}

#myInfo button {
  margin: 5px 0;
  padding: 5px 10px;
  background-color: #5a9a6e;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#myInfo button:hover {
  background-color: #4a8a5e;
}

/* Message Styling */
.success-message,
.error-message {
  padding: 10px;
  margin: 5px;
  border-radius: 4px;
  font-size: 14px;
}

.success-message {
  background: #d4edda;
  color: #155724;
}

.error-message {
  background: #f8d7da;
  color: #721c24;
}

.dismiss-button {
  float: right;
  cursor: pointer;
  font-weight: bold;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
  background-color: white;
  margin: 10% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  max-width: 600px;
  border-radius: 4px;
  position: relative;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
}

.modal-content h2,
.modal-content h3 {
  margin: 10px 0;
}

.modal-content input,
.modal-content select {
  width: calc(100% - 10px);
  padding: 5px;
  margin: 5px 0;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.modal-content input.error {
  border: 1px solid red;
}

.modal-content button {
  padding: 8px 15px;
  margin: 5px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.modal-content button:hover {
  background-color: #0056b3;
}

.outlet-row,
.elev-area-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 5px 0;
}

.outlet-row input,
.elev-area-row input,
.outlet-row select {
  flex: 1;
}

.outlet-row button,
.elev-area-row button {
  padding: 5px 10px;
  background-color: #dc3545;
}

.outlet-row button:hover,
.elev-area-row button:hover {
  background-color: #c82333;
}

#inspector {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 1000;
  background: white;
  border: 1px solid #ccc;
  padding: 10px;
  cursor: move;
  width: 200px;
}

/* ===================================================================
   Formula Panel - Calculation transparency with KaTeX
   =================================================================== */

.hc-formula-panel {
  background: #fff;
  border: 1px solid #d1dbe6;
  border-radius: 8px;
  margin: 16px 0;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.hc-formula-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #f8f9fa, #eef1f5);
  border-bottom: 1px solid #d1dbe6;
  cursor: pointer;
  user-select: none;
}

.hc-formula-panel-icon {
  font-size: 10px;
  transition: transform 0.2s;
  color: #3498db;
}

.hc-formula-panel.hc-collapsed .hc-formula-panel-icon {
  transform: rotate(0deg);
}

.hc-formula-panel:not(.hc-collapsed) .hc-formula-panel-icon {
  transform: rotate(90deg);
}

.hc-formula-panel-title {
  font-weight: 700;
  font-size: 14px;
  color: #2c3e50;
  flex: 1;
}

.hc-formula-panel-badge {
  background: #3498db;
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.hc-formula-panel-toggle {
  font-size: 11px;
  color: #7f8c8d;
}

.hc-formula-panel.hc-collapsed .hc-formula-panel-body {
  display: none;
}

.hc-formula-panel-body {
  padding: 8px 16px 16px;
}

.hc-formula-step {
  margin: 16px 0;
  padding: 16px;
  background: #fafbfc;
  border: 1px solid #e8ecf0;
  border-left: 4px solid #3498db;
  border-radius: 4px;
}

.hc-formula-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.hc-formula-title {
  font-weight: 700;
  font-size: 13px;
  color: #2c3e50;
}

.hc-formula-ref {
  font-size: 11px;
  color: #95a5a6;
  font-style: italic;
}

.hc-formula-equation {
  text-align: center;
  margin: 12px 0;
  padding: 8px;
  background: #fff;
  border-radius: 4px;
}

.hc-formula-sub {
  text-align: center;
  margin: 8px 0;
  padding: 6px 8px;
  color: #555;
  font-size: 13px;
}

.hc-formula-sub-label {
  display: block;
  font-size: 11px;
  color: #95a5a6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.hc-formula-result {
  text-align: center;
  margin: 12px 0 4px;
  padding: 10px;
  background: linear-gradient(135deg, #eaf6ff, #f0f7ff);
  border: 1px solid #bee5ff;
  border-radius: 4px;
  font-weight: 600;
}

.hc-formula-vars {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e8ecf0;
  font-size: 12px;
  color: #555;
}

.hc-formula-vars-title {
  font-weight: 600;
  color: #7f8c8d;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.hc-formula-vars ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.hc-formula-vars li {
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
}

.hc-formula-vars li:last-child {
  border-bottom: none;
}

.hc-formula-unit {
  color: #95a5a6;
  font-size: 11px;
}

/* Formula Modal */
.hc-formula-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hc-formula-modal {
  background: #fff;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hc-formula-modal-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, #2c3e50, #34495e);
  color: white;
  position: relative;
}

.hc-formula-modal-header h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.hc-formula-modal-subtitle {
  font-size: 13px;
  opacity: 0.8;
}

.hc-formula-modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  opacity: 0.7;
  line-height: 1;
}

.hc-formula-modal-close:hover {
  opacity: 1;
}

.hc-formula-modal-body {
  overflow-y: auto;
  padding: 16px 24px;
  flex: 1;
}

.hc-formula-modal-footer {
  padding: 12px 24px;
  border-top: 1px solid #e1e8ed;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.hc-formula-modal-footer button {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.hc-formula-modal-footer button:first-child {
  background: #3498db;
  color: white;
}

.hc-formula-modal-footer button:last-child {
  background: #e1e8ed;
  color: #2c3e50;
}

.hc-tex-fallback {
  font-family: 'Courier New', monospace;
  background: #f5f5f5;
  padding: 2px 4px;
  border-radius: 2px;
}

/* Print-friendly formula styles */
@media print {
  .hc-formula-panel-header,
  .hc-formula-panel-toggle,
  .hc-formula-modal-overlay,
  .hc-formula-modal-footer { display: none; }
  .hc-formula-step { border: 1px solid #ccc; page-break-inside: avoid; }
}