/* سامانهٔ فیش حقوقی — استایل اصلی (RTL، سبک و چاپ‌پذیر) */

:root {
    --ink: #1f2933;
    --muted: #5f6c7b;
    --line: #d6dde5;
    --bg: #f4f6f8;
    --card: #ffffff;
    --accent: #1f6f5c;
    --accent-soft: #e8f3ef;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Tahoma, "Segoe UI", "IRANSans", sans-serif;
    font-size: 14px;
    line-height: 1.7;
}

.wrap {
    max-width: 1040px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

/* ---------- ورود ---------- */

.login-box {
    max-width: 420px;
    margin: 8vh auto 0;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 28px;
    box-shadow: 0 6px 24px rgba(31, 41, 51, .06);
}

.login-box h1 {
    margin: 0 0 8px;
    font-size: 18px;
    text-align: center;
}

.login-box .lead {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

/* ---------- فرم‌ها ---------- */

label {
    display: block;
    margin: 12px 0 4px;
    font-size: 13px;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
}

input:focus, select:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

button, .btn {
    display: inline-block;
    margin-top: 16px;
    padding: 9px 18px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
}

button:hover, .btn:hover { filter: brightness(1.08); }

.btn.ghost {
    background: transparent;
    color: var(--accent);
}

.btn.ghost:hover { background: var(--accent-soft); }

.card {
    max-width: 420px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 22px;
}

/* ---------- پیام‌ها ---------- */

.alert {
    margin: 16px 0;
    padding: 10px 14px;
    border-radius: 6px;
    border: 1px solid #e3b4b4;
    background: #fdf1f1;
    color: #8a2b2b;
    font-size: 13px;
}

.alert.ok {
    border-color: #b6dcc8;
    background: #f0faf5;
    color: #1c6b4a;
}

.center { text-align: center; }

/* ---------- نوار بالا و انتخاب دوره ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.topbar .who { font-weight: 700; }
.topbar .actions .btn { margin-top: 0; margin-inline-start: 8px; }

.picker {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.picker label { margin: 0; }
.picker select { width: auto; min-width: 120px; }

/* ---------- فیش ---------- */

.sheet {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 22px;
}

.sheet-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    border-top: 3px solid var(--accent);
    border-bottom: 1px solid #e6e9ee;
    padding: 10px 0 10px;
    margin-bottom: 16px;
}

.sheet-head .head-main { text-align: center; flex: 1; }
.sheet-head .org { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.sheet-head .sub { font-size: 13px; color: var(--muted); }

.sheet-head .head-side {
    min-width: 120px;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    background: #f7fbf9;
}

.sheet-head .head-side span { display: block; font-size: 11px; color: var(--muted); }
.sheet-head .head-side strong { font-size: 14px; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}
.toolbar .btn { margin: 0; }

table.grid {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
    font-size: 13px;
}

table.grid th,
table.grid td {
    border: 1px solid #e9edf1;
    padding: 7px 9px;
    text-align: right;
    vertical-align: middle;
}

table.grid th {
    background: #f7f9fb;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

table.grid td.wide { font-weight: 600; }

table.grid tbody tr:nth-child(even) td { background: #fcfdfe; }

table.grid .c-code { width: 70px; text-align: center; }
table.grid .c-num { width: 150px; text-align: left; direction: ltr; }

table.grid tfoot .total th,
table.grid tfoot .total td {
    background: #f2f6f4;
    font-weight: 700;
}

table.grid tfoot .net td,
table.grid tfoot .net th {
    background: var(--accent-soft);
    font-weight: 700;
}

.net-text { line-height: 1.8; flex: 1; }
.note { color: var(--muted); font-weight: 400; font-size: 12px; }

.net-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-soft);
    padding: 12px 16px;
    font-size: 13px;
}

.net-amount { text-align: center; min-width: 190px; }
.net-amount span { display: block; font-size: 11px; color: var(--muted); }
.net-amount strong { font-size: 18px; direction: ltr; display: block; }

.empty { text-align: center; color: var(--muted); }

/* کادرهای امضا — فقط در نسخهٔ چاپی */
.signatures {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 18px;
}

.sign {
    border: 1px solid var(--line);
    border-radius: 6px;
    height: 78px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
    font-size: 11px;
    color: var(--muted);
    background: #fcfdfe;
}

.print-foot {
    margin-top: 10px;
    font-size: 10px;
    color: var(--muted);
    text-align: center;
}

/* نوار ابزار صفحهٔ چاپ */
.print-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
}
.print-tools .btn { margin: 0; }
.print-tools .hint { color: var(--muted); font-size: 12px; }

/* ---------- پابرگ ---------- */

.foot {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 16px 28px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

/* ---------- چاپ / PDF: A4 عمودی با حاشیه ---------- */

@page {
    size: A4 portrait;
    margin: 8mm;
}

body.print {
    background: #fff;
    font-size: 12px;
}

body.print .wrap {
    max-width: none;
    padding: 0;
    margin: 0;
}

body.print .sheet {
    border: 0;
    border-radius: 0;
    /*
     * حاشیهٔ داخلی، نه فقط @page:
     * اگر کاربر در پنجرهٔ چاپ «Margins: None» را انتخاب کند، مرورگر حاشیهٔ
     * @page را حذف می‌کند و متن به لبهٔ کاغذ می‌چسبد. این padding تضمین می‌کند
     * در هر حالت فاصله از کناره‌ها حفظ شود.
     */
    padding: 8mm;
    font-size: 10px;
    line-height: 1.55;
}

body.print .sheet-head {
    border-top: 3px solid #1f6f5c;
    border-bottom: 1px solid #e6e9ee;
    padding: 7px 0 6px;
    margin-bottom: 9px;
}

body.print .sheet-head .org { font-size: 14px; letter-spacing: .3px; }
body.print .sheet-head .sub { font-size: 10px; }
body.print .sheet-head .head-side { background: #fff; border-color: #e6e9ee; padding: 3px 9px; min-width: 88px; }
body.print .sheet-head .head-side span { font-size: 8.5px; }
body.print .sheet-head .head-side strong { font-size: 11px; }

body.print table.grid {
    font-size: 9.5px;
    margin-bottom: 7px;
    border-collapse: separate;
    border-spacing: 0;
}

body.print table.grid th,
body.print table.grid td {
    padding: 2.4px 6px;
    border: 0;
    border-bottom: 1px solid #edf0f3;
    line-height: 1.5;
}

body.print table.grid th {
    background: #fff;
    color: #6b7280;
    font-weight: 600;
}

body.print table.grid {
    border-top: 1px solid #e6e9ee;
    border-bottom: 1px solid #e6e9ee;
}

body.print table.grid th { white-space: nowrap; }
body.print table.grid .c-num { width: 104px; }
body.print table.grid .c-code { width: 44px; }

body.print table.grid thead { display: table-header-group; }
body.print table.grid thead th { border-bottom: 1px solid #dfe3e8; }
body.print table.grid tr { page-break-inside: avoid; }
body.print table.grid tbody tr:nth-child(even) td { background: #fff; }

body.print table.grid tfoot .total th,
body.print table.grid tfoot .total td {
    background: #f7f9fb;
    border-top: 1px solid #dfe3e8;
    border-bottom: 0;
}

body.print .net-box {
    padding: 7px 12px;
    font-size: 9.5px;
    border: 1px solid #e6e9ee;
    background: #fbfcfd;
    border-radius: 4px;
}
body.print .net-amount { min-width: 150px; }
body.print .net-amount span { font-size: 8.5px; }
body.print .net-amount strong { font-size: 13px; }

body.print .signatures { margin-top: 12px; gap: 8px; }
body.print .sign {
    height: 46px;
    font-size: 9px;
    border-style: dashed;
    border-color: #d8dde3;
    background: #fff;
}
body.print .print-foot { font-size: 8.5px; margin-top: 6px; color: #9aa3ad; }

/* فیش‌های پرردیف (بیش از ۲۴ ردیف) باز هم فشرده‌تر */
body.print .sheet.compact table.grid th,
body.print .sheet.compact table.grid td { padding: 1.4px 5px; font-size: 9px; line-height: 1.4; }
body.print .sheet.compact table.grid { margin-bottom: 6px; }
body.print .sheet.compact .sign { height: 38px; }
body.print .sheet.compact .signatures { margin-top: 8px; }
body.print .sheet.compact .net-box { padding: 5px 10px; }
body.print .sheet.compact .print-foot { display: none; }

@media print {
    .no-print,
    .topbar,
    .picker,
    .toolbar,
    .print-tools,
    .foot { display: none !important; }

    html, body {
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* اگر کاربر از خود صفحهٔ فیش هم چاپ بگیرد، همین چیدمان اعمال شود */
    .sheet {
        border: 0 !important;
        border-radius: 0 !important;
        padding: 8mm !important;
        font-size: 10px;
        line-height: 1.55;
    }

    .sheet-head {
        border-top: 3px solid #1f6f5c !important;
        border-bottom: 1px solid #e6e9ee !important;
        padding: 7px 0 6px !important;
        margin-bottom: 9px !important;
    }

    table.grid {
        font-size: 9.5px;
        margin-bottom: 7px;
        border-collapse: separate;
        border-spacing: 0;
        border-top: 1px solid #e6e9ee;
        border-bottom: 1px solid #e6e9ee;
    }

    table.grid th,
    table.grid td {
        padding: 2.4px 6px;
        border: 0;
        border-bottom: 1px solid #edf0f3;
        line-height: 1.5;
    }

    table.grid th { background: #fff; color: #6b7280; font-weight: 600; }
    table.grid thead { display: table-header-group; }
    table.grid thead th { border-bottom: 1px solid #dfe3e8; }
    table.grid tr { page-break-inside: avoid; }

    .sheet.compact table.grid th,
    .sheet.compact table.grid td { padding: 1.4px 5px; font-size: 9px; }
}
