.engineering-calculator-container {
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.engineering-calculator {
    box-sizing: border-box;
    position: relative;
    max-width: 730px;
    width: 100%;
    min-width: 0;
    background: var(--ec-bg, #f0f0f0);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    color: var(--ec-text, #333333);
}

.display { margin-bottom: 16px; }

#engineering-result {
    box-sizing: border-box;
    width: 100%;
    height: 60px;
    min-height: 48px;
    font-size: clamp(16px, 5vw, 24px);
    text-align: right;
    padding: 0 15px;
    border: none;
    border-radius: 10px;
    background: var(--ec-display-bg, #ffffff);
    color: var(--ec-text, #333333);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

.calc-header-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 15px;
}

.calc-header-row .units-toggle,
.calc-header-row .calc-dropdown-wrap { display: flex; align-items: stretch; }

.calc-header-row .units-toggle { margin-bottom: 0; }
.calc-header-row .switch { height: 34px; min-height: 34px; flex-shrink: 0; }
.calc-header-row .calc-dropdown-btn { height: 34px; min-height: 34px; }

.calc-dropdown-wrap { position: relative; }

.calc-dropdown-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--ec-btn-func, #d0d0d0);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.calc-dropdown-btn:hover { filter: brightness(0.9); }
.calc-dropdown-btn.calc-dropdown-open { filter: brightness(0.85); }

.calc-history-panel,
.calc-help-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    margin-top: 6px;
    min-width: 100%;
    width: max-content;
    max-width: min(320px, calc(100vw - 40px));
    max-height: min(280px, 50vh);
    background: var(--ec-display-bg, #ffffff);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
    z-index: 100;
}

.calc-history-panel.calc-history-open,
.calc-help-panel.calc-help-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.calc-history-header,
.calc-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--ec-btn-func, #e8e8e8);
    color: var(--ec-text, #333);
    font-weight: bold;
    font-size: 14px;
}

.calc-history-clear,
.calc-dropdown-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 6px 8px;
    min-width: 36px;
    min-height: 36px;
    opacity: 0.7;
}

.calc-history-clear:hover,
.calc-dropdown-close:hover { opacity: 1; }

.calc-history-list {
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.calc-history-empty {
    color: var(--ec-text, #888);
    opacity: 0.6;
    font-size: 14px;
    padding: 20px;
    text-align: center;
}

.calc-history-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.calc-history-item:hover {
    background: var(--ec-btn-func, #f0f0f0);
    border-color: rgba(0,0,0,.1);
}

.calc-history-item:active { filter: brightness(0.95); }

.calc-history-expr {
    font-size: 13px;
    color: var(--ec-text, #333);
    word-break: break-all;
}

.calc-history-result {
    font-size: 12px;
    color: var(--ec-accent, #2196F3);
    margin-top: 2px;
}

.calc-help-content {
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ec-text, #333);
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.calc-help-content p { margin: 0 0 10px; }
.calc-help-content p:last-child { margin-bottom: 0; }
.calc-help-content ul { margin: 0 0 10px; padding-left: 18px; }
.calc-help-content li { margin-bottom: 4px; }
.calc-help-content code {
    background: var(--ec-btn-func, #eee);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

.units-toggle { margin-bottom: 15px; text-align: left; }

.switch {
    position: relative;
    display: inline-block;
    width: 120px;
    height: 34px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--ec-toggle-deg, #2196F3);
    border-radius: 17px;
    transition: .4s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    color: white;
    font-weight: bold;
    font-size: 14px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transition: .4s;
    backdrop-filter: blur(2px);
}

input:checked + .slider { background-color: var(--ec-toggle-rad, #4CAF50); }

input:checked + .slider:before {
    transform: translateX(86px);
    background-color: rgba(255, 255, 255, 0.3);
}

.deg, .rad { z-index: 1; transition: opacity 0.3s; }
.deg { opacity: 1; }
.rad { opacity: 0.7; }
input:checked + .slider .deg { opacity: 0.7; }
input:checked + .slider .rad { opacity: 1; }

.buttons table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.buttons td { padding: 4px; }

.buttons button {
    width: 100%;
    min-height: 48px;
    height: 50px;
    font-size: clamp(14px, 4vw, 18px);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--ec-btn-num, #ffffff);
    color: var(--ec-text, #333333);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

.buttons button:hover { filter: brightness(0.92); }
.buttons button:active { transform: scale(0.95); }
.buttons .func { background: var(--ec-btn-func, #d0d0d0); }
.buttons .num  { background: var(--ec-btn-num, #ffffff); }

.buttons .clear {
    background: var(--ec-btn-clear, #ff4444);
    color: white;
}
.buttons .clear:hover { filter: brightness(0.85); }

.buttons .constant { background: var(--ec-btn-const, #87ceeb); }
.buttons .constant:hover { filter: brightness(0.9); }

.buttons .equals { background: var(--ec-btn-equal, #90ee90); }
.buttons .equals:hover { filter: brightness(0.9); }

/* ── Адаптив ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .engineering-calculator-container {
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    .engineering-calculator { padding: 16px; border-radius: 12px; }
    #engineering-result { height: 54px; min-height: 44px; font-size: clamp(16px, 4.5vw, 20px); padding: 0 12px; }
    .calc-header-row { gap: 8px; margin-bottom: 12px; }
    .calc-header-row .switch { height: 44px; min-height: 44px; }
    .calc-header-row .calc-dropdown-btn { min-width: 44px; min-height: 44px; width: 44px; height: 44px; }
    .calc-history-panel, .calc-help-panel { max-width: min(300px, calc(100vw - 24px)); max-height: min(260px, 45vh); }
    .calc-history-item { padding: 12px; min-height: 44px; }
    .buttons td { padding: 3px; }
    .buttons button { min-height: 44px; height: 48px; font-size: clamp(13px, 3.5vw, 16px); }
    .switch { width: 100px; }
    .slider { font-size: 12px; padding: 0 12px; border-radius: 22px; }
    .slider:before { height: 24px; width: 24px; bottom: 10px; }
    input:checked + .slider:before { transform: translateX(66px); }
}

@media (max-width: 480px) {
    .engineering-calculator-container {
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }
    .engineering-calculator { padding: 12px; border-radius: 10px; }
    #engineering-result { height: 48px; min-height: 44px; font-size: 16px; padding: 0 10px; }
    .display { margin-bottom: 12px; }
    .calc-header-row { gap: 6px; margin-bottom: 10px; }
    .calc-header-row .switch { height: 44px; min-height: 44px; }
    .calc-header-row .calc-dropdown-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
    .calc-history-panel, .calc-help-panel { left: auto; right: 0; max-width: calc(100vw - 16px); max-height: 40vh; }
    .calc-history-header, .calc-help-header { padding: 8px 10px; font-size: 13px; }
    .calc-history-list { max-height: 180px; }
    .calc-history-item { padding: 10px; }
    .calc-history-expr { font-size: 12px; }
    .calc-history-result { font-size: 11px; }
    .calc-help-content { font-size: 12px; padding: 10px 12px; }
    .buttons td { padding: 2px; }
    .buttons button { min-height: 44px; height: 44px; font-size: 13px; }
    .switch { width: 90px; }
    .slider { font-size: 11px; padding: 0 10px; border-radius: 22px; }
    .slider:before { height: 22px; width: 22px; bottom: 11px; }
    input:checked + .slider:before { transform: translateX(56px); }
}

@media (max-width: 360px) {
    .engineering-calculator { padding: 10px; }
    .buttons button { font-size: 12px; }
    .switch { width: 80px; }
    .slider:before { height: 20px; width: 20px; bottom: 12px; }
    input:checked + .slider:before { transform: translateX(50px); }
}
