:root {
    --teal-50: #f0f9fa;
    --teal-100: #d4eff1;
    --teal-200: #a8d5d8;
    --teal-300: #8cc5c9;
    --teal-400: #6fb5ba;
    --teal-500: #5a9ea3;
    --teal-600: #478186;
    --teal-700: #3a6a6e;
    --gold-50: #fdf8ed;
    --gold-100: #f5ecd0;
    --gold-200: #e8d192;
    --gold-300: #dfc070;
    --gold-400: #d4ad4e;
    --gold-500: #c49a3a;
    --gold-600: #a47e2d;
    --dark-50: #f5f5f6;
    --dark-100: #e5e5e7;
    --dark-200: #cdcdd0;
    --dark-300: #9d9da3;
    --dark-400: #6b6b73;
    --dark-500: #4a4a54;
    --dark-600: #3a3a42;
    --dark-700: #2d2d34;
    --dark-800: #1e1e24;
    --dark-900: #141418;
    --white: #ffffff;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition: all .2s ease;
}

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

body {
    font-family: 'Inter', 'Noto Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--dark-50);
    color: var(--dark-700);
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--teal-600); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--teal-700); }

.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--dark-800) 0%, var(--dark-900) 100%);
    color: var(--white);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand img {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: contain;
    background: var(--white);
    padding: 4px;
}

.sidebar-brand-text {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.3px;
}

.sidebar-brand-text span {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--teal-200);
    letter-spacing: .5px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--dark-400);
    padding: 0 12px;
    margin-bottom: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--dark-300);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
}

.sidebar-link:hover {
    background: rgba(255,255,255,.06);
    color: var(--white);
}

.sidebar-link.active {
    background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
    color: var(--white);
    box-shadow: 0 2px 8px rgba(90,158,163,.3);
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .7;
}

.sidebar-link.active svg,
.sidebar-link:hover svg { opacity: 1; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--teal-400), var(--gold-300));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: var(--white);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--dark-400);
}

.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.top-bar {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--dark-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--dark-800);
    letter-spacing: -.3px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-content {
    padding: 28px 32px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
    white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: linear-gradient(135deg, var(--teal-500), var(--teal-600));
    color: var(--white);
    box-shadow: 0 2px 4px rgba(90,158,163,.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(90,158,163,.3);
    color: var(--white);
}

.btn-gold {
    background: linear-gradient(135deg, var(--gold-400), var(--gold-500));
    color: var(--white);
    box-shadow: 0 2px 4px rgba(196,154,58,.25);
}

.btn-gold:hover {
    background: linear-gradient(135deg, var(--gold-500), var(--gold-600));
    transform: translateY(-1px);
    color: var(--white);
}

.btn-outline {
    background: var(--white);
    color: var(--dark-500);
    border: 1px solid var(--dark-200);
}

.btn-outline:hover {
    border-color: var(--teal-400);
    color: var(--teal-600);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #dc2626;
    color: var(--white);
}

.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--dark-100);
    overflow: hidden;
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--dark-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark-700);
}

.card-body { padding: 24px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--dark-100);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}

.stat-card-icon.teal { background: var(--teal-100); color: var(--teal-600); }
.stat-card-icon.gold { background: var(--gold-100); color: var(--gold-500); }
.stat-card-icon.green { background: #dcfce7; color: var(--success); }
.stat-card-icon.red { background: #fee2e2; color: var(--danger); }
.stat-card-icon.blue { background: #dbeafe; color: var(--info); }

.stat-card-icon svg { width: 22px; height: 22px; }

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--dark-800);
    line-height: 1;
    margin-bottom: 4px;
    letter-spacing: -.5px;
}

.stat-card-label {
    font-size: 13px;
    color: var(--dark-400);
    font-weight: 500;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--dark-400);
    background: var(--dark-50);
    border-bottom: 1px solid var(--dark-200);
}

table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--dark-100);
    font-size: 13px;
}

table tr:hover td {
    background: var(--teal-50);
}

table tr:last-child td { border-bottom: none; }

.badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.badge-draft { background: var(--dark-100); color: var(--dark-500); }
.badge-active, .badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-accepted, .badge-paid { background: #dcfce7; color: #166534; }
.badge-rejected, .badge-cancelled, .badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-expired { background: var(--gold-100); color: var(--gold-600); }
.badge-closed { background: var(--dark-200); color: var(--dark-600); }
.badge-partially_paid { background: #fef3c7; color: #92400e; }

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--dark-600);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--dark-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--dark-700);
    background: var(--white);
    transition: var(--transition);
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--teal-400);
    box-shadow: 0 0 0 3px rgba(168,213,216,.25);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6b73' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control { min-height: 80px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-inline {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--dark-100);
    margin-top: 24px;
}

.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--dark-400);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: .4;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--dark-500);
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

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

.detail-item {
    padding: 12px 0;
}

.detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--dark-400);
    margin-bottom: 4px;
}

.detail-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--dark-700);
}

.budget-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 20px;
    background: var(--dark-50);
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.budget-summary-item {
    text-align: center;
}

.budget-summary-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -.3px;
}

.budget-summary-value.revenue { color: var(--teal-600); }
.budget-summary-value.cost { color: var(--danger); }
.budget-summary-value.profit { color: var(--success); }
.budget-summary-value.negative { color: var(--danger); }

.budget-summary-label {
    font-size: 12px;
    color: var(--dark-400);
    font-weight: 500;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--dark-100);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .5s ease;
}

.progress-bar-fill.teal { background: linear-gradient(90deg, var(--teal-400), var(--teal-600)); }
.progress-bar-fill.gold { background: linear-gradient(90deg, var(--gold-300), var(--gold-500)); }
.progress-bar-fill.green { background: linear-gradient(90deg, #4ade80, var(--success)); }

.chart-container {
    position: relative;
    height: 300px;
    max-height: 300px;
    padding: 16px;
    overflow: hidden;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--dark-800) 0%, var(--dark-900) 50%, var(--teal-700) 100%);
}

.login-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
    width: 420px;
    max-width: 90vw;
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, var(--dark-800), var(--dark-700));
    padding: 36px 40px 30px;
    text-align: center;
}

.login-header img {
    width: 72px;
    height: 72px;
    border-radius: 14px;
    margin-bottom: 14px;
    background: var(--white);
    padding: 6px;
}

.login-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--white);
    margin-bottom: 4px;
}

.login-header p {
    font-size: 13px;
    color: var(--dark-300);
}

.login-body {
    padding: 36px 40px;
}

.login-body .form-group { margin-bottom: 22px; }

.login-body .btn {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 15px;
}

.money-in { color: var(--success); }
.money-out { color: var(--danger); }
.text-muted { color: var(--dark-400); }
.text-bold { font-weight: 700; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark-700);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.action-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.page-tabs {
    display: flex;
    gap: 4px;
    background: var(--dark-50);
    padding: 4px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
}

.page-tab {
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--dark-400);
    transition: var(--transition);
    cursor: pointer;
}

.page-tab:hover { color: var(--dark-700); }

.page-tab.active {
    background: var(--white);
    color: var(--teal-600);
    box-shadow: var(--shadow-sm);
}

.tooltip {
    position: relative;
}

.errorlist {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}

.errorlist li {
    color: var(--danger);
    font-size: 12px;
}

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--dark-700);
    padding: 4px;
    border-radius: 6px;
}
.hamburger-btn:hover {
    background: var(--dark-50);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,.5);
    z-index: 99;
}
.sidebar-overlay.active {
    display: block;
}

.stat-card-sub {
    font-size: 12px;
    color: var(--dark-400);
    margin-top: 2px;
}

@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform .3s ease;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content { margin-left: 0; }
    .page-content { padding: 16px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .budget-summary { grid-template-columns: 1fr; }
    .hamburger-btn { display: block; }
    .top-bar { padding: 0 16px; }
}

body.rtl {
  direction: rtl;
  text-align: right;
}

body.rtl .sidebar {
  left: auto;
  right: 0;
}

body.rtl .main-content {
  margin-left: 0;
  margin-right: var(--sidebar-width);
}

body.rtl .sidebar-link {
  flex-direction: row-reverse;
}

body.rtl .sidebar-brand {
  flex-direction: row-reverse;
}

body.rtl .sidebar-user {
  flex-direction: row-reverse;
}

body.rtl table th,
body.rtl table td {
  text-align: right;
}

body.rtl .text-right {
  text-align: left;
}

body.rtl .top-bar {
  flex-direction: row-reverse;
}

body.rtl .top-bar-actions {
  flex-direction: row-reverse;
}

body.rtl .btn {
  flex-direction: row-reverse;
}

body.rtl .stat-card-icon {
  margin-left: 0;
  margin-right: 0;
}

body.rtl select.form-control {
  background-position: left 12px center;
  padding-left: 36px;
  padding-right: 14px;
}

body.rtl .form-actions {
  justify-content: flex-start;
}

body.rtl .section-header {
  flex-direction: row-reverse;
}

body.rtl .card-header {
  flex-direction: row-reverse;
}

body.rtl .badge {
  direction: ltr;
}

body.rtl .sidebar-section-title {
  text-align: right;
}

body.rtl .sidebar-footer .sidebar-link {
  flex-direction: row-reverse;
}

body.rtl .alert {
  flex-direction: row-reverse;
}

body.rtl .detail-grid {
  direction: rtl;
}

body.rtl .action-group {
  flex-direction: row-reverse;
}

body.rtl .page-tabs {
  flex-direction: row-reverse;
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--dark-50);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--dark-200);
}

.lang-toggle-btn {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--dark-400);
  transition: var(--transition);
}

.lang-toggle-btn.active {
  background: var(--teal-500);
  color: white;
  box-shadow: var(--shadow-sm);
}

.lang-toggle-btn:hover:not(.active) {
  color: var(--dark-600);
}

@media (max-width: 768px) {
  body.rtl .sidebar {
    left: auto;
    right: 0;
    transform: translateX(100%);
  }
  body.rtl .sidebar.open {
    transform: translateX(0);
  }
  body.rtl .main-content { margin-right: 0; }
}
