/* ===== Тема (адаптация под Telegram + брендовый зелёный) ===== */
:root {
    --bg-color: var(--tg-theme-bg-color, #f5f7fa);
    --card-bg: var(--tg-theme-secondary-bg-color, #ffffff);
    --green-main: #2e9b4e;
    --green-light: var(--tg-theme-secondary-bg-color, #e8f5e9);
    --green-hover: #268a40;
    --text-main: var(--tg-theme-text-color, #1d2129);
    --text-secondary: var(--tg-theme-hint-color, #86909c);
    --border-color: var(--tg-theme-section-separator-color, #e5e6eb);
    --red-warn: #ff3b30;
}

@media (prefers-color-scheme: dark) {
    :root {
        --green-light: rgba(46, 155, 78, 0.15);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    padding-bottom: 30px;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s, color 0.2s;
}

/* ===== Container ===== */
.container {
    padding: 0 16px;
}

/* ===== Hero ===== */
.hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    gap: 16px;
}
.hero-text h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1.2;
}
.hero-text p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
}
.hero-illustration .doc-icon {
    font-size: 44px;
    background: var(--green-light);
    padding: 16px;
    border-radius: 18px;
    transform: rotate(-5deg);
}

/* ===== Doc Types ===== */
.doc-types {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}
.type-card {
    background: var(--card-bg);
    padding: 10px 6px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 2px solid transparent;
    transition: all 0.15s;
    cursor: pointer;
    user-select: none;
}
@media (hover: hover) {
    .type-card:hover {
        border-color: var(--green-main);
        transform: translateY(-1px);
    }
}
.type-card:active {
    transform: scale(0.97);
}
.type-card.selected {
    border-color: var(--green-main);
    background: var(--green-light);
}
.icon-box {
    font-size: 22px;
    margin-bottom: 4px;
    line-height: 1;
}
.icon-box-check {
    background: var(--green-main);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
}
.type-card span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    display: block;
}
.type-card.selected span {
    color: var(--green-main);
    font-weight: 600;
}

/* ===== Form Card ===== */
.form-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}
.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 14px;
}
.card-header .icon {
    font-size: 20px;
    margin-right: 10px;
}
.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

/* ===== Banner ===== */
.banner {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 12px;
    margin-bottom: 12px;
    line-height: 1.4;
}
.banner-info {
    background: rgba(46, 155, 78, 0.1);
    color: var(--green-main);
}
.banner-success {
    background: var(--green-light);
    color: var(--green-main);
    font-weight: 500;
}
.banner-warn {
    background: rgba(255, 149, 0, 0.12);
    color: #b86e00;
}

/* ===== Inputs ===== */
.input-group {
    margin-bottom: 12px;
}
.input-group:last-child {
    margin-bottom: 0;
}
.input-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}
.input-group label .hint {
    font-weight: 400;
    opacity: 0.8;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

input, select {
    width: 100%;
    padding: 11px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    font-size: 14px;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s, background 0.15s;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}
input:focus, select:focus {
    border-color: var(--green-main);
}
input[readonly] {
    background: var(--green-light);
    color: var(--text-secondary);
    border-color: transparent;
    cursor: default;
}
input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2386909c'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 30px;
}
input[type="date"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2386909c' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ===== Services Table ===== */
.service-row {
    display: grid;
    grid-template-columns: 2fr 0.8fr 1fr 1fr 1.1fr 36px;
    gap: 5px;
    margin-bottom: 8px;
    align-items: center;
}
.service-row input,
.service-row select {
    padding: 9px 8px;
    font-size: 13px;
}
.btn-remove {
    background: var(--red-warn);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: opacity 0.15s;
}
.btn-remove:active {
    opacity: 0.7;
}

.btn-add {
    background: transparent;
    color: var(--green-main);
    border: 1.5px dashed var(--green-main);
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    margin-top: 4px;
    transition: background 0.15s;
}
.btn-add:active {
    background: var(--green-light);
}

/* === Secondary button (Сохранить) === */
.btn-secondary {
    background: var(--card-bg);
    color: var(--green-main);
    border: 1.5px solid var(--green-main);
    width: 100%;
    padding: 11px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    margin-top: 12px;
    transition: background 0.15s;
}
.btn-secondary:active {
    background: var(--green-light);
}
.btn-secondary.saved {
    background: var(--green-main);
    color: white;
}

/* === Link button (text-only, no border) === */
.btn-link {
    background: transparent;
    color: var(--green-main);
    border: none;
    width: 100%;
    padding: 8px;
    margin-top: 6px;
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    text-align: center;
}
.btn-link:active {
    opacity: 0.6;
}

/* === Collapsible details === */
.collapsible {
    margin-bottom: 10px;
}
.collapsible summary {
    padding: 10px 12px;
    background: var(--bg-color);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    color: var(--text-secondary);
    list-style: none;
    user-select: none;
    transition: background 0.15s;
}
.collapsible summary::-webkit-details-marker {
    display: none;
}
.collapsible summary::before {
    content: "▶";
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.2s;
    font-size: 10px;
}
.collapsible[open] summary::before {
    transform: rotate(90deg);
}
.collapsible[open] summary {
    background: var(--green-light);
    color: var(--green-main);
    margin-bottom: 12px;
}
.collapsible summary:active {
    opacity: 0.7;
}

.total-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 16px;
}
#totalSum {
    color: var(--green-main);
    font-size: 18px;
    font-weight: 700;
}

/* ===== Submit ===== */
.submit-btn {
    width: 100%;
    padding: 16px;
    background: var(--green-main);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
    margin: 8px 0 20px 0;
    box-shadow: 0 4px 14px rgba(46, 155, 78, 0.25);
}
@media (hover: hover) {
    .submit-btn:not(:disabled):hover {
        background: var(--green-hover);
        transform: translateY(-1px);
    }
}
.submit-btn:active:not(:disabled) {
    transform: scale(0.98);
}
.submit-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none;
}
.submit-btn.loading {
    background: var(--text-secondary);
    pointer-events: none;
}
.submit-btn.loading .btn-text::after {
    content: "...";
    animation: dots 1s steps(3) infinite;
}
@keyframes dots {
    0%, 33% { content: ""; }
    34%, 66% { content: "."; }
    67%, 100% { content: ".."; }
}
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.plus-icon {
    font-size: 18px;
}

.spacer {
    height: 10px;
}

/* ===== Responsive: маленькие экраны ===== */
@media (max-width: 380px) {
    .service-row {
        grid-template-columns: 1.8fr 0.7fr 0.9fr 0.9fr 1fr 32px;
        gap: 4px;
    }
    .service-row input,
    .service-row select {
        padding: 8px 6px;
        font-size: 12px;
    }
    .hero-text h2 {
        font-size: 19px;
    }
    .type-card {
        padding: 8px 4px;
    }
    .type-card span {
        font-size: 10px;
    }
}

/* === Radio group (срок оплаты) === */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}
.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--tg-theme-hint-color, #e0e0e0);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    background: var(--tg-theme-secondary-bg-color, #f8f8f8);
}
.radio-option:hover {
    background: var(--tg-theme-bg-color, #fff);
    border-color: var(--tg-theme-button-color, #3390ec);
}
.radio-option input[type="radio"] {
    margin: 0;
    accent-color: var(--tg-theme-button-color, #3390ec);
}
.radio-option input[type="radio"]:checked + span {
    font-weight: 600;
    color: var(--tg-theme-button-color, #3390ec);
}