/* ThreadCalc.com - Precision Thread Calculator
   Visual style based on ThreadPal's green-toned panel layout */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 13px;
  background: #2d3a2d;
  color: #1a1a1a;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 6px;
}

/* Header */
.header-bar {
  background: linear-gradient(135deg, #3a5a3a, #4a6a4a);
  color: #e8f0e8;
  padding: 8px 16px;
  border-radius: 4px 4px 0 0;
  border-bottom: 2px solid #2a4a2a;
}
.header-bar h1 {
  font-size: 18px;
  font-weight: 600;
  font-family: 'Trebuchet MS', sans-serif;
}
.header-bar .subtitle {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.8;
  margin-left: 8px;
}

/* Main Layout */
.main-layout {
  background: #c4d4c4;
  padding: 6px;
  border-radius: 0 0 4px 4px;
}

/* Panels */
.panel {
  background: #d8e4d8;
  border: 1px solid #9aaa9a;
  border-radius: 3px;
  margin-bottom: 6px;
}

.panel-header {
  background: linear-gradient(180deg, #6a8a6a, #5a7a5a);
  color: #fff;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 28px;
  position: relative;
}

.panel-title {
  text-decoration: underline;
  flex-shrink: 0;
}

.panel-subtitle {
  text-align: center;
  font-weight: 600;
  padding: 2px 8px;
  font-size: 12px;
  background: #e0eae0;
  border-bottom: 1px solid #b0c0b0;
}

.panel-body {
  padding: 6px 8px;
}

/* Inline header fields (legacy) */
.field-group {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}
.field-group label {
  white-space: nowrap;
  font-weight: 400;
}
.inline-left { margin-right: auto; }
.inline-right { margin-left: auto; }

/* Header fields (External/Internal Dimensions) */
.header-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.header-field {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-field label {
  white-space: nowrap;
  font-weight: 400;
}

/* Dimension Grid */
.dim-grid {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  flex-wrap: wrap;
}
.dim-section {
  flex: 1;
  min-width: 140px;
}
.dim-title {
  text-align: center;
  font-weight: 600;
  font-size: 11px;
  text-decoration: underline;
  margin-bottom: 3px;
}
.dim-labels {
  display: flex;
  gap: 2px;
  justify-content: center;
}
.dim-labels span {
  width: 60px;
  text-align: center;
  font-size: 10px;
  color: #555;
}
.dim-values {
  display: flex;
  gap: 2px;
  justify-content: center;
}

/* Input Fields */
.input-field, .result-field {
  border: 1px solid #999;
  border-radius: 2px;
  padding: 2px 4px;
  font-size: 12px;
  font-family: 'Consolas', 'Courier New', monospace;
  text-align: center;
  width: 68px;
  height: 22px;
}
.result-field {
  background: #f0f4f0;
  color: #333;
}
.result-field:read-only {
  cursor: default;
}
.active-input {
  background: #ffe8e0 !important;
  border-color: #c88;
}
.result-field.sm, .input-field.sm {
  width: 56px;
}

/* Warning style for MOW < Major */
.result-field.warn {
  color: #cc0000;
  font-weight: bold;
}

/* Thread Type Select */
.thread-type-row {
  margin-bottom: 6px;
}
.thread-type-row select {
  width: 100%;
  padding: 3px;
  font-size: 12px;
}
.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.field-pair {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.field-pair label {
  font-size: 11px;
  font-weight: 600;
}
.series-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.radio-group {
  display: flex;
  gap: 6px;
  font-size: 11px;
}
.radio-group label {
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

/* Sizes Button */
.btn-sizes {
  background: #e0e8e0;
  border: 1px solid #888;
  border-radius: 3px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
}
.btn-sizes:hover { background: #d0d8d0; }

/* Classes of Fit */
.fit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.fit-row label {
  width: 55px;
  font-size: 11px;
  text-align: right;
}
.fit-row select {
  width: 60px;
  font-size: 12px;
  padding: 2px;
}

/* MOW Panel */
.mow-row {
  margin-bottom: 4px;
}
.mow-section {
  border-top: 1px solid #b0c0b0;
  padding-top: 4px;
}
.mow-sub-header {
  display: flex;
  justify-content: space-around;
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 2px;
}
.mow-detail-row {
  margin-bottom: 3px;
}
.mow-reset-row {
  text-align: center;
  margin-top: 4px;
}

/* Middle Row Layout */
.middle-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.thread-select { flex: 2; min-width: 220px; }
.btn-help, .btn-help-sm {
  background: #e0e8e0;
  border: 1px solid #888;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 4px;
}
.btn-help-sm { width: 18px; height: 18px; font-size: 10px; }
.btn-help:hover, .btn-help-sm:hover { background: #d0d8d0; }
.classes-fit { flex: 1; min-width: 130px; }
.mow-panel { flex: 2; min-width: 250px; }

/* Bottom Row Layout */
.bottom-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.starts-panel { flex: 2; }
.pct-panel { flex: 1; }
.tap-drills-panel { flex: 2; }

.starts-grid, .pct-grid {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.starts-grid .field-pair,
.pct-grid .field-pair {
  flex: 1;
  min-width: 60px;
}

/* Tap Drills */
.tap-type-toggle {
  display: flex;
  gap: 8px;
  font-size: 10px;
  margin-left: auto;
}
.tap-type-toggle label { color: #fff; cursor: pointer; display: flex; align-items: center; gap: 2px; }
.tap-table-wrap {
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid #999;
  background: #fff;
}
.tap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.tap-table th {
  background: #e8f0e8;
  padding: 2px 4px;
  border-bottom: 1px solid #999;
  position: sticky;
  top: 0;
  font-size: 10px;
}
.tap-table td {
  padding: 1px 4px;
  border-bottom: 1px solid #ddd;
  text-align: center;
  font-family: 'Consolas', monospace;
  font-size: 11px;
}
.tap-table tr:hover { background: #f0f8f0; }
.tap-table tr.selected { background: #c8e0c8; }

/* Footer Row */
.footer-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.loe-panel { flex: 2; }
.display-opts { flex: 2; }
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.loe-grid {
  display: flex;
  gap: 8px;
}
.loe-toggle {
  display: flex;
  gap: 8px;
  margin: 4px 0;
  font-size: 11px;
}
.loe-range {
  font-size: 10px;
  color: #555;
}
.opts-row {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 11px;
}
.opts-row label {
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

/* Action Buttons */
.btn-action {
  padding: 6px 20px;
  border: 1px solid #666;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-width: 80px;
}
.btn-green {
  background: linear-gradient(180deg, #5a8a5a, #4a7a4a);
  color: #fff;
}
.btn-green:hover { background: linear-gradient(180deg, #4a7a4a, #3a6a3a); }
.btn-blue {
  background: linear-gradient(180deg, #5a7aaa, #4a6a9a);
  color: #fff;
}
.btn-blue:hover { background: linear-gradient(180deg, #4a6a9a, #3a5a8a); }
.btn-gray {
  background: linear-gradient(180deg, #aaa, #999);
  color: #fff;
}
.btn-gray:hover { background: linear-gradient(180deg, #999, #888); }
.btn-sm {
  padding: 2px 10px;
  font-size: 11px;
  border: 1px solid #888;
  border-radius: 2px;
  background: #e0e8e0;
  cursor: pointer;
}
.btn-sm:hover { background: #d0d8d0; }

/* Menu Dropdown (CSS-only checkbox toggle) */
.menu-wrapper {
  position: relative;
  display: inline-block;
}
.menu-toggle {
  display: none;
}
.menu-toggle:checked ~ .menu-dropdown {
  display: block;
}
.menu-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  background: #f0f4f0;
  border: 1px solid #888;
  border-radius: 3px;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.3);
  z-index: 100;
  min-width: 200px;
  margin-bottom: 4px;
}
.menu-dropdown a {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 12px;
  border: none;
  background: none;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  color: #333;
  box-sizing: border-box;
}
.menu-dropdown a:hover {
  background: #d0e0d0;
}
.menu-dropdown hr {
  border: none;
  border-top: 1px solid #ccc;
  margin: 2px 0;
}

/* Modals */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-content {
  background: #e8f0e8;
  border: 2px solid #6a8a6a;
  border-radius: 6px;
  min-width: 300px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-wide { max-width: 600px; }
.modal-header {
  background: linear-gradient(180deg, #6a8a6a, #5a7a5a);
  color: #fff;
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 4px 4px 0 0;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: #fcc; }
.modal-body {
  padding: 12px;
}
.hidden { display: none !important; }

/* Size List */
.size-type-grid {
  margin-bottom: 8px;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #e8ece8;
  padding: 6px 8px;
}
.size-type-row {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 12px;
  justify-content: space-around;
}
.size-type-row:last-child { margin-bottom: 0; }
.size-type-row label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 60px;
}
.size-list-header {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 4px;
  background: #e0e8e0;
  border: 1px solid #bbb;
  border-bottom: none;
  border-radius: 3px 3px 0 0;
}
.size-list {
  width: 100%;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  border: 1px solid #999;
  margin-bottom: 8px;
}

/* Coating */
.coating-grid {
  display: flex;
  gap: 16px;
}
.coating-section { flex: 1; }
.coating-section h3 {
  font-size: 12px;
  margin-bottom: 6px;
  border-bottom: 1px solid #999;
  padding-bottom: 2px;
}
.coating-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.coating-table th, .coating-table td {
  padding: 2px 6px;
  border: 1px solid #ccc;
  text-align: center;
}
.coating-table th { background: #e0e8e0; }
.coating-toggle {
  margin: 8px 0;
  font-size: 11px;
  display: flex;
  gap: 8px;
}

/* Config */
.config-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.config-row label { width: 140px; text-align: right; }
.config-row select { flex: 1; padding: 2px; }

/* Info Modal */
#infoContent {
  font-size: 12px;
  line-height: 1.5;
}
#infoContent h3 {
  margin: 8px 0 4px;
  font-size: 13px;
}
#infoContent table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0;
}
#infoContent td {
  padding: 2px 6px;
  border-bottom: 1px solid #ddd;
  font-family: 'Consolas', monospace;
  font-size: 11px;
}

/* Site Footer */
.site-footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 6px;
}
.footer-note {
  text-align: center;
  font-size: 11px;
  color: #8a9a8a;
  margin-bottom: 6px;
}
.ad-footer {
  padding: 4px;
  text-align: center;
  min-height: 50px;
  background: #c4d4c4;
  border-radius: 4px;
}

/* Help Diagrams */
.help-diagram {
  display: flex;
  justify-content: center;
  padding: 8px;
  background: #fafafa;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin: 4px 0;
}
.help-diagram svg {
  max-width: 100%;
  height: auto;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #e0e8e0; }
::-webkit-scrollbar-thumb { background: #8a9a8a; border-radius: 4px; }

/* Responsive - Tablet */
@media (max-width: 768px) {
  #app { padding: 4px; }

  .middle-row, .bottom-row, .footer-row {
    flex-direction: column;
  }

  /* Remove min-widths that force overflow */
  .thread-select, .classes-fit, .mow-panel,
  .starts-panel, .pct-panel, .tap-drills-panel,
  .loe-panel, .display-opts {
    min-width: 0;
    flex: none;
    width: 100%;
  }

  /* Panel headers: wrap fields below title */
  .panel-header {
    flex-wrap: wrap;
    gap: 4px 8px;
  }

  /* Header fields row: all fields in one row, labels above inputs */
  .header-fields {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 12px;
  }
  .header-field {
    flex-direction: column;
    align-items: center;
    gap: 1px;
  }
  .header-field label {
    font-size: 9px;
    text-align: center;
  }

  /* Dimension grid: 2 columns */
  .dim-grid {
    flex-wrap: wrap;
    gap: 6px;
  }
  .dim-section {
    min-width: calc(50% - 4px);
    flex: 1 1 calc(50% - 4px);
  }

  /* Inputs slightly smaller */
  .input-field, .result-field { width: 62px; }
  .result-field.sm, .input-field.sm { width: 50px; }
  .dim-labels span { width: 54px; font-size: 9px; }

  /* Action buttons horizontal on tablet */
  .action-buttons {
    flex-direction: row;
    justify-content: center;
  }

  /* Modals fit screen */
  .modal-content {
    min-width: 0;
    max-width: 95vw;
    margin: 8px;
  }
  .modal-wide { max-width: 95vw; }
}

/* Responsive - Phone */
@media (max-width: 480px) {
  body { font-size: 12px; }
  #app { padding: 2px; }

  .header-bar { padding: 6px 10px; }
  .header-bar h1 { font-size: 15px; }
  .header-bar .subtitle { display: block; margin-left: 0; font-size: 11px; }

  .main-layout { padding: 4px; }

  /* Panel headers: title on top, fields below in one row */
  .panel-header {
    flex-direction: column;
    gap: 2px;
    padding: 4px 6px;
    text-align: center;
  }
  .panel-title { flex-shrink: 1; }

  /* Header fields: single row, label above input */
  .header-fields {
    width: 100%;
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .header-field {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    flex: 1;
    min-width: 0;
  }
  .header-field label {
    font-size: 8px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .header-field input {
    width: 100%;
    min-width: 0;
  }

  /* Dimension grid: single column */
  .dim-grid {
    flex-direction: column;
    padding: 4px 6px;
    gap: 8px;
  }
  .dim-section {
    min-width: 0;
    flex: none;
    width: 100%;
  }

  /* Make inputs fill available space */
  .input-field, .result-field {
    width: 58px;
    height: 24px;
    font-size: 12px;
    padding: 2px 2px;
  }
  .result-field.sm, .input-field.sm {
    width: 48px;
  }

  /* Dim labels/values: allow shrinking */
  .dim-labels { gap: 2px; }
  .dim-labels span { width: auto; min-width: 40px; flex: 1; font-size: 9px; }
  .dim-values { gap: 2px; }
  .dim-values input { flex: 1; min-width: 0; }

  /* Thread type panel */
  .input-row { flex-wrap: wrap; }
  .series-row { flex-wrap: wrap; gap: 4px; }
  .radio-group { flex-wrap: wrap; gap: 4px; }

  /* Starts grid: wrap */
  .starts-grid {
    flex-wrap: wrap;
    gap: 4px;
  }
  .starts-grid .field-pair {
    min-width: calc(50% - 4px);
    flex: 1 1 calc(50% - 4px);
  }

  /* Percent thread - ensure both fields visible */
  .pct-grid {
    flex-wrap: nowrap;
    gap: 4px;
  }
  .pct-grid .field-pair {
    min-width: 0;
    flex: 1;
  }
  .pct-grid .field-pair select,
  .pct-grid .field-pair input {
    width: 100%;
    min-width: 0;
  }

  /* LOE grid: wrap */
  .loe-grid { flex-wrap: wrap; }

  /* Tap drills table */
  .tap-table-wrap { max-height: 150px; }
  .tap-type-toggle { font-size: 9px; gap: 4px; }

  /* Display options */
  .opts-row { flex-wrap: wrap; gap: 6px; }

  /* Action buttons: full width row */
  .action-buttons {
    flex-direction: row;
    width: 100%;
    justify-content: center;
    gap: 6px;
    padding: 4px 0;
  }
  .btn-action {
    padding: 8px 14px;
    font-size: 12px;
    min-width: 70px;
    flex: 1;
  }

  /* MOW panel */
  .mow-detail-row .dim-values input { width: auto; flex: 1; min-width: 0; }
  .mow-detail-row .dim-labels span { width: auto; flex: 1; min-width: 0; }

  /* Modals */
  .modal-content {
    min-width: 0;
    max-width: calc(100vw - 16px);
    max-height: 85vh;
    margin: 8px;
  }
  .modal-wide { max-width: calc(100vw - 16px); }
  .modal-body { padding: 8px; }

  /* Size modal */
  .size-type-row { gap: 6px; flex-wrap: wrap; }
  .size-type-row label { min-width: 50px; font-size: 11px; }

  /* Coating modal */
  .coating-grid { flex-direction: column; gap: 8px; }

  /* Config modal */
  .config-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .config-row label { width: auto; text-align: left; }
  .config-row select { width: 100%; }

  /* Footer */
  .footer-note { font-size: 10px; }

  /* Help diagrams: scale SVG */
  .help-diagram { padding: 4px; }
  .help-diagram svg { max-width: 100%; height: auto; }

  /* Panel subtitle (designation) */
  .panel-subtitle {
    font-size: 11px;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Prevent horizontal overflow but allow select dropdowns */
  .panel { overflow: visible; }
  .panel-body { overflow: visible; }
}

/* ===== Standalone Page Styles (Flask conversion) ===== */
.page-container {
  max-width: 980px;
  margin: 0 auto;
  padding: 6px;
}
.page-panel {
  background: #e8f0e8;
  border: 2px solid #6a8a6a;
  border-radius: 6px;
  margin-top: 8px;
}
.page-header {
  background: linear-gradient(180deg, #6a8a6a, #5a7a5a);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px 4px 0 0;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.page-body {
  padding: 12px 16px;
}
.back-link {
  display: inline-block;
  margin: 8px 0;
  padding: 4px 12px;
  background: linear-gradient(180deg, #5a8a5a, #4a7a4a);
  color: #fff;
  text-decoration: none;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #3a6a3a;
}
.back-link:hover {
  background: linear-gradient(180deg, #4a7a4a, #3a6a3a);
}
.nav-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.nav-links a {
  padding: 4px 12px;
  background: #e0e8e0;
  color: #333;
  text-decoration: none;
  border: 1px solid #999;
  border-radius: 3px;
  font-size: 12px;
}
.nav-links a:hover {
  background: #d0d8d0;
}
/* Export text area */
.export-textarea {
  width: 100%;
  min-height: 300px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  padding: 8px;
  border: 1px solid #999;
  border-radius: 3px;
  background: #fff;
  resize: vertical;
}
