/* ============================================================
   سیستم مدیریت کارگاه خیاطی - استایل اصلی
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-700: #334155;
    --gray-900: #0f172a;
    --white: #ffffff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
    --sidebar-width: 250px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    font-size: 14px;
    line-height: 1.7;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Layout ---------------- */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: var(--gray-100);
    position: fixed;
    top: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    font-size: 17px;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-icon { font-size: 22px; }

.sidebar-nav { display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; overflow-y: auto; }
.sidebar-nav a {
    color: #cbd5e1;
    padding: 11px 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--white); text-decoration: none; }
.sidebar-nav a.active { background: var(--primary); color: var(--white); font-weight: 600; }
.sidebar-nav .ic { font-size: 16px; width: 20px; text-align: center; }

.main-area { flex: 1; margin-right: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.toggle-sidebar { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }

.global-search { flex: 1; display: flex; max-width: 480px; }
.global-search input {
    flex: 1;
    border: 1px solid var(--gray-200);
    border-radius: 8px 0 0 8px;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 13px;
    background: var(--gray-50);
}
.global-search button {
    border: 1px solid var(--gray-200);
    border-right: none;
    background: var(--gray-50);
    border-radius: 0 8px 8px 0;
    padding: 0 14px;
    cursor: pointer;
}

.topbar-user { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { background: var(--primary-light); color: var(--primary-dark); font-size: 11px; padding: 3px 9px; border-radius: 20px; }
.btn-logout { background: var(--gray-100); padding: 7px 14px; border-radius: 8px; font-size: 13px; color: var(--gray-700); }
.btn-logout:hover { background: var(--danger-light); color: var(--danger); text-decoration: none; }

.content { padding: 24px; flex: 1; }

.app-footer { text-align: center; padding: 16px; color: var(--gray-500); font-size: 12px; }

/* ---------------- Alerts ---------------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }

/* ---------------- Page header ---------------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 20px; font-weight: 700; }

/* ---------------- Stats grid ---------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    border-right: 4px solid var(--primary);
}
.stat-card.stat-blue { border-color: var(--primary); }
.stat-card.stat-green { border-color: var(--success); }
.stat-card.stat-orange { border-color: var(--warning); }
.stat-card.stat-gray { border-color: var(--gray-500); }
.stat-card.stat-red { border-color: var(--danger); }
.stat-icon { font-size: 26px; }
.stat-info { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 18px; font-weight: 700; }
.stat-label { font-size: 12.5px; color: var(--gray-500); }

/* ---------------- Cards ---------------- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--gray-100); }
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-header a { font-size: 12.5px; }
.card-toolbar { padding: 16px 20px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.card-wide { grid-column: 1 / -1; }
.form-card { padding: 24px; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 20px; }

/* ---------------- Tables ---------------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: var(--gray-50);
    color: var(--gray-500);
    font-size: 12px;
    font-weight: 600;
    text-align: right;
    padding: 11px 16px;
    border-bottom: 1px solid var(--gray-200);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); font-size: 13.5px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }
.empty-row { text-align: center; color: var(--gray-500); padding: 24px !important; }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form { display: inline; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 4px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-status { background: var(--primary-light); color: var(--primary-dark); }
.badge-status.status-success { background: var(--success-light); color: #166534; }
.badge-status.status-warning { background: var(--warning-light); color: #92400e; }
.badge-status.status-danger { background: var(--danger-light); color: #991b1b; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    background: var(--gray-100);
    color: var(--gray-700);
    transition: all 0.15s;
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--gray-700); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=file],
select, textarea {
    width: 100%;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13.5px;
    background: var(--white);
    color: var(--gray-900);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.section-title { margin: 20px 0 10px; font-size: 14px; font-weight: 700; }
.inline-search { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-search input, .inline-search select { width: auto; min-width: 180px; }
.report-filter label { font-size: 13px; color: var(--gray-500); }
.total-badge { font-weight: 700; color: var(--primary-dark); }

/* ---------------- Modal ---------------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 200; align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-content { background: var(--white); border-radius: var(--radius); width: 92%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--gray-100); }
.modal-header h3 { font-size: 15.5px; font-weight: 700; }
.modal-close { cursor: pointer; font-size: 22px; color: var(--gray-500); line-height: 1; }
.modal-body { padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--gray-100); }

/* ---------------- Profile / Info card ---------------- */
.profile-info-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 24px;
    margin-bottom: 20px;
    font-size: 13.5px;
}
.profile-info-card .full-row { grid-column: 1 / -1; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ---------------- Timeline ---------------- */
.log-form { display: flex; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--gray-100); }
.timeline { list-style: none; padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; position: relative; }
.timeline li { position: relative; padding-right: 22px; }
.timeline-dot { position: absolute; right: 0; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline-text { font-size: 13.5px; }
.timeline-date { font-size: 11.5px; color: var(--gray-500); margin-top: 2px; }

/* ---------------- Report tabs ---------------- */
.report-tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.report-tabs a { background: var(--white); padding: 9px 18px; border-radius: 8px; font-size: 13px; color: var(--gray-700); box-shadow: var(--shadow); }
.report-tabs a.active { background: var(--primary); color: var(--white); }
.report-tabs a:hover { text-decoration: none; }

/* ---------------- Login page ---------------- */
.login-body { background: linear-gradient(135deg, var(--gray-900), var(--primary-dark)); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: var(--white); border-radius: 16px; padding: 40px 36px; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); }
.login-logo { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-box h2 { font-size: 16px; color: var(--gray-500); font-weight: 500; margin-bottom: 22px; }
.login-hint { text-align: center; margin-top: 16px; font-size: 12px; color: var(--gray-500); }

/* ---------------- Invoice print ---------------- */
.print-body { background: var(--gray-100); }
.invoice-toolbar { display: flex; justify-content: center; gap: 12px; padding: 18px; }
.invoice-sheet { background: var(--white); max-width: 800px; margin: 0 auto 40px; padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.invoice-header { display: flex; justify-content: space-between; border-bottom: 2px solid var(--gray-900); padding-bottom: 20px; margin-bottom: 20px; }
.invoice-meta { text-align: left; }
.invoice-customer { margin-bottom: 24px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-size: 13.5px; }
.invoice-items-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.invoice-items-table th, .invoice-items-table td { border: 1px solid var(--gray-200); padding: 9px 12px; font-size: 13px; text-align: center; }
.invoice-items-table th { background: var(--gray-50); }
.invoice-summary { max-width: 320px; margin-right: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.invoice-summary div { display: flex; justify-content: space-between; padding-bottom: 6px; border-bottom: 1px solid var(--gray-100); }
.invoice-final { font-weight: 700; font-size: 15px; color: var(--primary-dark); }
.invoice-footer { display: flex; justify-content: space-between; margin-top: 60px; }
.signature-box { border-top: 1px solid var(--gray-300); width: 180px; text-align: center; padding-top: 6px; font-size: 12px; color: var(--gray-500); }
.invoice-totals input { background: var(--gray-50); }
.current-logo img { max-width: 140px; border-radius: 8px; margin-bottom: 10px; }

@media print {
    .no-print { display: none !important; }
    .invoice-sheet { box-shadow: none; margin: 0; max-width: 100%; }
    body { background: var(--white); }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.show { transform: translateX(0); }
    .main-area { margin-right: 0; min-width: 0; }
    .toggle-sidebar { display: block; flex-shrink: 0; }
    .global-search { max-width: none; min-width: 0; }
    .topbar-user .user-role { display: none; }

    .topbar {
        padding: 10px 16px;
        gap: 12px;
    }

    .topbar-user {
        gap: 7px;
        min-width: max-content;
    }

    .user-name {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .content {
        padding: 20px 16px;
        overflow-x: hidden;
    }

    .dashboard-grid {
        grid-template-columns: minmax(0, 1fr);
    }

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

    .card {
        max-width: 100%;
    }

    .data-table {
        min-width: 650px;
    }

    .card:has(.data-table) {
        overflow-x: auto;
    }

    .form-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .profile-info-card {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .invoice-sheet {
        width: calc(100% - 24px);
        padding: 28px;
    }
}

@media (max-width: 600px) {
    .topbar {
        padding: 9px 12px;
        gap: 8px;
    }

    .toggle-sidebar {
        font-size: 19px;
    }

    .global-search {
        flex: 1;
    }

    .global-search input {
        min-width: 0;
        padding: 8px 10px;
        font-size: 12px;
    }

    .global-search button {
        padding: 0 10px;
    }

    .topbar-user {
        margin-right: 0;
    }

    .topbar-user .btn-logout {
        padding: 6px 9px;
        font-size: 12px;
    }

    .user-name {
        display: none;
    }

    .content {
        padding: 16px 12px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
        margin-bottom: 16px;
    }

    .page-header h1 {
        font-size: 18px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 18px;
    }

    .stat-card {
        padding: 15px 16px;
    }

    .dashboard-grid {
        gap: 14px;
    }

    .card-header,
    .card-toolbar {
        padding: 13px 14px;
    }

    .card-header {
        gap: 8px;
        flex-wrap: wrap;
    }

    .form-card {
        padding: 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .inline-search {
        align-items: stretch;
        flex-direction: column;
    }

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

    .actions-cell {
        flex-direction: column;
        align-items: stretch;
    }

    .actions-cell .btn {
        width: 100%;
    }

    .profile-info-card {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .profile-info-card .full-row {
        grid-column: auto;
    }

    .log-form {
        flex-direction: column;
        padding: 14px;
    }

    .log-form .btn {
        width: 100%;
    }

    .report-tabs {
        gap: 5px;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 3px;
    }

    .report-tabs a {
        white-space: nowrap;
        padding: 8px 13px;
    }

    .modal-content {
        width: calc(100% - 24px);
        max-height: 92vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .login-box {
        padding: 30px 22px;
    }

    .invoice-toolbar {
        flex-wrap: wrap;
        padding: 12px;
    }

    .invoice-sheet {
        width: calc(100% - 16px);
        padding: 18px 14px;
        margin-bottom: 20px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 16px;
    }

    .invoice-meta {
        text-align: right;
    }

    .invoice-customer {
        grid-template-columns: 1fr;
    }

    .invoice-items-table {
        min-width: 620px;
    }

    .invoice-sheet {
        overflow-x: auto;
    }

    .invoice-summary {
        max-width: 100%;
        width: 100%;
    }

    .invoice-footer {
        flex-direction: column;
        gap: 35px;
        margin-top: 40px;
    }

    .signature-box {
        width: 160px;
    }
}

@media (max-width: 380px) {
    .content {
        padding-left: 9px;
        padding-right: 9px;
    }

    .topbar {
        padding-left: 8px;
        padding-right: 8px;
    }

    .topbar-user .btn-logout {
        font-size: 11px;
        padding: 5px 7px;
    }

    .stat-card {
        gap: 10px;
        padding: 13px;
    }

    .stat-icon {
        font-size: 23px;
    }

    .stat-value {
        font-size: 16px;
    }

    .card-header,
    .card-toolbar {
        padding-left: 11px;
        padding-right: 11px;
    }
}
