/* =========================================
   MyLife - Premium Persian RTL Dashboard
   Mobile First Improvements
   Compatible with PHP 7.4+
========================================= */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #0b1020;
    --bg-soft: #10172a;
    --panel: #151e32;
    --panel-hover: #1b2740;
    --border: rgba(255,255,255,.08);
    --text: #f3f6fc;
    --muted: #96a4bc;
    --primary: #8b7cff;
    --primary-light: #a99eff;
    --success: #35d39a;
    --danger: #ff7185;
    --warning: #ffc66d;
    --radius: 18px;
    --shadow: 0 14px 38px rgba(0,0,0,.18);
}

* {
    box-sizing: border-box;
}

html {
    direction: rtl;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at top right, rgba(91,75,180,.12), transparent 38%),
        var(--bg);
    color: var(--text);
    font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.8;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
input[type="submit"] {
    cursor: pointer;
}

button:disabled,
input[type="submit"]:disabled {
    cursor: not-allowed;
    opacity: .55;
}

img {
    max-width: 100%;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

/* =========================================
   Sidebar
========================================= */

.sidebar {
    width: 255px;
    min-width: 255px;
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    padding: 27px 17px;
    background: rgba(13,19,35,.96);
    border-left: 1px solid var(--border);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 30px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 14px;
    color: #fff;
    font-size: 23px;
    font-weight: 800;
    background: linear-gradient(135deg, #a69aff, #6553d9);
    box-shadow: 0 8px 22px rgba(122,104,255,.22);
}

.brand strong {
    display: block;
    font-size: 18px;
    letter-spacing: .2px;
}

.brand small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    margin-top: -2px;
}

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: 27px;
}

.main-nav a {
    display: flex;
    align-items: center;
    min-height: 46px;
    padding: 10px 15px;
    color: #aab5ca;
    border: 1px solid transparent;
    border-radius: 12px;
    transition: background .2s, color .2s, border-color .2s;
}

.main-nav a:hover,
.main-nav a.active {
    color: #fff;
    background: linear-gradient(100deg, rgba(139,124,255,.18), rgba(139,124,255,.05));
    border-color: rgba(139,124,255,.18);
}

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 13px;
    margin-top: auto;
    padding: 17px 10px 0;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.sidebar-bottom a {
    color: #ff9ba9;
}

.sidebar-bottom a:hover {
    color: #fff;
}

/* =========================================
   Main content
========================================= */

.main-content {
    flex: 1;
    min-width: 0;
    padding: 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 28px;
}

.topbar h1 {
    margin: 3px 0 0;
    font-size: 27px;
    font-weight: 800;
    line-height: 1.5;
}

.eyebrow {
    color: var(--primary-light);
    font-size: 12px;
    font-weight: 600;
}

.topbar-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-date {
    padding: 9px 15px;
    color: #c4cbe0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    white-space: nowrap;
    font-size: 12px;
}

/* =========================================
   Connection and synchronization status
========================================= */

.app-sync-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 6px 11px;
    color: #cbd5e8;
    background: rgba(21,30,50,.9);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 11px;
    white-space: nowrap;
}

.connection-dot {
    width: 8px;
    height: 8px;
    display: inline-block;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--warning);
}

.connection-dot.online {
    background: var(--success);
    box-shadow: 0 0 9px rgba(53,211,154,.5);
}

.connection-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 9px rgba(255,113,133,.4);
}

.queue-counter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    color: #d5ceff;
    background: rgba(139,124,255,.17);
    border: 1px solid rgba(139,124,255,.2);
    border-radius: 7px;
    font-size: 10px;
    font-weight: 800;
}

/* =========================================
   Cards and grids
========================================= */

.grid {
    display: grid;
    gap: 18px;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card {
    min-width: 0;
    padding: 23px;
    background: linear-gradient(145deg, rgba(24,34,56,.98), rgba(18,27,46,.98));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card + .card {
    margin-top: 18px;
}

.card-title {
    margin: 0 0 17px;
    font-size: 16px;
    font-weight: 700;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 23px;
    background: linear-gradient(145deg, #19243b, #131c30);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card:after {
    content: "";
    position: absolute;
    width: 95px;
    height: 95px;
    left: -25px;
    top: -28px;
    border-radius: 50%;
    background: rgba(139,124,255,.08);
    pointer-events: none;
}

.stat-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 9px;
}

.stat-value {
    display: block;
    font-size: clamp(20px, 2.2vw, 29px);
    line-height: 1.6;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.stat-note {
    display: block;
    color: var(--muted);
    font-size: 11px;
    margin-top: 8px;
}

.text-success {
    color: var(--success) !important;
}

.text-danger {
    color: var(--danger) !important;
}

.text-warning {
    color: var(--warning) !important;
}

.text-muted {
    color: var(--muted) !important;
}

/* =========================================
   Buttons
========================================= */

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    min-height: 42px;
    padding: 9px 17px;
    color: #fff;
    background: #28344c;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 11px;
    font-weight: 600;
    transition: transform .15s, filter .15s, background .15s;
}

.btn:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, #8e80ff, #6957e7);
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(115,96,238,.18);
}

.btn-success {
    color: #071d16;
    background: var(--success);
    border-color: transparent;
}

.btn-danger {
    color: #fff;
    background: #b83e56;
    border-color: transparent;
}

.btn-warning {
    color: #2a1a03;
    background: var(--warning);
    border-color: transparent;
}

.btn-outline {
    background: transparent;
    border-color: rgba(255,255,255,.16);
}

.btn-sm {
    min-height: 33px;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
}

.actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.page-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

/* =========================================
   Forms
========================================= */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    color: #d8deec;
    font-size: 12px;
    font-weight: 600;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 11px 13px;
    color: var(--text);
    background: #0f1729;
    border: 1px solid rgba(255,255,255,.11);
    border-radius: 10px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(139,124,255,.12);
}

input::placeholder,
textarea::placeholder {
    color: #71809a;
}

select {
    appearance: auto;
}

select option {
    color: #fff;
    background: #111a2d;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary);
}

.form-help {
    color: var(--muted);
    font-size: 11px;
}

.form-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

/* =========================================
   Tables
========================================= */

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 13px;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

thead {
    background: rgba(255,255,255,.035);
}

th,
td {
    padding: 14px 15px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    color: #b4bfd3;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

td {
    color: #e1e6f0;
    font-size: 12px;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: rgba(255,255,255,.018);
}

.table-empty {
    padding: 30px !important;
    text-align: center;
    color: var(--muted);
}

/* =========================================
   Badges
========================================= */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 7px;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-success {
    color: #66e5b7;
    background: rgba(53,211,154,.12);
}

.badge-danger {
    color: #ff98a7;
    background: rgba(255,113,133,.12);
}

.badge-warning {
    color: #ffd38a;
    background: rgba(255,198,109,.12);
}

.badge-primary {
    color: #bcb2ff;
    background: rgba(139,124,255,.14);
}

.badge-muted {
    color: #b0bad0;
    background: rgba(150,164,188,.12);
}

/* =========================================
   Alerts
========================================= */

.alert {
    margin-bottom: 20px;
    padding: 13px 16px;
    border: 1px solid transparent;
    border-radius: 11px;
    font-size: 12px;
}

.alert-success {
    color: #83ebc5;
    background: rgba(53,211,154,.09);
    border-color: rgba(53,211,154,.2);
}

.alert-error,
.alert-danger {
    color: #ffabb7;
    background: rgba(255,113,133,.09);
    border-color: rgba(255,113,133,.2);
}

.alert-warning {
    color: #ffda9a;
    background: rgba(255,198,109,.09);
    border-color: rgba(255,198,109,.2);
}

/* =========================================
   Filters
========================================= */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
    margin-bottom: 20px;
    padding: 17px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.filters .form-group {
    flex: 1;
    min-width: 145px;
}

.filters .btn {
    flex-shrink: 0;
}

/* =========================================
   Empty states
========================================= */

.empty-state {
    padding: 45px 20px;
    text-align: center;
    border: 1px dashed rgba(255,255,255,.13);
    border-radius: 14px;
}

.empty-state strong {
    display: block;
    font-size: 16px;
    margin-bottom: 7px;
}

.empty-state p {
    color: var(--muted);
    font-size: 12px;
    margin: 0 0 17px;
}

/* =========================================
   Login
========================================= */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(ellipse at top, rgba(139,124,255,.16), transparent 48%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 430px;
    padding: 34px;
    background: linear-gradient(145deg, #19243b, #121b2e);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: 0 25px 70px rgba(0,0,0,.3);
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand .brand-mark {
    width: 60px;
    height: 60px;
    margin: 0 auto 13px;
    font-size: 29px;
    border-radius: 18px;
}

.login-brand h1 {
    margin: 0;
    font-size: 24px;
}

.login-brand p {
    color: var(--muted);
    font-size: 12px;
    margin: 5px 0 0;
}

.login-card .form-group {
    margin-bottom: 17px;
}

/* =========================================
   Reports and print
========================================= */

.report-heading {
    margin-bottom: 20px;
}

.report-heading h2 {
    margin: 0 0 5px;
    font-size: 20px;
}

.report-heading p {
    color: var(--muted);
    margin: 0;
    font-size: 12px;
}

.print-only {
    display: none;
}

hr {
    height: 1px;
    border: 0;
    background: var(--border);
    margin: 23px 0;
}

.small {
    font-size: 11px;
}

.mt-1 {
    margin-top: 8px;
}

.mt-2 {
    margin-top: 16px;
}

.mb-2 {
    margin-bottom: 16px;
}

/* =========================================
   Mobile navigation
========================================= */

.mobile-bottom-nav {
    display: none;
}

.quick-add-button {
    display: none;
}

/* =========================================
   Tablet
========================================= */

@media (max-width: 1100px) {

    .sidebar {
        width: 220px;
        min-width: 220px;
    }

    .main-content {
        padding: 23px;
    }

    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* =========================================
   Mobile - Premium layout
========================================= */

@media (max-width: 760px) {

    html,
    body {
        min-height: 100%;
        overflow-x: hidden;
    }

    body {
        font-size: 13px;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-shell {
        display: block;
        min-height: 100vh;
    }

    /*
       Sidebar در موبایل به یک سربرگ کوچک تبدیل می‌شود.
       لینک‌ها و خروج از حساب در دسکتاپ باقی می‌مانند.
    */

    .sidebar {
        position: relative;
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 12px 15px;
        border-left: none;
        border-bottom: 1px solid var(--border);
        background: rgba(13,19,35,.98);
    }

    .brand {
        padding: 0;
        border-bottom: none;
        gap: 10px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        font-size: 20px;
    }

    .brand strong {
        font-size: 16px;
    }

    .brand small {
        font-size: 10px;
    }

    .main-nav {
        display: none;
    }

    .sidebar-bottom {
        display: none;
    }

    .main-content {
        width: 100%;
        min-width: 0;
        padding: 17px 13px calc(100px + env(safe-area-inset-bottom));
    }

    /* Header */

    .topbar {
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 19px;
    }

    .topbar h1 {
        font-size: 21px;
        line-height: 1.5;
        margin-top: 2px;
    }

    .eyebrow {
        font-size: 10px;
    }

    .topbar-tools {
        align-items: flex-end;
        flex-direction: column;
        gap: 6px;
    }

    .topbar-date {
        padding: 5px 9px;
        font-size: 10px;
        border-radius: 9px;
    }

    .app-sync-status {
        min-height: 30px;
        padding: 4px 8px;
        gap: 5px;
        font-size: 9px;
        border-radius: 9px;
    }

    .connection-dot {
        width: 7px;
        height: 7px;
    }

    .queue-counter {
        min-width: 19px;
        height: 19px;
        padding: 0 5px;
        font-size: 9px;
    }

    /* Cards */

    .grid {
        gap: 11px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .card {
        padding: 16px;
        border-radius: 15px;
    }

    .card + .card {
        margin-top: 13px;
    }

    .card-title {
        font-size: 14px;
        margin-bottom: 13px;
    }

    .stat-card {
        padding: 14px 12px;
        border-radius: 15px;
    }

    .stat-label {
        font-size: 10px;
        margin-bottom: 5px;
    }

    .stat-value {
        font-size: clamp(17px, 5vw, 23px);
        line-height: 1.5;
    }

    .stat-note {
        font-size: 9px;
        margin-top: 5px;
    }

    /* Forms */

    .form-grid {
        grid-template-columns: 1fr;
        gap: 13px;
    }

    .form-group.full {
        grid-column: auto;
    }

    .form-group {
        gap: 6px;
    }

    label {
        font-size: 11px;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
    select,
    textarea {
        min-height: 45px;
        padding: 10px 11px;
        font-size: 13px;
        border-radius: 10px;
    }

    textarea {
        min-height: 105px;
    }

    .form-footer {
        gap: 8px;
        margin-top: 17px;
    }

    .form-footer .btn {
        flex: 1;
    }

    /* Buttons */

    .btn {
        min-height: 40px;
        padding: 8px 12px;
        font-size: 12px;
    }

    .btn-sm {
        min-height: 32px;
        font-size: 10px;
    }

    .actions {
        gap: 6px;
    }

    .page-actions {
        align-items: stretch;
        gap: 10px;
        margin-bottom: 15px;
    }

    .page-actions .actions {
        width: 100%;
    }

    .page-actions .actions .btn {
        flex: 1;
    }

    /* Tables */

    .table-wrap {
        border-radius: 11px;
    }

    table {
        min-width: 570px;
    }

    th,
    td {
        padding: 11px 10px;
    }

    th {
        font-size: 10px;
    }

    td {
        font-size: 11px;
    }

    /* Filters */

    .filters {
        align-items: stretch;
        gap: 10px;
        padding: 13px;
    }

    .filters .form-group {
        min-width: 100%;
    }

    .filters .btn {
        width: 100%;
    }

    /* Alerts */

    .alert {
        padding: 11px 12px;
        font-size: 11px;
        margin-bottom: 14px;
    }

    /* Empty state */

    .empty-state {
        padding: 30px 15px;
    }

    .empty-state strong {
        font-size: 14px;
    }

    .empty-state p {
        font-size: 11px;
    }

    /* Login */

    .login-card {
        padding: 25px 19px;
        border-radius: 18px;
    }

    /* Bottom navigation */

    .mobile-bottom-nav {
        position: fixed;
        z-index: 1000;
        right: 0;
        left: 0;
        bottom: 0;

        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: stretch;

        min-height: 66px;
        padding: 7px 5px calc(7px + env(safe-area-inset-bottom));

        background: rgba(16,23,42,.97);
        border-top: 1px solid rgba(255,255,255,.09);
        box-shadow: 0 -8px 30px rgba(0,0,0,.25);

        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 1px;
        min-width: 0;
        color: #8492ab;
        border-radius: 11px;
        transition: color .2s, background .2s;
    }

    .mobile-bottom-nav a.active {
        color: #c2b9ff;
        background: rgba(139,124,255,.12);
    }

    .mobile-nav-icon {
        display: block;
        font-family: Tahoma, Arial, sans-serif;
        font-size: 21px;
        line-height: 1.25;
        font-weight: 700;
    }

    .mobile-nav-label {
        display: block;
        font-size: 9px;
        line-height: 1.5;
        font-weight: 600;
        white-space: nowrap;
    }

    /* Floating quick add button */

    .quick-add-button {
        position: fixed;
        z-index: 1001;
        left: 17px;
        bottom: calc(82px + env(safe-area-inset-bottom));

        width: 53px;
        height: 53px;

        display: flex;
        justify-content: center;
        align-items: center;

        color: #fff;
        background: linear-gradient(135deg, #a395ff, #6957e7);
        border: 1px solid rgba(255,255,255,.2);
        border-radius: 18px;

        font-family: Tahoma, Arial, sans-serif;
        font-size: 32px;
        font-weight: 400;
        line-height: 1;

        box-shadow: 0 8px 25px rgba(105,87,231,.38);
        transition: transform .2s, box-shadow .2s;
    }

    .quick-add-button:active {
        transform: scale(.93);
        box-shadow: 0 4px 14px rgba(105,87,231,.3);
    }

    /* Safe spacing */

    .report-heading h2 {
        font-size: 17px;
    }

    .report-heading p {
        font-size: 11px;
    }

    hr {
        margin: 17px 0;
    }
}

/* =========================================
   Small phones
========================================= */

@media (max-width: 380px) {

    .main-content {
        padding-right: 10px;
        padding-left: 10px;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .topbar-tools {
        gap: 4px;
    }

    .app-sync-status {
        font-size: 8px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 13px;
    }

    .mobile-nav-label {
        font-size: 8px;
    }

    .mobile-nav-icon {
        font-size: 19px;
    }

    .quick-add-button {
        width: 49px;
        height: 49px;
        left: 13px;
    }
}

/* =========================================
   Print
========================================= */

@media print {

    :root {
        --bg: #fff;
        --text: #111;
        --muted: #555;
        --border: #ddd;
    }

    body {
        background: #fff !important;
        color: #111 !important;
        font-family: Tahoma, Arial, sans-serif;
        font-size: 11px;
        padding: 0;
    }

    .sidebar,
    .topbar-date,
    .app-sync-status,
    .mobile-bottom-nav,
    .quick-add-button,
    .no-print,
    .btn,
    .filters {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .main-content {
        padding: 0;
        width: 100%;
    }

    .topbar {
        margin-bottom: 15px;
    }

    .topbar h1 {
        color: #111;
        font-size: 20px;
    }

    .card,
    .stat-card {
        color: #111;
        background: #fff !important;
        border: 1px solid #ddd;
        box-shadow: none;
        break-inside: avoid;
    }

    th,
    td {
        color: #111 !important;
        border-color: #ddd;
    }

    thead {
        background: #f3f3f3 !important;
    }

    .print-only {
        display: block;
    }

    a {
        color: #111;
    }
}
