/*
  Copyright (c) 2024-2026 Dr. Hanna. All Rights Reserved.
  This software is proprietary and confidential.
  Unauthorized copying, distribution, or use of this file via any medium is strictly prohibited without a valid license.
  For licensing inquiries, please contact: hannafeedingcalc@proton.me
*/
:root {
    --primary: #1a7a6d;
    --primary-text: #ffffff;
    --secondary: #2a9d8f;
    --success: #28a745;
    --success-text: #155724;
    --warning: #ffc107;
    --warning-text: #856404;
    --warning-text-on-bg: #333333;
    --danger: #dc3545;
    --danger-text: #721c24;
    --white: #FFFFFF;
    --text-primary: #333333;
    --text-secondary: #666666;
    --light-bg: #f8f9fa;
    --border: #dee2e6;
    --warning-bg: #fff8e1;
    --danger-bg: #ffebee;
    --success-bg: #f0f9ff;
    --preview-bg: #fff9e6;
}

/* Dark mode — tool-specific overrides (shared vars in dark-theme.css) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --secondary: #6EC6AF;
        --light-bg: #333333;
        --success-text: #80e0a0;
        --warning-text-on-bg: #e0e0e0;
        --success-bg: #203540;
        --preview-bg: #3d3820;
    }
}

:root[data-theme="dark"] {
    --secondary: #6EC6AF;
    --light-bg: #333333;
    --success-text: #80e0a0;
    --warning-text-on-bg: #e0e0e0;
    --success-bg: #203540;
    --preview-bg: #3d3820;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

input, textarea, select, button {
    font-family: inherit;
}

body {
    font-family: 'DM Sans', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 15px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 76px 20px 20px 20px;
}

/* Floating Action Bar */
.floating-action-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    background: var(--primary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.fab-left {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.fab-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

.floating-action-bar .btn-primary {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.floating-action-bar .btn-primary:hover {
    background: rgba(255, 255, 255, 0.25);
}

.btn-fab-generate {
    padding: 6px 14px;
    border: 2px solid white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    background: white;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
}

.btn-fab-generate:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.auto-save-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
}

.restore-banner {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    background: var(--warning-bg);
    border-bottom: 2px solid var(--warning);
    font-size: 13px;
    color: var(--text-primary);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

header {
    background: var(--primary);
    color: var(--white);
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 28px;
    margin-bottom: 10px;
    color: var(--white);
}

header p {
    font-size: 15px;
    opacity: 0.9;
    color: var(--white);
}

.main-content {
    padding: 30px;
}

/* Mode Selection */
.mode-selection {
    background: var(--light-bg);
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 30px;
    width: 100%;
    /* Clearfix */
    box-sizing: border-box;
}

.mode-selection h2 {
    color: var(--primary);
    margin-bottom: 15px;
    font-size: 20px;
}

.mode-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: 200px;
    padding: 20px;
    border: 3px solid var(--border);
    background: var(--white);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.mode-btn:hover {
    border-color: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.mode-btn.active {
    border-color: var(--primary);
    background: var(--success-bg);
}

.mode-btn h3 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 18px;
}

.mode-btn p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

/* Scope pill toggle */
.scope-selector {
    margin-top: 24px;
}

.scope-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 680px;
    margin: 0 auto;
}

.scope-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 3px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    background: var(--white);
}

.scope-card:hover {
    border-color: var(--secondary);
}

.scope-card.active {
    border-color: var(--primary);
    background: var(--success-bg);
}

.scope-card-radio {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 50%;
    margin-top: 1px;
    transition: border-color 0.2s ease;
    position: relative;
}

.scope-card.active .scope-card-radio {
    border-color: var(--primary);
}

.scope-card.active .scope-card-radio::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

.scope-card-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.scope-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.scope-card.active .scope-card-title {
    color: var(--primary);
}

.scope-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Legacy toolbar nav (kept for section jump links if reused) */
.toolbar-nav {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-nav:empty {
    display: none;
}

/* Outline button (for destructive/secondary actions) */
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

/* Protocol Configuration Sections */
.protocol-section {
    margin-bottom: 30px;
    padding: 25px;
    border: 2px solid var(--border);
    border-radius: 8px;
    display: none;
    position: relative;
    /* Layout Safety */
    z-index: 1;
    /* Ensure stacking context */
    background: var(--white);
    /* Ensure opacity */
}

.protocol-section.active {
    display: block;
}

.protocol-section h2 {
    color: var(--primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Table Styles */
.tier-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 15px;
}

.tier-table th {
    background: var(--primary);
    color: var(--primary-text);
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.tier-table td {
    padding: 8px;
    border: 1px solid var(--border);
}

.tier-table input,
.tier-table select {
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
}

.tier-table select {
    width: 100%;
}

.tier-table input:focus,
.tier-table select:focus {
    outline: none;
    border-color: var(--secondary);
}

.tier-table input[type="number"] {
    text-align: right;
    width: 70px;
}

.tier-table input[type="text"] {
    width: 100%;
    min-width: 220px;
}

.tier-table textarea {
    width: 100%;
}

.tier-table td:first-child {
    white-space: nowrap;
}

/* Compact numeric columns */
.tier-table td:nth-child(3),
.tier-table td:nth-child(4),
.tier-table td:nth-child(5),
.tier-table td:nth-child(6),
.tier-table td:nth-child(7),
.tier-table td:nth-child(8),
.tier-table td:nth-child(9) {
    width: 80px;
}

.tier-table th:nth-child(3),
.tier-table th:nth-child(4),
.tier-table th:nth-child(5),
.tier-table th:nth-child(6),
.tier-table th:nth-child(7),
.tier-table th:nth-child(8),
.tier-table th:nth-child(9) {
    width: 80px;
}

.tier-table tr:hover {
    background: #f8f9fa;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-text);
}

.btn-success {
    background: var(--success);
    color: var(--primary-text);
}

.btn-warning {
    background: var(--warning);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: var(--primary-text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* Delete Button in Table */
.delete-row-btn {
    background: var(--danger);
    color: var(--primary-text);
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
}

.delete-row-btn:hover {
    background: #c82333;
}

/* Combined Protocol Settings */
.weight-sliders {
    background: var(--light-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.slider-group {
    margin-bottom: 20px;
}

.slider-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.slider-container input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    background: var(--border);
    outline: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.slider-container .slider-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    min-width: 60px;
    text-align: right;
}

/* Live Preview */
.preview-section {
    background: var(--preview-bg);
    border: 2px solid var(--warning);
    border-radius: 8px;
    padding: 20px;
    margin-top: 30px;
}

.preview-section h3 {
    color: var(--primary);
    margin-bottom: 15px;
}

.preview-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.preview-inputs label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.preview-inputs input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.preview-output {
    background: var(--white);
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid var(--success);
}

.preview-output h4 {
    color: var(--primary);
    margin-bottom: 10px;
}

.preview-output p {
    margin: 5px 0;
    font-size: 15px;
}

.preview-output strong {
    color: var(--primary);
}

/* Action Buttons Footer */
.action-footer {
    background: var(--light-bg);
    padding: 25px;
    border-top: 2px solid var(--border);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Validation Messages */
.validation-message {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: none;
}

.validation-message.error {
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    color: var(--danger-text);
}

.validation-message.success {
    background: var(--success-bg);
    border: 1px solid var(--success);
    color: var(--success-text);
}

.validation-message.warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    color: var(--warning-text);
}

/* Protocol Info */
.protocol-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.protocol-info label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--primary);
}

.protocol-info input,
.protocol-info textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.protocol-info textarea {
    resize: vertical;
    min-height: 60px;
}

.form-control {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 15px;
    background: var(--white);
    color: var(--text-primary);
    resize: vertical;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26, 122, 109, 0.15);
}

/* Tooltips */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    color: var(--secondary);
    margin-left: 5px;
}

.tooltip:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: var(--primary-text);
    padding: 8px 12px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 13px;
    z-index: 1000;
}

/* Extracted from inline styles and JS */
.protocol-info-section {
    display: none;
}

.full-width-col {
    grid-column: 1 / -1;
}

.tier-shift-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.form-select,
.form-input,
.contraindication-input,
.clinical-note-input,
.clinical-note-textarea {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.contraindication-input {
    flex: 1;
    /* Override width for flex context */
}

.example-text {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.adv-multiplier-section {
    grid-column: 1 / -1;
    display: none;
}

.adv-multiplier-container {
    background: var(--light-bg);
    padding: 15px;
    border-radius: 6px;
    margin-top: 10px;
}

.adv-multiplier-title {
    color: var(--primary);
    margin-bottom: 10px;
}

/* JS Dynamic Elements */
.contraindication-row {
    display: flex;
    align-items: center;
    padding: 8px;
    background: var(--light-bg);
    border-radius: 4px;
    gap: 8px;
}

.contraindication-checkbox {
    margin-right: 10px;
}

.clinical-note-item {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 10px;
}

.clinical-note-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: start;
}

.clinical-note-input {
    margin-bottom: 8px;
}

.clinical-note-textarea {
    resize: vertical;
    min-height: 50px;
}

.clinical-note-delete {
    margin-top: 4px;
}

.adv-multiplier-input {
    width: 150px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Refactored inline styles from Protocol Builder.html */
.header-layout {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
}

.logo-img {
    height: 120px;
    width: auto;
}

/* Theme toggle is now in floating action bar */

.literature-ref-box {
    margin-top: 20px;
    padding: 15px;
    background: var(--success-bg);
    border-radius: 8px;
    border-left: 4px solid var(--secondary);
}

.literature-ref-title {
    color: var(--primary);
    margin-bottom: 15px;
}

.input-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.optional-tag {
    font-size: 13px;
    font-weight: normal;
    color: var(--text-secondary);
}

.warning-box-styled {
    padding: 20px;
    background: var(--warning-bg);
    border-radius: 8px;
    border: 2px solid #ffa726;
    margin-bottom: 20px;
}

.white-box {
    background: var(--white);
    padding: 15px;
    border-radius: 6px;
}

.flex-item-center {
    display: flex;
    align-items: center;
}

.section-margin-top {
    margin-top: 30px;
}

.grid-full-width {
    grid-column: 1 / -1;
}

.textarea-min-height {
    min-height: 80px;
}

.nested-indent {
    margin: 8px 0 0 28px;
    font-size: 13px;
    color: var(--text-secondary);
}

.nested-section {
    display: none;
    padding-left: 10px;
    border-left: 3px solid #ffa726;
}

.gap-20 {
    gap: 20px;
}

.margin-bottom-15 {
    margin-bottom: 15px;
}

.margin-top-10 {
    margin-top: 10px;
}

.width-auto {
    width: auto;
}

.cursor-pointer {
    cursor: pointer;
}

.font-size-16 {
    font-size: 15px;
}

.font-weight-600 {
    font-weight: 600;
}

.display-block {
    display: block;
}

.flex-wrap {
    flex-wrap: wrap;
}

.transition-input {
    width: 60px;
    margin: 0 6px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.checkbox-margin-right {
    margin-right: 10px;
}

.checkbox-margin-right-8 {
    margin-right: 8px;
}

/* ---------- Mode-card info popover ---------- */

/* Theme-aware shadow token (dark mode shadow visibility). */
:root { --shadow-popover: 0 6px 18px rgba(0, 0, 0, 0.18); }
:root[data-theme="dark"] { --shadow-popover: 0 6px 18px rgba(0, 0, 0, 0.55); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --shadow-popover: 0 6px 18px rgba(0, 0, 0, 0.55); }
}

.mode-btn { position: relative; }

.mode-info-trigger {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.mode-info-trigger:hover,
.mode-info-trigger:focus-visible,
.mode-info-trigger[aria-expanded="true"] {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--light-bg);
    outline: none;
}

.mode-info-popover {
    position: absolute;
    top: 38px;
    right: 8px;
    z-index: 1100;
    width: 240px;
    max-width: calc(100% - 16px);
    padding: 10px 12px;
    background: var(--white);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow-popover, 0 6px 18px rgba(0, 0, 0, 0.18));
    text-align: left;
    font-size: 13px;
    line-height: 1.4;
    transform: none;
}
.mode-info-popover[hidden] { display: none; }
.mode-info-popover::before,
.mode-info-popover::after {
    content: "";
    position: absolute;
    top: -7px;
    right: 12px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid var(--border);
}
.mode-info-popover::after {
    top: -6px;
    border-bottom-color: var(--white);
}

.mode-info-popover-hint {
    margin: 0 0 8px 0;
    color: var(--text-primary);
}

.mode-info-popover-action {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
}
.mode-info-popover-action:hover,
.mode-info-popover-action:focus-visible {
    outline: none;
    text-decoration: none;
}

/* ---------- Inline <details> expander ---------- */

.mode-details-group {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-details {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
}
.mode-details > summary {
    padding: 10px 14px;
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    font-size: 14px;
    list-style: none;
    user-select: none;
}
.mode-details > summary::-webkit-details-marker { display: none; }
.mode-details > summary::before {
    content: "\25B8";
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.15s;
}
.mode-details[open] > summary::before { transform: rotate(90deg); }
.mode-details[open] { border-color: var(--primary); }
.mode-details-body {
    padding: 4px 14px 14px 14px;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.55;
}
.mode-details-body p { margin: 0 0 8px 0; }
.mode-details-body p:last-child { margin-bottom: 0; }

@media (max-width: 480px) {
    .mode-info-popover {
        width: auto;
        left: 8px;
        right: 8px;
        max-width: none;
    }
    .mode-info-popover::before,
    .mode-info-popover::after { right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
    .mode-info-trigger,
    .mode-details > summary::before { transition: none; }
}