:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --surface: #f8fafc;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Tahoma, Arial, sans-serif; background: var(--surface); color: var(--text); font-size: 14px; direction: rtl; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; min-width: 240px; background: #0f172a; color: #e2e8f0; display: flex; flex-direction: column; position: fixed; top: 0; right: 0; height: 100vh; z-index: 100; overflow-y: auto; transition: transform .3s; }
.sidebar-logo { padding: 20px 16px 12px; border-bottom: 1px solid #1e293b; }
.sidebar-logo .company { font-size: 1.1rem; font-weight: 800; color: #f1f5f9; }
.sidebar-logo .project { font-size: .72rem; color: #94a3b8; margin-top: 2px; line-height: 1.4; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-section { padding: 12px 16px 4px; font-size: .65rem; font-weight: 700; color: #475569; text-transform: uppercase; letter-spacing: .08em; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: #94a3b8; cursor: pointer; transition: all .15s; font-size: .87rem; border-right: 3px solid transparent; }
.nav-item:hover { background: #1e293b; color: #f1f5f9; }
.nav-item.active { background: #1e3a8a; color: #93c5fd; border-right-color: #3b82f6; }
.nav-item i { width: 18px; text-align: center; }
.sidebar-user { padding: 12px 16px; border-top: 1px solid #1e293b; font-size: .8rem; color: #94a3b8; display: flex; align-items: center; gap: 8px; }
.sidebar-user .user-avatar { width: 32px; height: 32px; border-radius: 50%; background: #1e3a8a; display: flex; align-items: center; justify-content: center; color: #93c5fd; font-weight: 700; font-size: .85rem; flex-shrink: 0; }

.main-content { margin-right: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow); }
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.page-content { flex: 1; padding: 24px; }

/* Cards */
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 1rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--primary); }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #f3e8ff; color: #7c3aed; }
.stat-val { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.stat-lbl { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 7px; font-size: .85rem; font-weight: 600; cursor: pointer; border: none; transition: all .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: 5px 10px; font-size: .78rem; border-radius: 6px; }
.btn-xs { padding: 3px 8px; font-size: .73rem; border-radius: 5px; }
.btn-icon { padding: 7px 9px; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 20px; font-size: .73rem; font-weight: 700; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-secondary { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-purple { background: #f3e8ff; color: #7c3aed; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
thead th { background: var(--surface-2); padding: 10px 14px; text-align: right; font-size: .78rem; font-weight: 700; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: .83rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
.td-actions { display: flex; gap: 4px; align-items: center; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.form-control { width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 7px; font-size: .87rem; color: var(--text); background: #fff; transition: border .15s; font-family: inherit; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-lg { max-width: 800px; }
.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; z-index: 10; }
.modal-title { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.btn-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); padding: 4px; line-height: 1; }
.btn-close:hover { color: var(--text); }

/* Toast */
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: 380px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); font-size: .87rem; font-weight: 600; animation: slideDown .25s ease; }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Login */
.login-page { min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .company { font-size: 1.6rem; font-weight: 900; color: var(--primary-dark); }
.login-logo .sub { font-size: .85rem; color: var(--text-muted); margin-top: 4px; }
.login-logo .icon { font-size: 3rem; margin-bottom: 8px; }

/* Progress bars */
.progress-wrap { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.progress-fill.blue { background: var(--primary); }
.progress-fill.green { background: var(--success); }
.progress-fill.orange { background: var(--warning); }
.progress-fill.red { background: var(--danger); }

/* Category Cards */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); cursor: pointer; transition: all .15s; }
.cat-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(29,78,216,.12); transform: translateY(-1px); }
.cat-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cat-badge { width: 36px; height: 36px; border-radius: 8px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem; }
.cat-budget { font-size: .8rem; color: var(--text-muted); text-align: left; }
.cat-budget strong { display: block; font-size: 1rem; color: var(--text); font-weight: 700; }
.cat-name { font-size: .95rem; font-weight: 700; margin-bottom: 10px; }
.cat-stats { display: flex; gap: 12px; font-size: .75rem; color: var(--text-muted); margin-bottom: 10px; }
.cat-stats span strong { color: var(--text); }

/* Work Item List */
.item-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.item-row:hover { background: var(--surface); }
.item-row:last-child { border-bottom: none; }
.item-code { font-size: .75rem; font-weight: 700; color: var(--primary); min-width: 60px; }
.item-desc { flex: 1; font-size: .85rem; line-height: 1.4; }
.item-desc .sub { font-size: .73rem; color: var(--text-muted); margin-top: 2px; }
.item-meta { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.pct-badge { font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 20px; }

/* Detail view */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.info-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.info-box-label { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.info-box-val { font-size: 1.05rem; font-weight: 700; color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 10px 20px; font-size: .85rem; font-weight: 600; cursor: pointer; border: none; background: none; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover { color: var(--text); }
.tab-count { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 9px; background: var(--surface-2); font-size: .67rem; margin-right: 5px; }
.tab-btn.active .tab-count { background: var(--primary-light); color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Budget summary */
.budget-bar { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; margin-bottom: 20px; }
.budget-bar-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.bval { text-align: center; }
.bval .lbl { font-size: .72rem; color: var(--text-muted); margin-bottom: 2px; }
.bval .val { font-size: 1.1rem; font-weight: 800; }
.bval .val.blue { color: var(--primary); }
.bval .val.red { color: var(--danger); }
.bval .val.green { color: var(--success); }
.bval .val.orange { color: var(--warning); }

/* Dashboard chart simulation */
.mini-chart { display: flex; gap: 6px; align-items: flex-end; height: 60px; padding: 8px 0; }
.mini-bar { flex: 1; border-radius: 3px 3px 0 0; min-width: 12px; cursor: default; transition: opacity .15s; }
.mini-bar:hover { opacity: .8; }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text-muted); margin-bottom: 16px; flex-wrap: wrap; }
.breadcrumb a { color: var(--primary); cursor: pointer; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--border); }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: .4; display: block; }
.empty-state p { font-size: .9rem; }

/* Attachment */
.attach-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; }
.attach-icon { width: 36px; height: 36px; border-radius: 7px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: .9rem; }
.attach-name { flex: 1; font-size: .85rem; font-weight: 600; }
.attach-meta { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-right: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .cat-grid { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal { margin: 8px; }
}
@media print {
  .sidebar, .topbar, .btn, .td-actions { display: none !important; }
  .main-content { margin-right: 0 !important; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}

/* Loader */
.loader { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Status colors for items */
.status-pending { color: var(--text-muted); }
.status-in_progress { color: var(--warning); }
.status-completed { color: var(--success); }
.status-paused { color: var(--danger); }

/* Notification dot */
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; margin-right: 2px; }

/* Sidebar mobile overlay */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
.sidebar-overlay.active { display: block; }
