/* ==========================================================
   MOBILE CALC — Apple-style калькуляторы
   Гибрид: плотные карточки iOS + мягкие тени + моноширинные цифры
   ========================================================== */

/* ==================================================== */
/* БАЗОВЫЕ ПЕРЕМЕННЫЕ ДЛЯ КАЛЬКУЛЯТОРОВ                  */
/* ==================================================== */
body.mobile-device {
    --calc-radius: 14px;
    --calc-radius-sm: 10px;
    --calc-radius-lg: 18px;
    --calc-font-num: 'SF Mono', 'Consolas', 'Roboto Mono', 'Menlo', monospace;
    --calc-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --calc-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* ==================================================== */
/* КОМПАКТНЫЕ ПОЛЯ                                       */
/* ==================================================== */
.calc-row {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}

.calc-row-2 {
    grid-template-columns: 1fr 1fr;
}

.calc-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.calc-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.calc-field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.2px;
    line-height: 1.3;
    padding-left: 2px;
}

.calc-field-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.calc-field-input-wrap input,
.calc-field-input-wrap select {
    width: 100%;
    height: 52px;
    padding: 0 16px;
    padding-right: 48px;
    font-size: 17px;
    font-weight: 600;
    font-family: var(--calc-font-num);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: var(--text-main);
    background: var(--bg-color);
    border: 1.5px solid transparent;
    border-radius: var(--calc-radius-sm);
    outline: none;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.calc-field-input-wrap input:focus,
.calc-field-input-wrap select:focus {
    border-color: var(--primary);
    background: var(--card-bg);
}

.calc-field-unit {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
    font-family: var(--calc-font-num);
}

.calc-field-input-wrap select {
    padding-right: 44px;
    font-family: inherit;
    font-weight: 600;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%2386868b" height="20" viewBox="0 0 24 24" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 14px center;
}

/* ==================================================== */
/* TOGGLE (М400/М500) — iOS-style segmented             */
/* ==================================================== */
.calc-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    padding: 3px;
    background: var(--bg-color);
    border-radius: var(--calc-radius-sm);
    border: none;
}

.calc-toggle button {
    height: 46px;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        color 0.2s ease,
        box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.calc-toggle button.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.calc-toggle button:active:not(.active) {
    background: rgba(120, 120, 128, 0.08);
}

body.dark-theme .calc-toggle button.active {
    background: #2c2c2e;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 0 0.5px rgba(255, 255, 255, 0.06);
}

/* ==================================================== */
/* ЭЛЕМЕНТЫ (5 кнопок в строку) — iOS-grid              */
/* ==================================================== */
.calc-elements {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.calc-element-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 2px;
    min-height: 70px;
    background: var(--bg-color);
    border: 1.5px solid transparent;
    border-radius: var(--calc-radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-tap-highlight-color: transparent;
}

.calc-element-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.calc-element-btn span {
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.calc-element-btn.active {
    background: var(--primary-light);
    color: var(--primary);
}

.calc-element-btn.active svg {
    transform: scale(1.08);
}

.calc-element-btn:active {
    transform: scale(0.96);
}

body.dark-theme .calc-element-btn.active {
    background: rgba(0, 113, 227, 0.22);
    color: #4a9eff;
}

/* ==================================================== */
/* ФОРМУЛА                                               */
/* ==================================================== */
.calc-formula {
    padding: 12px 14px;
    background: var(--bg-color);
    border-radius: var(--calc-radius-sm);
    font-size: 13px;
    font-family: var(--calc-font-num);
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 12px;
}

.calc-formula strong {
    color: var(--text-main);
    font-weight: 700;
}

/* ==================================================== */
/* ЗАГОЛОВОК СЕКЦИИ — iOS-style                          */
/* ==================================================== */
.calc-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin: 18px 0 10px 2px;
}

.calc-section-title:first-child {
    margin-top: 4px;
}

/* ==================================================== */
/* РАСХОД НА 1 м³ — плотная карточка iOS               */
/* ==================================================== */
.calc-per-m3 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    padding: 14px 16px;
    background: var(--bg-color);
    border-radius: var(--calc-radius);
    font-size: 14px;
    margin-bottom: 12px;
}

.calc-per-m3 .row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
    gap: 8px;
}

.calc-per-m3 .row span:first-child {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    font-weight: 500;
}

.calc-per-m3 .row span:last-child {
    font-weight: 700;
    font-family: var(--calc-font-num);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    white-space: nowrap;
    color: var(--text-main);
}

.calc-per-m3-footer {
    grid-column: 1 / -1;
    padding-top: 10px;
    margin-top: 2px;
    border-top: 1px solid rgba(120, 120, 128, 0.14);
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--calc-font-num);
}

.calc-per-m3-footer strong {
    color: var(--text-main);
    font-weight: 700;
}

body.dark-theme .calc-per-m3-footer {
    border-top-color: rgba(255, 255, 255, 0.1);
}

/* ==================================================== */
/* СПЕЦИФИКАЦИЯ — таблица iOS-style                     */
/* ==================================================== */
.calc-spec {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-bottom: 12px;
}

.calc-spec th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 8px 4px;
    border-bottom: 1px solid rgba(120, 120, 128, 0.18);
    white-space: nowrap;
}

body.dark-theme .calc-spec th {
    border-bottom-color: rgba(255, 255, 255, 0.12);
}

.calc-spec th.num {
    text-align: right;
}

.calc-spec td {
    padding: 12px 4px;
    border-bottom: 1px solid rgba(120, 120, 128, 0.1);
    font-family: var(--calc-font-num);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    color: var(--text-main);
    white-space: nowrap;
    font-weight: 600;
}

body.dark-theme .calc-spec td {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.calc-spec td.name {
    font-family: inherit;
    font-weight: 600;
    font-size: 14.5px;
}

.calc-spec td.num {
    text-align: right;
    font-weight: 700;
}

.calc-spec td.unit {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding-left: 6px;
    padding-right: 6px;
    font-family: inherit;
    text-align: center;
}

.calc-spec tr.total td {
    border-top: 2px solid rgba(120, 120, 128, 0.2);
    border-bottom: none;
    padding-top: 14px;
    padding-bottom: 4px;
    font-size: 16px;
    font-weight: 800;
}

body.dark-theme .calc-spec tr.total td {
    border-top-color: rgba(255, 255, 255, 0.15);
}

.calc-spec tr.total td.name {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
}

.calc-spec tr.total td.num {
    color: var(--primary);
    font-size: 18px;
    letter-spacing: -0.02em;
}

/* ==================================================== */
/* ВЛАЖНОСТЬ                                             */
/* ==================================================== */
.calc-moisture {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: rgba(0, 113, 227, 0.07);
    border-radius: var(--calc-radius);
    margin-bottom: 8px;
    font-size: 14px;
}

body.dark-theme .calc-moisture {
    background: rgba(0, 113, 227, 0.15);
}

.calc-moisture-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.calc-moisture-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.calc-moisture input {
    width: 56px;
    height: 40px;
    padding: 0 6px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    font-family: var(--calc-font-num);
    color: var(--text-main);
    background: var(--card-bg);
    border: 1.5px solid transparent;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s ease;
}

.calc-moisture input:focus {
    border-color: var(--primary);
}

.calc-moisture-sep {
    color: var(--text-muted);
    font-weight: 600;
}

.calc-moisture-result {
    padding: 8px 14px 10px 22px;
    font-size: 12.5px;
    font-family: var(--calc-font-num);
    color: var(--text-muted);
    line-height: 1.55;
}

.calc-moisture-result strong {
    color: var(--text-main);
    font-weight: 700;
}

/* ==================================================== */
/* СНОСКИ-ЧЕКМАРКИ                                       */
/* ==================================================== */
.calc-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.55;
    padding: 8px 2px 14px 2px;
}

.calc-notes .ok {
    color: #34c759;
    font-weight: 600;
}

.calc-notes .warn {
    color: #ff9500;
    font-weight: 600;
}

.calc-notes .info {
    color: var(--text-muted);
}

/* ==================================================== */
/* ИТОГ + КНОПКИ — iOS-card                             */
/* ==================================================== */
.calc-total-block {
    padding: 20px 18px 18px;
    background: var(--card-bg);
    border: 1px solid rgba(120, 120, 128, 0.14);
    border-radius: var(--calc-radius-lg);
    text-align: center;
    margin-top: 6px;
    box-shadow: var(--calc-shadow);
}

body.dark-theme .calc-total-block {
    background: #1c1c1e;
    border-color: rgba(255, 255, 255, 0.08);
}

.calc-total-value {
    font-size: 34px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.035em;
    line-height: 1.05;
    font-family: var(--calc-font-num);
    font-variant-numeric: tabular-nums;
}

.calc-total-currency {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 8px;
    font-family: var(--calc-font-num);
    letter-spacing: -0.01em;
}

.calc-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 16px;
}

.calc-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 54px;
    padding: 0 14px;
    border: none;
    border-radius: var(--calc-radius);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
        background 0.15s ease,
        box-shadow 0.2s ease;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.calc-action-btn svg {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.calc-action-btn.primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.28);
}

.calc-action-btn.primary:active {
    transform: scale(0.96);
    background: var(--primary-hover);
    box-shadow: 0 2px 6px rgba(0, 113, 227, 0.2);
}

.calc-action-btn.secondary {
    background: var(--bg-color);
    color: var(--primary);
}

body.dark-theme .calc-action-btn.secondary {
    background: #2c2c2e;
}

.calc-action-btn.secondary:active {
    transform: scale(0.96);
    background: rgba(0, 113, 227, 0.1);
}

/* ==================================================== */
/* BOTTOM SHEET «ОТПРАВИТЬ» — iOS-action-sheet style    */
/* ==================================================== */
.share-sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 8px;
    box-sizing: border-box;
}

.share-sheet-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.share-sheet {
    width: 100%;
    max-width: 440px;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 0;
    transform: translateY(20px) scale(0.97);
    opacity: 0;
    transition:
        transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
        opacity 0.3s ease;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: env(safe-area-inset-bottom, 0px);
}

body.dark-theme .share-sheet {
    background: #1c1c1e;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.7),
        0 4px 12px rgba(0, 0, 0, 0.4);
}

.share-sheet-overlay.open .share-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.share-sheet-handle {
    width: 36px;
    height: 5px;
    border-radius: 3px;
    background: rgba(120, 120, 128, 0.3);
    margin: 8px auto 0;
    flex-shrink: 0;
}

body.dark-theme .share-sheet-handle {
    background: rgba(255, 255, 255, 0.2);
}

.share-sheet-header {
    padding: 14px 20px 12px;
    text-align: center;
    border-bottom: 1px solid rgba(120, 120, 128, 0.16);
    flex-shrink: 0;
}

body.dark-theme .share-sheet-header {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.share-sheet-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
    letter-spacing: -0.01em;
    text-transform: none;
}

.share-sheet-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.75;
}

.share-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}

.share-sheet-group {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(120, 120, 128, 0.16);
}

body.dark-theme .share-sheet-group {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.share-sheet-group:last-child {
    border-bottom: none;
}

.share-sheet-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 6px 8px 4px;
    opacity: 0.7;
}

.share-option {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 10px 8px;
    background: transparent;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease;
}

.share-option:active {
    background: rgba(120, 120, 128, 0.1);
}

body.dark-theme .share-option:active {
    background: rgba(255, 255, 255, 0.06);
}

.share-option-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    line-height: 1;
    overflow: hidden;
}

.share-option-icon svg {
    width: 18px;
    height: 18px;
    stroke: #fff;
    fill: none;
    display: block;
}

.share-option-icon.app {
    background: linear-gradient(135deg, #0071e3, #0080ff);
}

.share-option-icon.wa {
    background: linear-gradient(135deg, #25D366, #1ebe5b);
}

.share-option-icon.tg {
    background: linear-gradient(135deg, #2AABEE, #229ED9);
}

.share-option-icon.viber {
    background: linear-gradient(135deg, #7360F2, #5E4FCC);
}

.share-option-icon.mail {
    background: linear-gradient(135deg, #EA4335, #c5221f);
}

.share-option-icon.copy {
    background: linear-gradient(135deg, #8e8e93, #636366);
}

.share-option-icon.pdf {
    background: linear-gradient(135deg, #FF3B30, #c92a20);
}

.share-option-icon.csv {
    background: linear-gradient(135deg, #34C759, #248A3D);
}

.share-option-icon.png {
    background: linear-gradient(135deg, #AF52DE, #7a3ba0);
}

.share-option-icon.link {
    background: linear-gradient(135deg, #0071e3, #004ba0);
}

.share-option-text {
    flex: 1;
    min-width: 0;
}

.share-option-text strong {
    display: block;
    font-size: 15px;
    font-weight: 400;
    color: var(--text-main);
    margin-bottom: 1px;
    letter-spacing: -0.01em;
}

.share-option-text small {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
    opacity: 0.75;
}

.share-sheet-close {
    margin: 8px 12px 8px;
    height: 52px;
    border-radius: 14px;
    background: var(--card-bg);
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    transition: background 0.12s ease;
    box-shadow: 0 -1px 0 rgba(120, 120, 128, 0.16);
}

.share-sheet-close:active {
    background: rgba(120, 120, 128, 0.1);
}

body.dark-theme .share-sheet-close {
    background: #2c2c2e;
    color: #f5f5f7;
    box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.08);
}

/* ==================================================== */
/* TOAST — iOS-style                                    */
/* ==================================================== */
.calc-toast {
    position: fixed;
    left: 50%;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(20px);
    background: rgba(28, 28, 30, 0.92);
    color: #fff;
    padding: 14px 22px;
    border-radius: 100px;
    font-size: 15px;
    font-weight: 600;
    z-index: 2147483647;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
    max-width: calc(100vw - 40px);
    letter-spacing: -0.01em;
}

.calc-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================================================== */
/* СКРЫТЫЙ КОНТЕЙНЕР ДЛЯ ЭКСПОРТА                       */
/* ==================================================== */
#calc-export-container {
    position: fixed;
    left: -99999px;
    top: 0;
    width: 800px;
    background: #fff;
    color: #000;
    padding: 0;
    box-sizing: border-box;
    font-family: Georgia, 'Times New Roman', serif;
}

/* ==================================================== */
/* АДАПТАЦИЯ ПОД УЗКИЕ ЭКРАНЫ                            */
/* ==================================================== */
@media (max-width: 360px) {
    .calc-row-3 {
        grid-template-columns: 1fr 1fr;
    }

    .calc-row-3 .calc-field:last-child {
        grid-column: 1 / -1;
    }

    .calc-element-btn {
        min-height: 64px;
        padding: 10px 2px;
    }

    .calc-element-btn svg {
        width: 20px;
        height: 20px;
    }

    .calc-element-btn span {
        font-size: 9px;
    }

    .calc-total-value {
        font-size: 28px;
    }

    .calc-actions {
        grid-template-columns: 1fr;
    }
}

/* ==================================================== */
/* АКЦЕНТ НА ПОЛЯХ КАЛЬКУЛЯТОРОВ (мобильная)            */
/* ==================================================== */
.calc-field-input-wrap input:focus,
.calc-field-input-wrap select:focus {
    border-color: var(--primary) !important;
    background-color: var(--card-bg) !important;
    box-shadow:
        0 0 0 4px rgba(0, 113, 227, 0.18),
        0 4px 14px rgba(0, 113, 227, 0.18) !important;
}

body.dark-theme .calc-field-input-wrap input:focus,
body.dark-theme .calc-field-input-wrap select:focus {
    background-color: #2c2c2e !important;
    box-shadow:
        0 0 0 4px rgba(0, 113, 227, 0.35),
        0 4px 14px rgba(0, 113, 227, 0.25) !important;
}

.calc-field-input-wrap input::placeholder {
    color: var(--primary);
    opacity: 0.45;
    font-weight: 600;
}

@keyframes fieldPulseMobile {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 113, 227, 0.4);
        border-color: rgba(0, 113, 227, 0.5);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(0, 113, 227, 0);
        border-color: rgba(0, 113, 227, 0.8);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 113, 227, 0);
        border-color: rgba(0, 113, 227, 0.3);
    }
}

.field-needs-input {
    animation: fieldPulseMobile 1.6s ease-out 2;
}

@media (prefers-reduced-motion: reduce) {
    .field-needs-input {
        animation: none !important;
    }
}

/* ==================================================== */
/* ЧАТЫ СООБЩЕСТВА — ФИНАЛЬНАЯ РАСКЛАДКА (mobile-calc)  */
/* ==================================================== */

/* Нижний док не нужен в чате */
body.mobile-device.chat-community-active .bottom-nav {
    display: none !important;
}

/* Основной контейнер приложения — не даём никаких лишних отступов */
body.mobile-device.chat-community-active .main-content {
    padding: 0 !important;
    margin: 0 !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
}

/* Секция чата = flex-колонка ровно на высоту вьюпорта минус шапка */
body.mobile-device.chat-community-active #market.section-content.active,
body.mobile-device.chat-community-active #properties.section-content.active,
body.mobile-device.chat-community-active #ratings.section-content.active {
    display: flex !important;
    flex-direction: column !important;
    height: calc(100dvh - 80px) !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 80px) !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    position: relative !important;
}

/* Обёртка чата — растягивается на всю секцию */
body.mobile-device.chat-community-active .community-chat-wrap {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: var(--card-bg) !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* Лента сообщений — растягивается и скроллится */
body.mobile-device.chat-community-active .community-chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 16px 14px !important;
    background: var(--bg-color) !important;
    box-sizing: border-box !important;
    order: 1 !important;
}

/* Поле ввода — прижато к низу, не улетает */
body.mobile-device.chat-community-active .community-chat-input-wrap {
    flex: 0 0 auto !important;
    margin: 0 !important;
    width: 100% !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) 12px !important;
    background: var(--card-bg) !important;
    border-top: 1px solid var(--hairline) !important;
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 5 !important;
    order: 2 !important;
}

/* Заглушка «нет доступа» — на всю ширину */
body.mobile-device.chat-community-active .community-chat-no-access {
    flex: 0 0 auto !important;
    order: 3 !important;
    width: 100% !important;
    padding: 20px !important;
    text-align: center !important;
    box-sizing: border-box !important;
}

/* Тёмная тема */
body.dark-theme.mobile-device.chat-community-active .community-chat-wrap {
    background: #1c1c1e !important;
}

body.dark-theme.mobile-device.chat-community-active .community-chat-messages {
    background: #000 !important;
}

body.dark-theme.mobile-device.chat-community-active .community-chat-input-wrap {
    background: #1c1c1e !important;
    border-top-color: rgba(255, 255, 255, 0.08) !important;
}

/* ==================================================== */
/* ЖЁСТКАЯ ФИКСАЦИЯ ПУЗЫРЕЙ — перебиваем всё, что мешает */
/* ==================================================== */

body.mobile-device.chat-community-active .community-chat-messages {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
}

body.mobile-device.chat-community-active .community-chat-msg {
    display: flex !important;
    align-items: flex-end !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ЧУЖИЕ сообщения — прижаты ВЛЕВО */
body.mobile-device.chat-community-active .community-chat-msg.their {
    flex-direction: row !important;
    justify-content: flex-start !important;
}

/* МОИ сообщения — прижаты ВПРАВО */
body.mobile-device.chat-community-active .community-chat-msg.mine {
    flex-direction: row-reverse !important;
    justify-content: flex-start !important;
}

body.mobile-device.chat-community-active .community-chat-msg.mine .community-chat-bubble {
    background: linear-gradient(135deg, #0071e3 0%, #0080ff 100%) !important;
    color: #ffffff !important;
}

body.mobile-device.chat-community-active .community-chat-msg.their .community-chat-bubble {
    background: var(--card-bg) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--hairline) !important;
}

body.mobile-device.chat-community-active .community-chat-bubble {
    max-width: 78% !important;
    min-width: 0 !important;
    flex-shrink: 1 !important;
    flex-grow: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 3px !important;
    padding: 10px 14px !important;
    border-radius: 18px !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

body.mobile-device.chat-community-active .community-chat-msg.their .community-chat-bubble {
    border-bottom-left-radius: 5px !important;
}

body.mobile-device.chat-community-active .community-chat-msg.mine .community-chat-bubble {
    border-bottom-right-radius: 5px !important;
}

body.mobile-device.chat-community-active .community-chat-avatar {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;
    flex-shrink: 0 !important;
}

body.mobile-device.chat-community-active .community-chat-author {
    font-size: 11.5px !important;
    font-weight: 700 !important;
    color: var(--primary) !important;
    margin-bottom: 2px !important;
}

body.mobile-device.chat-community-active .community-chat-msg.mine .community-chat-author {
    color: rgba(255, 255, 255, 0.85) !important;
    text-align: right !important;
}

body.mobile-device.chat-community-active .community-chat-text {
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    font-size: 14.5px !important;
    line-height: 1.45 !important;
}

body.mobile-device.chat-community-active .community-chat-meta {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
    font-size: 10.5px !important;
    opacity: 0.75 !important;
    margin-top: 3px !important;
}

body.mobile-device.chat-community-active .community-chat-msg.mine .community-chat-meta {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* ==================================================== */
/* ПРОСТОЕ ОБЪЯВЛЕНИЕ В ЧАТЕ — ВИЗУАЛЬНОЕ ВЫДЕЛЕНИЕ     */
/* ==================================================== */

.community-chat-msg.simple-ad-msg .community-chat-bubble {
    background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%) !important;
    border: 1.5px solid #ffcc00 !important;
    color: #1d1d1f !important;
    box-shadow: 0 4px 14px rgba(255, 149, 0, 0.22) !important;
    border-radius: 18px !important;
    padding: 14px 16px !important;
    max-width: 88% !important;
}

body.dark-theme .community-chat-msg.simple-ad-msg .community-chat-bubble {
    background: linear-gradient(135deg, #3a2e1a 0%, #2a2212 100%) !important;
    border-color: #ff9500 !important;
    color: #f5f5f7 !important;
    box-shadow: 0 4px 14px rgba(255, 149, 0, 0.35) !important;
}

.community-chat-msg.simple-ad-msg .community-chat-author {
    color: #ff9500 !important;
    font-size: 12.5px !important;
    font-weight: 800 !important;
    letter-spacing: 0.2px !important;
}

body.dark-theme .community-chat-msg.simple-ad-msg .community-chat-author {
    color: #ffb340 !important;
}

.community-chat-msg.simple-ad-msg .community-chat-text {
    white-space: pre-wrap !important;
    font-weight: 500 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
}

.community-chat-msg.simple-ad-msg .community-chat-meta {
    color: #86868b !important;
    opacity: 0.85 !important;
}

body.dark-theme .community-chat-msg.simple-ad-msg .community-chat-meta {
    color: #98989d !important;
}

/* Фото внутри объявления */
.community-chat-photo {
    margin: 8px 0 4px 0;
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.04);
}

body.dark-theme .community-chat-photo {
    background: rgba(255, 255, 255, 0.06);
}

.community-chat-photo img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 320px;
    object-fit: cover;
    border-radius: 12px;
}

/* Акцентная кнопка добавления расчёта в смету. */
.calc-action-btn[onclick*="openSaveToProjectSheet"] {
    background: linear-gradient(135deg, #0071e3, #1688ff);
    color: #fff;
    box-shadow: 0 6px 16px rgba(0, 113, 227, 0.26);
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.24s cubic-bezier(0.16, 1, 0.3, 1),
        filter 0.2s ease;
}

.calc-action-btn[onclick*="openSaveToProjectSheet"]:active {
    transform: scale(0.98);
    filter: brightness(0.96);
}

.calc-action-btn[onclick*="openSaveToProjectSheet"]:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
}

.calc-validation-message {
    display: block;
    margin-top: 6px;
    color: #d93025;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

.calc-input-invalid {
    border-color: #d93025 !important;
    box-shadow: 0 0 0 3px rgba(217, 48, 37, 0.12) !important;
}

@media (max-width: 430px) {
    body.mobile-device .calc-actions {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .calc-action-btn[onclick*="openSaveToProjectSheet"] {
        transition: none;
    }
}
