/* --- Variables --- */
:root {
  --color-text-primary: #1e293b; /* slate-800 */
  --color-text-secondary: #475569; /* slate-600 */
  --color-text-muted: #64748b; /* slate-500 */
  --color-text-inverted: #e2e8f0; /* slate-200 */

  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f8fafc; 
  --color-bg-subtle: #f1f5f9; /* slate-100 */

  --color-border-primary: #e2e8f0; /* slate-200 */
  --color-border-dark: #334155; /* slate-700 */

  --color-brand: #0e73e6; /* Kadence-like blue */
  --color-brand-text: #0b5ab8; /* Darker Kadence-like blue */

  --color-risk-low: #4ade80; /* green-400 */
  --color-risk-moderate: #facc15; /* yellow-400 */
  --color-risk-high: #ef4444; /* red-500 */
  
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);

  --border-radius-md: 0.375rem; /* rounded-md */
  --border-radius-lg: 0.5rem; /* rounded-lg */
  --border-radius-2xl: 1.5rem; /* rounded-2xl */
  --border-radius-full: 9999px;
}

/* --- Dark Mode Variables --- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text-primary: #e2e8f0; /* slate-200 */
    --color-text-secondary: #94a3b8; /* slate-400 */
    --color-text-muted: #94a3b8; /* slate-400 */
    --color-text-inverted: #1e293b; /* slate-800 */
    
    --color-bg-primary: #1e293b;
    --color-bg-secondary: #0f172a;
    --color-bg-subtle: #334155;

    --color-border-primary: #334155;
    --color-brand-text: #60a5fa; /* blue-400 */
  }
}

/* --- Base Styles --- */
main {
  max-width: 1290px;
  margin-left: auto;
  margin-right: auto;
  color: var(--color-text-primary);
  transition: color 0.3s, background-color 0.3s;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
}

/* --- Header --- */
header {
  text-align: center;
  margin-bottom: 2rem;
}

header p {
  margin-top: 0.5rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  color: var(--color-text-secondary);
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

/* --- Layout --- */
.calculator-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 2rem;
}

@media (min-width: 1024px) { /* lg */
  .calculator-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .input-panel {
    grid-column: span 2 / span 2;
  }
  #result-wrapper {
    grid-column: span 3 / span 3;
  }
}

/* --- Panels / Cards --- */
.panel {
  /* Styles for background, padding, shadow, and border are removed 
     to allow the component to blend into the host page (e.g., WordPress). */
}

.panel h2 {
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 700;
  margin: 0 0 1.5rem 0;
}

/* --- Input Form --- */
.form-groups-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  width: 100%;
  background-color: var(--color-bg-subtle);
  border-radius: var(--border-radius-lg);
  padding: 0.25rem;
}
.segmented-control button {
  width: 100%;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius-md);
  text-align: center;
  font-weight: 600;
  transition: all 0.2s;
  border: none;
  background-color: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.segmented-control button:hover {
    background-color: rgba(148, 163, 184, 0.2);
}
.segmented-control button.active {
  background-color: var(--color-bg-primary);
  color: var(--color-brand-text);
  box-shadow: var(--shadow);
}
.segmented-control button:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

/* Input Field */
.input-wrapper {
  position: relative;
}

input[type="number"] {
  width: 100%;
  padding: 0.75rem 4rem 0.75rem 1rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  background-color: var(--color-bg-subtle);
  border: 2px solid transparent;
  border-radius: var(--border-radius-lg);
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  color: var(--color-text-primary);
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px rgba(14, 115, 230, 0.4);
}

.input-unit-display {
  position: absolute;
  inset: 0;
  right: 1rem;
  left: auto;
  display: flex;
  align-items: center;
  pointer-events: none;
}
.input-unit-display span {
  color: var(--color-text-muted);
  font-weight: 600;
}

/* --- Result Display --- */
/* Placeholder */
#placeholder-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 480px;
    color: var(--color-text-muted);
    text-align: center;
}
#placeholder-container.hidden { display: none; }
#placeholder-container svg {
    margin: 0 auto 0.5rem;
    height: 3rem;
    width: 3rem;
    stroke: var(--color-text-muted);
}
#placeholder-container h3 {
    margin-top: 0.5rem;
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--color-text-primary);
}
#placeholder-container p {
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

/* Result View */
#result-container.hidden { display: none; }
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
}
.result-actions button {
    padding: 0.5rem;
    border-radius: var(--border-radius-full);
    color: var(--color-text-muted);
    background-color: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}
.result-actions button:hover {
    background-color: var(--color-bg-subtle);
    color: var(--color-text-primary);
}
.result-actions button svg {
    height: 1.25rem;
    width: 1.25rem;
}

.result-summary {
  text-align: center;
  margin: 1.5rem 0;
}
.result-summary p { margin: 0; }
.result-summary p:first-child {
  font-size: 1.125rem;
  color: var(--color-text-secondary);
}
#result-ratio {
  font-size: 3.75rem;
  line-height: 1;
  font-weight: 700;
  margin: 0.5rem 0;
}
#result-category {
  font-size: 1.5rem;
  font-weight: 600;
  transition: color 0.3s;
}
.category-low { color: var(--color-risk-low); }
.category-moderate { color: var(--color-risk-moderate); }
.category-high { color: var(--color-risk-high); }

#result-interpretation {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--color-text-secondary);
}

/* WHR Gauge */
#whr-gauge {
    width: 100%;
    user-select: none;
    margin-top: 2rem;
}
.gauge-bar {
    position: relative;
    height: 1rem;
    border-radius: var(--border-radius-full);
    display: flex;
    overflow: hidden;
    border: 2px solid transparent;
}
@media (prefers-color-scheme: dark) { .gauge-bar { border-color: var(--color-border-dark); } }

#gauge-low-segment { background-color: var(--color-risk-low); }
#gauge-moderate-segment { background-color: var(--color-risk-moderate); }
#gauge-high-segment { background-color: var(--color-risk-high); }

#gauge-indicator {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: left 0.3s ease-out;
}
.indicator-dot {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: var(--border-radius-full);
    background-color: var(--color-bg-primary);
    border: 4px solid var(--color-brand);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.indicator-dot-inner {
    width: 0.25rem;
    height: 0.25rem;
    border-radius: var(--border-radius-full);
    background-color: var(--color-brand);
}

.gauge-labels {
    position: relative;
    width: 100%;
    height: 1rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
}
.gauge-labels span {
    position: absolute;
    transform: translateX(-50%);
    transition: left 0.3s ease-out;
}

#gauge-category-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}
#gauge-category-labels > span {
    flex-shrink: 0;
    transition: width 0.3s ease-out;
}
#gauge-cat-low { text-align: left; }
#gauge-cat-moderate { text-align: center; }
#gauge-cat-high { text-align: right; }

/* Category Info */
#category-info-container {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border-primary);
}
#category-info-title {
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-align: center;
}
@media (min-width: 640px) { #category-info-title { text-align: left; } }

#category-info-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#category-info-list .category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background-color: var(--color-bg-subtle);
    border-radius: var(--border-radius-lg);
}
.category-item-details {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.category-color-dot {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: var(--border-radius-full);
}
.category-item-name { font-weight: 500; }
.category-item-range {
    font-family: monospace;
    color: var(--color-text-secondary);
}

/* --- How to Measure & Footer --- */
.how-to-measure {
  margin-top: 2rem;
}
footer {
    margin-top: 3rem;
}

.how-to-measure-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem 2rem;
}
@media (min-width: 768px) { .how-to-measure-grid { grid-template-columns: 1fr 1fr; } }

.how-to-measure h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.75rem 0;
}
.how-to-measure ul {
    padding-left: 1.25rem;
    list-style-type: decimal;
    color: var(--color-text-secondary);
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

footer {
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}
footer p { margin: 0.25rem 0; }

/* --- Print styles --- */
@media print {
    .no-print {
        display: none !important;
    }
    main {
        max-width: 100%;
        color: #000 !important;
    }
    .panel {
        box-shadow: none;
        border: 1px solid #ccc;
        background-color: #fff !important;
    }
    .result-summary p:first-child, 
    #result-interpretation, 
    .gauge-labels, 
    #gauge-category-labels, 
    .category-item-range,
    header p,
    .how-to-measure ul {
        color: #555 !important;
    }
}