:root {
    color-scheme: light dark;
    --bg: var(--theme-bg, light-dark(#f0f4f1, #101814));
    --paper: var(--theme-paper, light-dark(#fff, #18211e));
    --ink: var(--theme-ink, light-dark(#14261d, #eff7f1));
    --muted: var(--theme-muted, light-dark(#52665a, #b0c4b8));
    --line: var(--theme-line, light-dark(#d4ded7, #3d5147));
    --accent: var(--theme-accent, light-dark(#1f5b3a, #a9e5bb));
    --tint: var(--theme-bg, light-dark(#dcefe1, #223e30));
    --primary: var(--theme-primary, light-dark(#205c3c, #afe6bf));
    --on-primary: var(--theme-on-primary, light-dark(#fff, #14251b));
}
:root[data-telegram-scheme="light"] { color-scheme: light; }
:root[data-telegram-scheme="dark"] { color-scheme: dark; }
:root[data-telegram-scheme] {
    --theme-bg: var(--tg-theme-secondary-bg-color);
    --theme-paper: var(--tg-theme-bg-color);
    --theme-ink: var(--tg-theme-text-color);
    --theme-muted: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color));
    --theme-line: var(--tg-theme-section-separator-color);
    --theme-accent: var(--tg-theme-link-color);
    --theme-primary: var(--tg-theme-button-color);
    --theme-on-primary: var(--tg-theme-button-text-color);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1rem/1.5 system-ui, sans-serif; }
main { max-width: 780px; margin: 0 auto; padding: clamp(14px, 5vw, 36px); }
header { border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
header a { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); }
h1 { font-size: clamp(1.6rem, 5vw, 2.3rem); letter-spacing: -.04em; margin: 0; }
h2, h3, p { margin: 0 0 .65rem; }
#rights, .hint { color: var(--muted); font-size: .91rem; }
#rights:empty, #feedback:empty { margin: 0; }
#feedback:not(:empty) { padding: .75rem; background: var(--paper); border-left: 4px solid var(--accent); border-radius: 8px; }
#orders, #card { display: grid; gap: .5rem; margin-top: .75rem; }
.panel, .order, .action { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.panel, .order { padding: .8rem .9rem; }
.order { display: flex; justify-content: space-between; align-items: center; gap: .75rem; text-align: left; color: var(--ink); }
.order-unread { background: var(--tint); border-radius: 1rem; padding: .1rem .55rem; font-variant-numeric: tabular-nums; }
.order-summary, .order-info { overflow-wrap: anywhere; }
.order-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .35rem .75rem; }
.order-heading h2 { margin: 0; font-size: 1.25rem; letter-spacing: -.025em; }
.order-status { margin: 0; padding: .15rem .55rem; border-radius: .5rem; background: var(--tint); font-size: .875rem; font-weight: 650; }
.order-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: .65rem 0 0; }
.order-totals dt { color: var(--muted); font-size: .875rem; }
.order-totals dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.order-info h3 { margin-bottom: .25rem; font-size: .95rem; }
.order-info ul { margin: 0 0 .65rem; padding-inline-start: 1.3rem; }
.order-info > :last-child { margin-bottom: 0; }
.action > summary {
    position: relative; min-height: 44px; padding: .625rem 2.5rem .625rem .9rem;
    border-radius: inherit; list-style: none; cursor: pointer; font-weight: 650;
}
.action > summary::-webkit-details-marker { display: none; }
.action > summary::after {
    content: ""; position: absolute; top: 50%; right: 1rem; width: .5rem; height: .5rem;
    border: solid var(--accent); border-width: 0 2px 2px 0; transform: translateY(-70%) rotate(45deg);
}
.action[open] { border-color: var(--accent); }
.action[open] > summary::after { transform: translateY(-30%) rotate(225deg); }
.action form { border-top: 1px solid var(--line); padding: .75rem .9rem; }
.row, nav { display: flex; gap: .6rem; align-items: end; }
nav { margin-top: .8rem; }
.row > input { flex: 1; }
form { display: grid; gap: .55rem; }
label { display: block; font-weight: 600; }
input, textarea, select, button {
    min-width: 0; max-width: 100%; min-height: 44px; padding: .55rem .75rem;
    border-radius: 9px; font: inherit;
}
input, textarea, select { width: 100%; color: var(--ink); background: var(--paper); border: 1px solid var(--line); }
textarea { resize: vertical; min-height: 85px; }
button { cursor: pointer; color: var(--on-primary); background: var(--primary); border: 1px solid transparent; font-weight: 650; }
button:disabled { opacity: .55; cursor: wait; }
.secondary { background: var(--paper); color: var(--accent); border-color: var(--line); }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.mail-entry { margin-top: .65rem; }
body.mail-open { overflow: hidden; }
html:has(.mail-open) { overflow: hidden; }
#mail {
    --mail-safe-top: max(env(safe-area-inset-top), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
    --mail-safe-bottom: max(env(safe-area-inset-bottom), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
    --mail-safe-left: max(env(safe-area-inset-left), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
    --mail-safe-right: max(env(safe-area-inset-right), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)));
    --mail-height: min(var(--mail-visible-height, 100dvh), var(--tg-viewport-stable-height, 100dvh));
    position: fixed; inset-inline: 0; top: var(--mail-top, 0px); height: var(--mail-height);
    max-width: 780px; margin-inline: auto; padding: var(--mail-safe-top)
        var(--mail-safe-right) var(--mail-safe-bottom) var(--mail-safe-left);
    display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto;
    background: var(--bg); overflow-wrap: anywhere;
}
.mail-header {
    margin: 0; padding: 4px 8px; display: grid; grid-template-columns: auto auto minmax(44px, 1fr);
    align-items: center; gap: 6px; background: var(--paper);
}
.mail-header h2 { margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mail-recipient { text-align: left; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.mail-history { position: relative; display: grid; grid-template-rows: minmax(0, 1fr); }
#mail :is(button, input, select, textarea, a) { min-width: 44px; }
#mail-contacts {
    position: absolute; z-index: 1; inset: 0 8px auto; max-height: 100%;
    overflow-y: auto; overscroll-behavior: contain; padding: 10px;
    background: var(--paper); border: 1px solid var(--line); border-radius: 9px;
}
#mail-contacts form, #mail-contacts form + button { margin-top: 8px; }
.mail-log { position: relative; overflow: auto; overscroll-behavior: contain; overflow-anchor: none; padding: 8px; }
.mail-message { padding: 8px 10px; margin-bottom: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
.mail-message:last-child, .mail-message > :last-child { margin-bottom: 0; }
.mail-file, .mail-selected-file, .mail-compose-row { display: flex; gap: 6px; align-items: center; min-width: 0; }
.mail-file a { display: inline-flex; align-items: center; flex-shrink: 0; min-height: 44px; padding-inline: 8px; }
.mail-preview {
    position: relative; display: grid; place-items: center; width: min(100%, 160px); height: 104px; padding: 0;
    margin-block: 4px; overflow: hidden; background: var(--tint);
}
.mail-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#mail-feedback { max-height: 4.5rem; overflow: auto; background: var(--paper); }
#mail-feedback:not(:empty) { padding: 4px 8px; border-top: 1px solid var(--line); }
.mail-composer { gap: 4px; padding: 4px 8px; border-top: 1px solid var(--line); background: var(--paper); }
.mail-addressing { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.mail-selections { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.mail-compose-row { align-items: end; }
.mail-compose-row button, .mail-selected-file button {
    flex: 0 0 44px; width: 44px; height: 44px; padding: 0; font-size: 1.25rem;
}
.mail-compose-row textarea {
    flex: 1; min-height: 44px; max-height: clamp(44px, calc(var(--mail-height) - 190px), min(22dvh, 9rem));
    padding: 9px; resize: none; line-height: 24px;
}
.mail-selected-file span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mail-viewer {
    position: fixed; inset: var(--mail-top, 0px) 0 auto; width: 100%; max-width: 780px;
    height: var(--mail-height); max-height: none; margin: 0 auto; border: 0;
    padding: var(--mail-safe-top) calc(8px + var(--mail-safe-right))
        var(--mail-safe-bottom) calc(8px + var(--mail-safe-left));
    color: var(--ink); background: var(--bg);
}
.mail-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.mail-viewer-toolbar { display: flex; justify-content: space-between; gap: 6px; padding-block: 4px; }
.mail-photo-frame { min-height: 0; overflow: auto; display: flex; }
.mail-photo-frame img { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; }
.mail-photo-zoom img { max-width: none; max-height: none; width: 200%; height: auto; align-self: flex-start; flex: none; margin: 0; }
