/* ===== THEME VARIABLES & GLOBAL RESET ===== */
:root {
    --bg-main: #090A0F;
    --bg-card: rgba(22, 24, 33, 0.75);
    --bg-card-active: rgba(28, 30, 41, 0.85);
    --border-color: rgba(100, 200, 255, 0.08);
    --border-color-focus: rgba(0, 229, 255, 0.4);
    --text-primary: #FFFFFF;
    --text-secondary: #8E8F9E;
    --text-muted: #565869;
    --accent-blue: #00B0FF;
    --accent-cyan: #00E5FF;
    --accent-glow: rgba(0, 229, 255, 0.25);
    --gradient-accent: linear-gradient(135deg, #00B0FF, #00E5FF);
    --ios-gray: rgba(120, 120, 128, 0.16);
    --ios-gray-active: rgba(120, 120, 128, 0.24);
    
    /* Font stacks */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', SFMono-Regular, Consolas, monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Disable tap highlight on iOS */
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed; /* Stop elastic scrolling on iOS */
    background-color: var(--bg-main);
    font-family: var(--font-sans);
    color: var(--text-primary);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== MAIN APP LAYOUT (Perfect fit for iPhone 15 Pro) ===== */
.app-container {
    width: 100%;
    height: 100dvh; /* Dynamic viewport height to account for mobile address bars */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: radial-gradient(circle at 50% 0%, rgba(0, 176, 255, 0.08) 0%, rgba(9, 10, 15, 0) 70%), var(--bg-main);
    
    /* iPhone Safe Area Padding */
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}

/* ===== APP HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(0, 176, 255, 0.15), rgba(0, 229, 255, 0.05));
    border: 1px solid rgba(0, 229, 255, 0.2);
    color: var(--accent-cyan);
}

.header-titles h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.header-titles p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Pulsating Syringe Icon Animation */
@keyframes pulse {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; filter: drop-shadow(0 0 4px var(--accent-cyan)); }
    100% { transform: scale(1); opacity: 0.9; }
}
.pulse-icon {
    animation: pulse 3s infinite ease-in-out;
}

/* ===== MAIN AREA (FLEX & COMPACT CARDS) ===== */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px; /* Tight spaces to fit iPhone height */
    padding: 10px 0;
}

/* Card Section Base */
.card-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 14px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.card-section:focus-within {
    border-color: rgba(0, 229, 255, 0.2);
    background: var(--bg-card-active);
}

/* Base Labels */
.box-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* Input Grid (Half layouts) */
.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.control-box {
    display: flex;
    flex-direction: column;
}

/* ===== STEPPER CONTROLS (iOS Style + & -) ===== */
.stepper-control {
    display: flex;
    align-items: center;
    background: var(--ios-gray);
    border-radius: 12px;
    height: 44px; /* Apple minimum touch target height */
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.step-btn {
    width: 44px;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--accent-cyan);
    font-size: 1.4rem;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
}

.step-btn:active {
    background-color: var(--ios-gray-active);
    transform: scale(0.93);
}

.value-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    height: 100%;
}

/* Numeric input styling inside stepper */
.value-display input {
    width: 48px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.15rem;
    font-weight: 700;
    text-align: right;
    outline: none;
    padding-right: 2px;
}

.value-display .unit {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: 2px;
}

/* Prevent inputs from spinning */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
}

/* ===== PRESETS ROW (TAPPABLE BUBBLES) ===== */
.presets-row {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-top: 8px;
}

.preset-btn {
    flex: 1;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preset-btn.active {
    background: rgba(0, 229, 255, 0.15);
    color: var(--accent-cyan);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(0, 229, 255, 0.2);
}

.preset-btn:active:not(.active) {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== SEGMENT CONTROL (iOS UISegmentedControl Mimic) ===== */
.segment-control {
    display: flex;
    background: var(--ios-gray);
    border-radius: 12px;
    padding: 2px;
    height: 44px; /* Apple Standard Touch Target */
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.segment-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.segment-btn.active {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.segment-btn:active:not(.active) {
    background: rgba(255, 255, 255, 0.03);
}

/* Compact segment button */
.segment-control.mini {
    height: 32px;
    border-radius: 8px;
    padding: 1px;
}

.segment-control.mini .segment-btn {
    font-size: 0.72rem;
    border-radius: 7px;
}

/* ===== DROPDOWNS & SELECTS ===== */
.select-wrapper {
    position: relative;
    background: var(--ios-gray);
    border-radius: 12px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.02);
    overflow: hidden;
}

.select-wrapper::after {
    content: "";
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-30%) rotate(45deg);
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--accent-cyan);
    border-bottom: 2px solid var(--accent-cyan);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.select-wrapper select {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0 32px 0 14px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

/* Stepper inside Ampoules select */
.ampoules-box .value-display select {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    padding: 0 10px;
}

/* ===== LIVE CONCENTRATION BADGE ===== */
.concentration-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 229, 255, 0.06);
    border: 1px solid rgba(0, 229, 255, 0.15);
    border-radius: 10px;
    padding: 8px 12px;
    margin-top: 10px;
}

.pulse-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-cyan);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-cyan);
}

.badge-text {
    font-size: 0.78rem;
    color: var(--accent-cyan);
    font-weight: 600;
    letter-spacing: -0.1px;
}

.badge-text strong {
    font-weight: 700;
    color: #FFFFFF;
}

/* ===== SPEED SECTION ===== */
.speed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.speed-header .box-label {
    margin-bottom: 0;
}

.speed-stepper-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.micro-steppers {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.micro-btn {
    width: 38px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: var(--ios-gray);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.micro-btn:active {
    background: var(--ios-gray-active);
    color: var(--text-primary);
    transform: scale(0.92);
}

.speed-input-box {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.25);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    height: 56px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 12px;
    transition: all 0.3s;
}

.speed-input-box:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 12px var(--accent-glow);
}

.speed-input-box input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1.4rem;
    font-weight: 800;
    outline: none;
    text-align: center;
    margin-top: -2px;
}

.speed-unit-text {
    font-size: 0.65rem;
    color: var(--accent-cyan);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-align: center;
    margin-top: 2px;
}

.speed-presets {
    margin-top: 8px;
}

/* ===== RESULTS DASHBOARD ===== */
.results-dashboard {
    background: linear-gradient(135deg, rgba(14, 21, 35, 0.9) 0%, rgba(8, 11, 18, 0.95) 100%);
    border: 1.5px solid rgba(0, 229, 255, 0.15);
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255,255,255,0.05);
}

.main-output {
    text-align: center;
    padding: 4px 0;
}

.output-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.output-value {
    font-size: 3.2rem;
    font-weight: 800;
    line-height: 1;
    color: #FFFFFF;
    letter-spacing: -1.5px;
    text-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
    margin: 4px 0;
    font-family: var(--font-sans);
}

.output-unit {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.secondary-output {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 6px 12px;
    margin: 6px auto 12px;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.alt-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.alt-value {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Details table inside card */
.details-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 10px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.detail-val {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.detail-val.highlight {
    color: #FFB300; /* Warm warning yellow for syringe lifetime */
    font-family: var(--font-mono);
}

/* ===== iOS INSTALL TO HOME SCREEN PROMPT ===== */
.ios-install-prompt {
    display: none; /* Controlled by JS */
    position: fixed;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 12px);
    left: 16px;
    right: 16px;
    background: rgba(28, 30, 41, 0.98);
    border: 1px solid rgba(0, 229, 255, 0.25);
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8);
    z-index: 1000;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: slideUpPrompt 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpPrompt {
    from { transform: translateY(120%) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.prompt-content {
    position: relative;
}

.close-prompt-btn {
    position: absolute;
    top: -10px;
    right: -6px;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.prompt-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #FFFFFF;
    margin-bottom: 4px;
}

.prompt-text {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.prompt-steps {
    padding-left: 16px;
    font-size: 0.78rem;
    color: #FFFFFF;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prompt-steps li {
    line-height: 1.35;
}

.share-icon-placeholder {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin: 0 2px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2300E5FF" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
}

.add-icon-placeholder {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin: 0 2px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2300E5FF" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
}

.prompt-arrow {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 16px;
    height: 16px;
    background: rgba(28, 30, 41, 0.98);
    border-right: 1px solid rgba(0, 229, 255, 0.25);
    border-bottom: 1px solid rgba(0, 229, 255, 0.25);
}

/* ===== ENHANCED TAP FEEDBACKS & ACTIVE STATES ===== */
button, select {
    outline: none;
}

/* Micro bounce for clicks */
button:active {
    transform: scale(0.96);
}

/* Disable body scrolling & default text selection on mobile */
body {
    -webkit-user-select: none;
    user-select: none;
}
input[type=number] {
    -webkit-user-select: text;
    user-select: text; /* Allow typing */
}
