/* Rocuronium PK/PD Simulator - OR Monitor Dark Theme */
/* Matched to propofol/remimazolam TCI apps */

/* ============================================
   CSS Variables - OR Monitor Dark Palette
   ============================================ */
:root {
    --primary: #00BCD4;
    --primary-dark: #0097A7;
    --primary-light: rgba(0,188,212,0.15);

    --success: #4CAF50;
    --success-light: rgba(76,175,80,0.15);
    --warning: #FFC107;
    --warning-light: rgba(255,193,7,0.15);
    --danger: #F44336;
    --danger-light: rgba(244,67,54,0.15);
    --info: #29B6F6;

    --bg: #1a1a1a;
    --bg-card: #2d2d2d;
    --bg-surface: #3a3a3a;
    --bg-elevated: #444444;

    --text: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #707070;
    --text-bright: #ffffff;

    --border: #4a4a4a;
    --border-light: #3a3a3a;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);

    --font: "Figtree", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", "Menlo", "Monaco", monospace;

    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);

    /* Chart colors */
    --chart-plasma: #29B6F6;
    --chart-effect: #4CAF50;
    --chart-tof: #CE93D8;
    --chart-grid: rgba(255,255,255,0.08);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent iOS auto-zoom on input focus */
input, select, textarea {
    font-size: max(16px, 1rem);
    color: var(--text);
}

/* Data value styling with monospace font */
.data-value,
.results-table td,
#maxPlasma,
#maxEffect {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 1rem 0;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-bright);
}

p {
    margin: 0 0 1rem 0;
}

ul {
    padding-left: 1.5rem;
}

li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

/* ============================================
   Layout
   ============================================ */
.main-app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
    padding-top: calc(16px + var(--sat));
    padding-bottom: calc(16px + var(--sab));
    padding-left: calc(16px + var(--sal));
    padding-right: calc(16px + var(--sar));
    background-color: var(--bg);
    min-height: 100vh;
}

.hidden {
    display: none;
}

/* ============================================
   Navigation Tabs
   ============================================ */
.tab-nav {
    display: flex;
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 4px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
    justify-content: center;
    min-height: 44px;
}

.tab-btn:hover {
    background-color: var(--bg-surface);
    color: var(--text);
}

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

.tab-icon {
    font-size: 14px;
    opacity: 0.9;
}

.tab-text {
    font-weight: 500;
}

/* ============================================
   Tab Content
   ============================================ */
.tab-content {
    min-height: 600px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ============================================
   Header
   ============================================ */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 8px;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-surface);
}

.card-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-bright);
}

.card-content {
    padding: 16px;
}

/* ============================================
   Patient Information Grid
   ============================================ */
.patient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    padding: 16px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-item label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item span {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    font-family: var(--mono);
}

/* ============================================
   Buttons
   ============================================ */
.primary-btn,
.secondary-btn,
.edit-btn,
.accept-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    min-height: 44px;
}

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

.primary-btn:hover:not(:disabled) {
    background-color: var(--primary-dark);
    box-shadow: var(--shadow-lg);
}

.primary-btn:disabled {
    background-color: var(--bg-elevated);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.6;
}

.secondary-btn {
    background-color: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.secondary-btn:hover {
    background-color: var(--bg-elevated);
    border-color: var(--primary);
    color: var(--primary);
}

.edit-btn {
    background-color: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 8px 12px;
    font-size: 12px;
}

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

/* ============================================
   Summary Cards
   ============================================ */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}

.summary-card h4 {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-card .value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.summary-card .unit {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================
   Chart Container
   ============================================ */
.chart-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    height: 400px;
}

/* ============================================
   Results Table
   ============================================ */
.results-table-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.results-table th {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.results-table td {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.8rem;
}

.results-table tbody tr:hover {
    background-color: var(--bg-surface);
}

/* ============================================
   Dose Events
   ============================================ */
.dose-events-container {
    margin-bottom: 24px;
}

.dose-events-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.dose-event {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-sm);
    padding: 16px;
    box-shadow: var(--shadow);
}

.dose-info h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 8px;
}

.dose-details {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.dose-details span {
    padding: 4px 8px;
    background-color: var(--primary-light);
    color: var(--primary);
    border-radius: 4px;
    font-weight: 500;
    font-family: var(--mono);
}

.dose-stop {
    background-color: var(--danger-light) !important;
    color: var(--danger) !important;
}

.delete-dose {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-dose:hover {
    background-color: var(--danger-light);
    color: var(--danger);
}

/* ============================================
   Actions
   ============================================ */
.actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

/* ============================================
   No Results State
   ============================================ */
.no-results {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.no-results h2 {
    font-size: 1.25rem;
    color: var(--text);
    margin-bottom: 12px;
}

/* ============================================
   Modals
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-bright);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background-color: var(--bg-surface);
    color: var(--text-bright);
}

/* ============================================
   Forms
   ============================================ */
.patient-form,
.dose-form {
    padding: 16px;
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="time"],
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--border-radius-sm);
    font-family: var(--font);
    font-size: 16px;
    background-color: var(--bg-surface);
    color: var(--text);
    transition: border-color 0.2s ease;
    min-height: 44px;
}

.form-group input[type="text"]:focus,
.form-group input[type="time"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group select option {
    background-color: var(--bg-card);
    color: var(--text);
}

/* Range slider dark styling */
.form-group input[type="range"] {
    width: 100%;
    margin: 8px 0;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    outline: none;
}

.form-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.form-group input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.radio-group {
    display: flex;
    gap: 24px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    margin-bottom: 0;
    color: var(--text);
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: var(--primary);
    width: 18px;
    height: 18px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.note {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 8px 0;
}

/* ============================================
   Disclaimer Modal
   ============================================ */
.disclaimer-header {
    text-align: center;
    padding: 24px 16px 0;
}

.disclaimer-header .warning-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    display: block;
}

.disclaimer-header h2 {
    color: var(--warning);
    font-size: 1.5rem;
}

.disclaimer-text {
    color: var(--text-secondary);
    line-height: 1.7;
    padding: 0 24px;
    margin-bottom: 24px;
}

.disclaimer-text p {
    margin-bottom: 8px;
}

.accept-btn {
    background-color: var(--primary);
    color: var(--text-bright);
    width: calc(100% - 48px);
    margin: 0 24px 24px;
    padding: 14px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-family: var(--font);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
}

.accept-btn:hover {
    background-color: var(--primary-dark);
}

/* ============================================
   Info Tab
   ============================================ */
.app-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.version {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.rk4-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: var(--text-bright);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

.warning-card .card-header {
    background-color: var(--warning-light);
    border-color: rgba(255,193,7,0.3);
}

.warning-card .warning-icon {
    color: var(--warning);
    font-size: 1.25rem;
}

.reference-card .reference-icon {
    color: var(--info);
    font-size: 1.25rem;
}

.developer-card .developer-icon {
    color: var(--primary);
    font-size: 1.25rem;
}

.technical-card .technical-icon {
    color: var(--primary);
    font-size: 1.25rem;
}

.technical-card .technical-details {
    margin-top: 1rem;
}

.technical-card .technical-details h4 {
    color: var(--primary);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.technical-card .technical-details ul {
    margin-left: 1rem;
    margin-bottom: 1rem;
}

.technical-card .technical-details li {
    margin-bottom: 0.25rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.calculation-card .calculation-icon {
    color: var(--success);
    font-size: 1.25rem;
}

.privacy-card .privacy-icon {
    color: var(--text-secondary);
    font-size: 1.25rem;
}

.reference {
    background-color: var(--bg-surface);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    margin-top: 16px;
    border-left: 3px solid var(--primary);
}

.reference h4 {
    color: var(--primary);
    margin-bottom: 8px;
}

.doi {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.orcid {
    font-family: var(--mono);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.tech {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.model-details {
    background-color: var(--bg-surface);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    margin: 16px 0;
    border-left: 3px solid var(--primary);
}

.model-details h4 {
    color: var(--primary);
    margin-bottom: 8px;
}

.model-details p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ============================================
   Loading State
   ============================================ */
.loading {
    display: flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .main-app {
        padding: 8px;
        padding-top: calc(8px + var(--sat));
        padding-bottom: calc(8px + var(--sab));
        padding-left: calc(8px + var(--sal));
        padding-right: calc(8px + var(--sar));
    }

    .tab-nav {
        gap: 2px;
    }

    .tab-btn {
        padding: 10px 8px;
        font-size: 13px;
        gap: 4px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .patient-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .dose-event {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .dose-details {
        flex-direction: column;
        gap: 8px;
    }

    .actions {
        flex-direction: column;
        width: 100%;
    }

    .actions button {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }

    .chart-container {
        height: 300px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.25rem;
    }

    .patient-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 12px;
    }

    .modal-content {
        margin: 8px;
        max-height: calc(100vh - 2rem);
    }

    .results-table {
        font-size: 0.7rem;
    }

    .results-table th,
    .results-table td {
        padding: 6px 8px;
    }
}

/* ============================================
   Focus & Accessibility
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
