/* Палитра — та же, что в WpfCalc.Android/Pages/Palette.cs. Тема переключается атрибутом data-theme у <html>. */
:root {
    --bg: #1E1E1E;
    --panel: #121212;
    --button: #2A2A2A;
    --operation: #333C47;
    --operation-text: #4DA3FF;
    --accent: #4DA3FF;
    --danger: #FF5C5C;
    --muted: #888888;
    --text: #FFFFFF;
    --text-soft: #F5F5F5;
    --divider: #333333;
    --card-stroke: #2A2A2A;
    --display-stroke: #222222;
    --notification: #2A6F4D;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #F2F4F7;
    --panel: #FFFFFF;
    --button: #E3E7EC;
    --operation: #DCE7F5;
    --operation-text: #1F6FD1;
    --accent: #2D8CF0;
    --danger: #D32F2F;
    --muted: #6B7280;
    --text: #1B1F24;
    --text-soft: #20262D;
    --divider: #C8CED6;
    --card-stroke: #CBD2DA;
    --display-stroke: #D7DCE2;
    color-scheme: light;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* --app-height задаёт js/app.js: установленное на iPhone приложение получает от Safari высоту окна
   меньше экрана на высоту строки состояния, и без поправки внизу остаётся пустая полоса */
html, body {
    height: var(--app-height, 100%);
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    /* приложение, а не документ: без выделения текста и меню по долгому нажатию */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

/* Строка состояния iOS (black-translucent) всегда с белым текстом — в светлой теме подкладываем тёмную полосу */
:root[data-theme="light"] body::before {
    content: "";
    position: fixed;
    inset: 0 0 auto 0;
    height: env(safe-area-inset-top);
    background: #1E1E1E;
    z-index: 30;
}

#app {
    height: 100%;
}

button, input, select {
    font: inherit;
    color: inherit;
}

a {
    color: var(--operation-text);
    font-size: 13px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

/* --- Калькулятор ----------------------------------------------------------------------- */

.calc {
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: var(--app-height, 100dvh);
    max-width: 480px;
    margin: 0 auto;
    padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
}

.display {
    position: relative;
    flex: 0 0 112px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--display-stroke);
    border-radius: 12px;
    overflow: hidden;
}

.display-text {
    font-weight: bold;
    line-height: 1.28;
    text-align: right;
    white-space: pre;
}

.display-foot {
    position: absolute;
    inset: auto 12px 6px 12px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.memory-mark {
    font-size: 13px;
    font-weight: bold;
    color: var(--operation-text);
}

.tax-info {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toast {
    position: absolute;
    top: 8px;
    left: 12px;
    max-width: calc(100% - 24px);
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--notification);
    color: #FFFFFF;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 1;
}

.key {
    min-width: 0;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: var(--button);
    color: var(--text);
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
}

.key:active {
    filter: brightness(1.25);
}

:root[data-theme="light"] .key:active {
    filter: brightness(0.9);
}

.key:disabled {
    opacity: 0.45;
}

.key.op {
    background: var(--operation);
    color: var(--operation-text);
}

.key.accent {
    background: var(--accent);
    color: #FFFFFF;
    font-size: 26px;
}

.key.danger {
    color: var(--danger);
}

.key.small {
    height: 40px;
    font-size: 12px;
}

.key.small.accent {
    font-size: 14px;
}

.row {
    flex: 0 0 auto;
    display: grid;
    gap: 4px;
}

.memory-row {
    grid-template-columns: 1fr 1fr 1fr 1fr 1.5fr;
}

.tax-row {
    grid-template-columns: repeat(6, 1fr);
}

.keypad {
    flex: 1 0 300px;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 4px;
}

.key.tall {
    grid-row: span 2;
}

.key.wide {
    grid-column: span 2;
}

/* --- История и настройки ----------------------------------------------------------------- */

.panel-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding-top: 4px;
    border-top: 1px solid var(--divider);
}

.panel-title {
    flex: 1;
    font-size: 14px;
    font-weight: bold;
    color: var(--muted);
    line-height: 36px;
    cursor: pointer;
}

.icon-button {
    width: 42px;
    height: 36px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
}

.panel-content {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.panel-content.history {
    flex: 0 1 26dvh;
}

.panel-content.settings {
    flex: 0 1 42dvh;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-empty {
    margin: 12px 4px;
    color: var(--muted);
    font-size: 12px;
}

.history-hint {
    margin: 0 4px 4px;
    color: var(--muted);
    font-size: 10px;
}

.history-row {
    display: grid;
    grid-template-columns: 1fr auto;
    padding: 4px;
    border-bottom: 1px solid color-mix(in srgb, var(--divider) 50%, transparent);
}

.history-expression {
    align-self: center;
    font-size: 12px;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.history-result {
    grid-column: span 2;
    color: var(--text-soft);
    font-size: 16px;
    font-weight: bold;
    text-align: right;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.history-pin {
    padding: 4px 12px;
    border: none;
    background: transparent;
    font-size: 15px;
    opacity: 0.3;
    cursor: pointer;
}

.history-pin.pinned {
    opacity: 1;
}

.card {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--card-stroke);
    border-radius: 8px;
}

.card-title {
    font-size: 14px;
    font-weight: bold;
}

/* поля ввода — не меньше 16px, иначе Safari на iPhone увеличивает страницу при фокусе */
.rate-input {
    width: 100%;
    padding: 6px;
    border: none;
    border-bottom: 1px solid var(--divider);
    background: transparent;
    font-size: 18px;
    text-align: center;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}

.presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
}

.setting-row select {
    min-width: 120px;
    padding: 6px 8px;
    border: 1px solid var(--card-stroke);
    border-radius: 8px;
    background: var(--button);
    font-size: 16px;
}

.switch {
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
}

/* --- Диалоги ----------------------------------------------------------------------------- */

.overlay {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--app-height, 100%);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    background: rgba(0, 0, 0, 0.5);
    z-index: 20;
}

.sheet {
    width: 100%;
    max-width: 456px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    border: 1px solid var(--card-stroke);
    border-radius: 14px;
    background: var(--bg);
}

.sheet-title {
    font-size: 16px;
    font-weight: bold;
}

.sheet .key.small {
    height: 44px;
    font-size: 14px;
}

.sheet-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 4px;
}

/* --- Конвертер валют ----------------------------------------------------------------------- */

.currency {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--app-height, 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: calc(24px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    background: var(--bg);
    overflow-y: auto;
    z-index: 10;
}

.currency > * {
    width: 100%;
    max-width: 448px;
    margin: 0 auto;
}

.currency-title {
    font-size: 20px;
    font-weight: bold;
}

.field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.field-label {
    font-size: 12px;
    color: var(--muted);
}

.field-input {
    width: 100%;
    min-width: 0;
    padding: 8px 2px;
    border: none;
    border-bottom: 1px solid var(--divider);
    border-radius: 0;
    background: transparent;
    font-size: 20px;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}

select.field-input {
    font-size: 16px;
    background: var(--bg);
}

.currency-pair {
    display: grid;
    grid-template-columns: 1fr 48px 1fr;
    align-items: end;
    gap: 8px;
}

.key.small.swap {
    height: 44px;
    font-size: 18px;
}

.currency-result {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--card-stroke);
    border-radius: 10px;
    background: var(--panel);
}

.currency-value {
    min-height: 34px;
    font-size: 26px;
    font-weight: bold;
    overflow-wrap: anywhere;
    -webkit-user-select: text;
    user-select: text;
}

.status {
    min-height: 16px;
    font-size: 12px;
    color: var(--muted);
}

.status.error {
    color: var(--danger);
}

.currency-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.currency-buttons .key.small {
    height: 44px;
    font-size: 14px;
}

/* --- Загрузка и ошибки Blazor --------------------------------------------------------------- */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #1B1F24;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom)) 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--button);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Загрузка");
}
