* { box-sizing: border-box; }

:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --orange: #f97316;
    --orange-bg: #ffedd5;
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --gray-bg: #f3f4f6;
}

body {
    margin: 0;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: #f5f7fb;
    color: var(--text);
    font-size: 14px;
    line-height: 1.7;
}

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

/* ===== Topbar ===== */
.topbar {
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 24px;
    flex-wrap: wrap;
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.brand { font-weight: 700; font-size: 16px; }
.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a {
    color: #dbeafe;
    padding: 6px 12px;
    border-radius: 8px;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.18); color: #fff; }
.userbox { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-name { font-weight: 700; }
.user-meta { color: #bfdbfe; font-size: 12px; }

/* ===== Layout ===== */
.container { max-width: 1280px; margin: 24px auto; padding: 0 16px; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 16px; }
.card {
    background: #fff;
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.muted { color: var(--muted); font-size: 12px; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    border-radius: 14px;
    padding: 16px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border-inline-start: 6px solid #9ca3af;
}
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat-new { border-color: #9ca3af; }
.stat-progress { border-color: var(--orange); }
.stat-completed { border-color: var(--blue); }
.stat-approved { border-color: var(--green); }
.stat-overdue { border-color: var(--red); }

/* ===== Alerts ===== */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.alert-success { background: var(--green-bg); color: #166534; border: 1px solid #86efac; }
.alert-error { background: var(--red-bg); color: #991b1b; border: 1px solid #fca5a5; }
.alert-warn { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.alert ul { margin: 6px 0 0; padding-inline-start: 20px; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }
.alert[hidden], [hidden] { display: none !important; }

/* ===== Filters ===== */
.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
input[type=text], input[type=password], select, textarea {
    font-family: inherit;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
    min-width: 180px;
}
textarea { min-width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 7px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    background: var(--primary);
    white-space: nowrap;
}
.btn:hover { filter: brightness(.95); }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; font-size: 15px; }
.btn-primary { background: var(--primary); }
.btn-ghost { background: rgba(255,255,255,.15); color: #fff; }
.btn-start { background: var(--orange); }
.btn-done { background: var(--blue); }
.btn-approve { background: var(--green); }
.btn-return { background: #7c3aed; }
.btn-danger { background: var(--red); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-chip { background: #eef2ff; color: var(--primary-dark); border: 1px solid #c7d2fe; font-weight: 600; }
.inline-form { display: inline-block; margin: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 4px; min-width: 150px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1100px; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f9fafb; font-size: 13px; color: #374151; position: sticky; top: 0; }
td small { color: var(--muted); display: block; }

tr.row-new td { background: #ffffff; }
tr.row-progress td { background: var(--orange-bg); }
tr.row-completed td { background: var(--blue-bg); }
tr.row-approved td { background: var(--green-bg); }
tr.is-overdue { box-shadow: inset 5px 0 0 var(--red); }
tr.is-near td.due { color: #b45309; font-weight: 700; }
tr.is-overdue td.due { color: var(--red); font-weight: 700; }
td.approved-date { color: var(--green); font-weight: 700; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.badge-new { background: #e5e7eb; color: #374151; }
.badge-progress { background: var(--orange); color: #fff; }
.badge-completed { background: var(--blue); color: #fff; }
.badge-approved { background: var(--green); color: #fff; }
.badge-overdue { background: var(--red); color: #fff; margin-top: 4px; }
.badge-near { background: #facc15; color: #713f12; }
.badge-active { background: var(--green-bg); color: #166534; }
.badge-inactive { background: var(--red-bg); color: #991b1b; }
.badge-role { background: #ede9fe; color: #5b21b6; }

/* ===== Legend ===== */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; margin-bottom: 12px; }
.legend span::before {
    content: '';
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 3px;
    margin-inline-end: 6px;
    vertical-align: middle;
}
.legend .lg-new::before { background: #e5e7eb; }
.legend .lg-progress::before { background: var(--orange); }
.legend .lg-completed::before { background: var(--blue); }
.legend .lg-approved::before { background: var(--green); }
.legend .lg-overdue::before { background: var(--red); }

/* ===== Forms ===== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.errors { background: var(--red-bg); color: #991b1b; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.errors ul { margin: 0; padding-inline-start: 20px; }
.ltr { direction: ltr; unicode-bidi: plaintext; }

/* ===== Login ===== */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e40af, #7c3aed); }
.login-card { background: #fff; width: 100%; max-width: 380px; padding: 32px 28px; border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 6px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { width: 100%; min-width: 0; }

@media (max-width: 720px) {
    .topbar { padding: 12px; }
    .userbox { margin-inline-start: 0; }
    .container { padding: 0 10px; }
}
