@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;700&display=swap');

:root {
    --bg: #f3f6f4;
    --panel: #ffffff;
    --ink: #1c2b24;
    --muted: #5f7268;
    --line: #d7e0db;
    --primary: #0f766e;
    --primary-dark: #0b5c56;
    --accent: #c2410c;
    --ok: #166534;
    --ok-bg: #dcfce7;
    --err: #991b1b;
    --err-bg: #fee2e2;
    --warn: #92400e;
    --warn-bg: #ffedd5;
    --open: #1e40af;
    --open-bg: #dbeafe;
    --shadow: 0 10px 30px rgba(28, 43, 36, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Vazirmatn", Tahoma, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, #d9f3ee 0%, transparent 40%),
        radial-gradient(circle at 90% 10%, #ffe8d6 0%, transparent 35%),
        var(--bg);
    min-height: 100vh;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary-dark);
    text-decoration: none;
}

.topbar nav { display: flex; gap: .4rem; flex-wrap: wrap; }

.topbar a {
    text-decoration: none;
    color: var(--muted);
    padding: .45rem .8rem;
    border-radius: 999px;
}

.topbar a.active,
.topbar nav a:hover {
    background: #e7f5f2;
    color: var(--primary-dark);
}

.container {
    width: min(1500px, calc(100% - 2rem));
    margin: 1.5rem auto 2rem;
    flex: 1;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1.25rem 1.4rem 1.6rem;
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

h1 { margin: 0 0 .4rem; font-size: 1.4rem; }
h2 { margin: 1.6rem 0 .7rem; font-size: 1.1rem; }
.muted { color: var(--muted); margin-top: 0; }

.form label {
    display: block;
    margin-bottom: 1rem;
}

.form label span,
.inline {
    display: block;
    margin-bottom: .35rem;
    color: var(--muted);
    font-size: .92rem;
}

.inline { display: flex; flex-direction: column; gap: .35rem; }

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .7rem .85rem;
    font: inherit;
    background: #fbfcfb;
    color: var(--ink);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(15, 118, 110, .25);
    border-color: var(--primary);
    background: #fff;
}

.grid-2, .grid-3 {
    display: grid;
    gap: 1rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .4rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    border-radius: 12px;
    padding: .65rem 1rem;
    font: inherit;
    cursor: pointer;
}

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

.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }

.btn.danger {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.btn.danger:hover { background: #991b1b; }

.link-danger { color: #b91c1c !important; }

.receipt-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: block;
}

.receipt-link { display: inline-block; }

.inline-form { display: inline; margin: 0; }

.btn-sm {
    padding: .35rem .65rem;
    border-radius: 10px;
    font-size: .85rem;
}

.row-unconfirmed td { background: #fffaf0; }
.row-confirmed td { background: transparent; }

.id-cell {
    display: flex;
    align-items: center;
    gap: .55rem;
    white-space: nowrap;
}

.row-id { font-weight: 600; color: var(--muted); }

.toggle {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 999px;
    transition: .2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    right: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(-18px);
}

.toggle input:disabled + .toggle-slider {
    opacity: .6;
    cursor: wait;
}

.danger-panel {
    border-color: #fecaca;
    box-shadow: 0 10px 30px rgba(185, 28, 28, 0.08);
}

.filters {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.filters input, .filters select { min-width: 180px; width: auto; flex: 1; }

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.count-line { margin: .25rem 0 0; font-size: .9rem; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}

th, td {
    border-bottom: 1px solid var(--line);
    padding: .55rem .5rem;
    text-align: right;
    vertical-align: top;
}

th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.small { font-size: .85rem; color: var(--muted); }
.nowrap { white-space: nowrap; }
.ids-cell { max-width: 280px; word-break: break-all; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; }
.actions-cell { white-space: nowrap; }
.actions-cell a { margin-left: .5rem; color: var(--primary-dark); }

.alert {
    border-radius: 12px;
    padding: .85rem 1rem;
    margin-bottom: 1rem;
}

.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--err-bg); color: var(--err); }

.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
}

.badge-open { background: var(--open-bg); color: var(--open); }
.badge-partial { background: var(--warn-bg); color: var(--warn); }
.badge-paid { background: var(--ok-bg); color: var(--ok); }

.meta-box {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .7rem 1rem;
    background: #f7faf8;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem;
    margin: 1rem 0 1.4rem;
}

.meta-box .full { grid-column: 1 / -1; }

.stats, .stats.secondary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .8rem;
    margin: 1rem 0;
}

.stats article {
    background: linear-gradient(180deg, #f8fffd, #f3faf7);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem;
}

.stats.secondary article {
    background: #fffaf5;
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: .85rem;
    margin-bottom: .4rem;
}

.stats strong {
    font-size: 1.05rem;
}

.hint {
    display: block;
    margin-top: .35rem;
    color: var(--primary-dark);
    min-height: 1.2em;
}

.hint.miss { color: var(--muted); }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin: 1.2rem 0;
}

.chart-card {
    background: #fbfdfe;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1rem 1.1rem 1.2rem;
}

.chart-card.wide { grid-column: 1 / -1; }

.chart-card h2 {
    margin: 0 0 .8rem;
    font-size: 1rem;
}

.chart-box {
    position: relative;
    height: 280px;
}

.chart-box.tall { height: 340px; }

.jalali-date {
    direction: ltr;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.export-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .55rem .9rem;
    margin: 0 0 1.1rem;
    padding: .75rem 1rem;
    background: #f3faf7;
    border: 1px dashed var(--line);
    border-radius: 12px;
    color: var(--muted);
    font-size: .92rem;
}

.export-bar a {
    color: var(--primary-dark);
    text-decoration: none;
    font-weight: 500;
}

.export-bar a:hover { text-decoration: underline; }

table tfoot th {
    background: #f3faf7;
    font-weight: 700;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 1rem;
    font-size: .85rem;
}

.nav-logout { color: #b91c1c !important; }

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100dvh - 2rem);
    max-width: 440px;
}

.login-panel h1 { margin-bottom: .35rem; }

.public-topbar {
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    text-align: center;
}

.public-subtitle {
    color: var(--muted);
    font-size: .92rem;
}

.public-app .container {
    padding-bottom: 1rem;
}

.public-app {
    padding-bottom: 0;
}

.share-head {
    align-items: flex-start;
}

.view-toggle {
    display: inline-flex;
    gap: .35rem;
    background: #f3faf7;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .25rem;
}

.view-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: .9rem;
    padding: .5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    min-height: 40px;
}

.view-btn.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.public-app[data-view="table"] .view-cards { display: none !important; }
.public-app[data-view="table"] .view-table { display: block; }
.public-app[data-view="cards"] .view-table { display: none !important; }
.public-app[data-view="cards"] .view-cards { display: grid; }

.share-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.share-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    min-width: 860px;
}

.share-table th,
.share-table td {
    border-bottom: 1px solid var(--line);
    padding: .65rem .55rem;
    text-align: right;
    vertical-align: top;
}

.share-table th {
    background: #f7faf8;
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.share-table tr.row-open td {
    background: #eff6ff;
}

.share-table tr.row-paid:hover td,
.share-table tr.row-open:hover td {
    background: #f3faf7;
}

.m-card-open {
    border-color: #93c5fd;
    background: linear-gradient(180deg, #f8fbff, #fff);
}

.share-person-panel {
    margin-top: 1rem;
}

.share-person-panel h2 {
    margin: 0 0 .25rem;
    font-size: 1.2rem;
}

.share-subtitle {
    margin: 1.2rem 0 .7rem;
    font-size: 1.05rem;
}

.share-chart-card {
    margin: 1rem 0 1.2rem;
}

.share-chart-card h3 {
    margin: 0 0 .75rem;
    font-size: 1rem;
}

.share-range-form {
    margin-bottom: 1rem;
}

.share-person-table {
    min-width: 520px;
}

.card-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: .85rem;
}

@media (min-width: 900px) {
    .card-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

.bottom-nav { display: none; }
.empty-card {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem;
    border: 1px dashed var(--line);
    border-radius: 14px;
    grid-column: 1 / -1;
}

.ltr, .ltr-input {
    direction: ltr;
    text-align: left;
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    flex: 1;
    min-width: 220px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: .55rem .9rem;
    cursor: pointer;
    color: var(--muted);
    font-size: .9rem;
    user-select: none;
}

.chip input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.chip.active,
.chip:has(input:checked) {
    background: #e7f5f2;
    border-color: #9fd0c7;
    color: var(--primary-dark);
    font-weight: 600;
}

.m-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1rem;
    margin-bottom: .85rem;
    box-shadow: 0 4px 14px rgba(28, 43, 36, 0.05);
}

.m-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: .55rem;
}

.m-card-id {
    font-size: .8rem;
    color: var(--muted);
    font-weight: 600;
}

.m-card-title {
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1.35;
}

.m-card-amount {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin: .35rem 0 .25rem;
    font-variant-numeric: tabular-nums;
}

.m-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem .75rem;
    color: var(--muted);
    font-size: .86rem;
    margin-bottom: .55rem;
}

.m-card-ids {
    background: #f7faf8;
    border-radius: 12px;
    padding: .65rem .75rem;
    margin-bottom: .75rem;
    word-break: break-word;
}

.m-card-ids div + div { margin-top: .25rem; }

.m-card-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .45rem;
}

.m-card-actions .btn { width: 100%; min-height: 42px; }

@media (max-width: 900px) {
    .grid-2, .grid-3, .meta-box, .stats, .stats.secondary, .chart-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    body {
        -webkit-tap-highlight-color: transparent;
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    .app { min-height: 100dvh; }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: .65rem;
        padding: .75rem 1rem;
        padding-top: calc(.75rem + env(safe-area-inset-top, 0px));
    }

    .brand {
        font-size: 1.05rem;
        text-align: center;
    }

    .top-nav {
        display: none !important;
    }

    .bottom-nav {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 50;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--line);
        padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -8px 24px rgba(28, 43, 36, 0.08);
    }

    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: .15rem;
        text-decoration: none;
        color: var(--muted);
        font-size: .72rem;
        font-weight: 500;
        padding: .45rem .2rem;
        border-radius: 12px;
        min-height: 52px;
    }

    .bottom-nav a.active {
        color: var(--primary-dark);
        background: #e7f5f2;
    }

    .bn-icon {
        font-size: 1.15rem;
        line-height: 1;
    }

    .container {
        width: calc(100% - 1rem);
        margin: .75rem auto 1rem;
    }

    .panel {
        border-radius: 14px;
        padding: 1rem;
        box-shadow: none;
    }

    .panel-head {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }

    h1 { font-size: 1.2rem; }

    .btn-block-mobile,
    .panel-head .btn.primary {
        width: 100%;
        min-height: 48px;
    }

    .filters {
        flex-direction: column;
        gap: .55rem;
    }

    .filters input,
    .filters select,
    .filters .btn,
    .filters .inline {
        min-width: 0;
        width: 100%;
        flex: none;
    }

    .filters .btn,
    .actions .btn,
    .form .btn {
        min-height: 46px;
    }

    input, select, textarea {
        font-size: 16px; /* جلوگیری از زوم iOS */
        min-height: 46px;
        border-radius: 14px;
    }

    textarea { min-height: 110px; }

    .grid-2, .grid-3, .meta-box, .stats, .stats.secondary, .chart-grid {
        grid-template-columns: 1fr;
    }

    .chart-card.wide { grid-column: auto; }
    .chart-box, .chart-box.tall { height: 240px; }

    .card-list {
        grid-template-columns: 1fr;
    }

    .filter-chips {
        width: 100%;
        min-width: 0;
    }

    .chip {
        flex: 1;
        justify-content: center;
        min-height: 44px;
    }

    .export-bar {
        gap: .5rem;
        font-size: .86rem;
    }

    .export-bar a {
        display: inline-block;
        padding: .35rem .55rem;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 999px;
    }

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

    .actions .btn { width: 100%; }

    .footer {
        padding-bottom: .5rem;
        font-size: .78rem;
    }

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

    .m-card-actions .btn.danger,
    .m-card-actions a:nth-child(3) {
        grid-column: 1 / -1;
    }
}

@media (max-width: 380px) {
    .m-card-amount { font-size: 1.05rem; }
    .bottom-nav a { font-size: .68rem; }
}
