:root {
    --green-700: #337321;
    --green-600: #43A047;
    --green-500: #4CAF50;
    --green-400: #4BAE50;
    --green-300: #87BF67;
    --green-200: #8DC26F;
    --green-100: #CFF3CF;
    --green-50: #76b852;
    --text: #1f2933;
    --muted: #667085;
    --surface: #ffffff;
    --border: #d7e8d7;
    --shadow: 0 18px 40px rgba(31, 41, 51, 0.12);
    --radius: 18px;
    --touch-min: 48px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html, body {
    margin: 0;
    min-height: 100dvh;
    font-family: "Roboto", sans-serif;
    color: var(--text);
    background: linear-gradient(145deg, var(--green-50), var(--green-200));
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

button,
a,
input,
select {
    -webkit-tap-highlight-color: rgba(76, 175, 80, 0.2);
}

button,
.btn,
.action-item,
.card-action,
.message-card,
.nav-btn {
    touch-action: manipulation;
}

.app-shell {
    width: min(100%, 420px);
    max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
    background: rgba(255, 255, 255, 0.96);
    border-radius: calc(var(--radius) + 6px);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-header {
    padding: calc(20px + var(--safe-top)) 24px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    gap: 12px;
}

.logo {
    width: 180px;
    max-width: 70%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.user-badge {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--muted);
    background: #f4faf4;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 10px;
}

.app-content {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 24px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.app-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px 24px calc(16px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: #fafdfa;
}

.nav-btn {
    border: 0;
    border-radius: 12px;
    min-height: var(--touch-min);
    padding: 12px 10px;
    background: var(--green-500);
    color: #fff;
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
}

.nav-btn:hover,
.nav-btn:focus-visible {
    background: var(--green-600);
}

.nav-btn-danger {
    background: #fff;
    color: var(--green-700);
    border: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

.loader {
    text-align: center;
    color: var(--green-50);
    padding: 32px 0;
}

.loader-bar {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    border-radius: 50%;
    border: 4px solid #dff3df;
    border-top-color: var(--green-500);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.stack-form,
.fragment {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    font: inherit;
    font-size: 16px;
    background: #fff;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    border: 0;
    border-radius: 12px;
    min-height: var(--touch-min);
    padding: 12px 16px;
    font: inherit;
    font-size: 16px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.btn-primary {
    background: var(--green-500);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background: var(--green-600);
}

.btn-secondary {
    background: #eef8ee;
    color: var(--green-700);
    border: 1px solid var(--border);
}

.hint {
    font-size: 14px;
    color: var(--muted);
    line-height: 1.5;
}

.hint a {
    color: var(--green-700);
    font-weight: 500;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 24px 12px;
}

.card-grid {
    display: grid;
    gap: 10px;
}

.card,
.card-action {
    text-align: left;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 14px;
    padding: 16px;
    width: 100%;
}

.card-action {
    min-height: var(--touch-min);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.card-action:hover,
.card-action:focus-visible {
    background: var(--green-100);
    border-color: var(--green-300);
    transform: translateY(-1px);
}

.card-title {
    display: block;
    font-weight: 700;
    color: var(--green-700);
}

.card-sub {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-top: 4px;
}

.card-messages {
    margin-top: 16px;
}

.section-head h2,
.section-head p {
    margin: 0 0 8px;
}

.section-head.compact h2 {
    font-size: clamp(18px, 4.5vw, 20px);
    color: var(--green-700);
}

.action-list {
    display: grid;
    gap: 10px;
}

.action-item {
    border: 0;
    border-radius: 14px;
    min-height: var(--touch-min);
    padding: 14px 16px;
    background: var(--green-500);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 13px;
    text-decoration: none;
    text-align: center;
}

.action-item:hover,
.action-item:focus-visible {
    background: var(--green-700);
}

.info-card,
.highlight-card {
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 8px;
}

.info-card {
    border: 1px solid var(--border);
    background: #fff;
}

.info-card small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.highlight-card {
    background: var(--green-500);
    color: #fff;
    margin-top: 16px;
}

.section-label {
    font-weight: 700;
    color: var(--green-700);
    margin: 16px 0 8px;
}

.message-list {
    display: grid;
    gap: 10px;
}

.message-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    min-height: var(--touch-min);
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    text-align: left;
    cursor: pointer;
}

.message-card:hover,
.message-card:focus-visible {
    background: var(--green-100);
    border-color: var(--green-300);
}

.message-card-top {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

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

.message-subject {
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
}

.message-badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 4px 8px;
}

.message-badge.is-new {
    background: #fff4e5;
    color: #b54708;
}

.message-badge.is-read {
    background: #ecfdf3;
    color: var(--green-700);
}

.message-table-desktop {
    display: none;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}

.data-table thead {
    background: #f4faf4;
}

.row-link {
    cursor: pointer;
}

.row-link:hover {
    background: var(--green-100);
}

.plain-list {
    padding-left: 18px;
}

.message-body {
    overflow-wrap: anywhere;
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--touch-min);
}

.checkbox-line input {
    width: 20px;
    height: 20px;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + var(--safe-bottom));
    transform: translateX(-50%);
    background: #1f2933;
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: min(92vw, 420px);
    z-index: 20;
}

.toast.error {
    background: #b42318;
}

.toast.success {
    background: var(--green-700);
}

.error-fragment h2 {
    color: var(--green-700);
}

@media (min-width: 768px) {
    .app-shell {
        width: min(100%, 400px);
    }

    .message-list {
        display: none;
    }

    .message-table-desktop {
        display: block;
    }
}

@media (max-width: 420px) {
    body {
        align-items: stretch;
        padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
    }

    .app-shell {
        width: 100%;
        max-height: none;
        min-height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom));
        border-radius: 16px;
    }

    .app-header,
    .app-content,
    .app-nav {
        padding-left: 16px;
        padding-right: 16px;
    }

    .app-nav {
        padding-bottom: calc(12px + var(--safe-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
