@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

/* ==================== المتغيرات العامة ==================== */
:root {
  --primary: #0c4a32;
  --primary-light: #15734e;
  --primary-dark: #062b1d;
  --accent: #c5a059; /* Harmonious Matte Gold */
  --accent-light: #faefd6;
  --success: #059669;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0px 4px 20px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0px 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-btn: 0px 4px 12px rgba(30, 41, 59, 0.15);
  --sidebar-width: 260px;
}

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

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; transition: color 0.3s; }
button { cursor: pointer; font-family: inherit; transition: all 0.3s; }
input, select, textarea { font-family: inherit; transition: all 0.3s; }

/* ==================== شاشة تسجيل الدخول ==================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #F4F7FE 0%, #E0E5F2 100%);
}

.login-card {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 48px 40px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  color: #fff; font-size: 32px; font-weight: 800;
  box-shadow: var(--shadow-btn);
}

.login-logo h1 { font-size: 24px; color: var(--text); font-weight: 700; margin-bottom: 8px; }
.login-logo p { color: var(--text-muted); font-size: 14px; font-weight: 500; }

.form-group { margin-bottom: 24px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 14px 18px; border: 1px solid var(--border);
  border-radius: 12px; font-size: 14px; font-weight: 500;
  background: #F4F7FE; color: var(--text);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(67, 24, 255, 0.1);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 24px; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.5px;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; box-shadow: var(--shadow-btn); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0px 6px 16px rgba(67, 24, 255, 0.4); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0px 4px 12px rgba(1, 181, 116, 0.3); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0px 4px 12px rgba(238, 93, 80, 0.3); }
.btn-outline { background: transparent; border: 2px solid var(--border); color: var(--text); box-shadow: none; }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.error-msg {
  background: rgba(238, 93, 80, 0.1); color: var(--danger); padding: 12px 16px;
  border-radius: 12px; font-size: 14px; font-weight: 600; margin-bottom: 24px; display: none;
  border-right: 4px solid var(--danger);
}
.error-msg.show { display: block; animation: fadeIn 0.3s ease; }

.success-msg {
  background: rgba(1, 181, 116, 0.1); color: var(--success); padding: 12px 16px;
  border-radius: 12px; font-size: 14px; font-weight: 600; margin-bottom: 24px; display: none;
  border-right: 4px solid var(--success);
}
.success-msg.show { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== تخطيط التطبيق (Sidebar + Navbar) ==================== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  box-shadow: 14px 0px 40px rgba(112, 144, 176, 0.08);
  display: flex; flex-direction: column;
  position: fixed; top: 0; right: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 1px solid var(--border);
}

.sidebar-header {
  padding: 32px 24px 24px; display: flex; align-items: center; gap: 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header .icon {
  width: 44px; height: 44px; background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; font-size: 20px; box-shadow: var(--shadow-btn);
}
.sidebar-header h2 { font-size: 18px; color: var(--text); font-weight: 700; }
.sidebar-header span { font-size: 12px; color: var(--text-muted); font-weight: 500; display: block; margin-top: 2px;}

.sidebar-nav { flex: 1; padding: 24px 16px; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 12px; margin-bottom: 8px;
  color: var(--text-muted); font-size: 15px; font-weight: 600;
  transition: all 0.3s;
}
.sidebar-nav a:hover { background: #f8fafc; color: var(--primary); transform: translateX(-4px); }
.sidebar-nav a.active { background: var(--primary); color: #fff; box-shadow: 0px 4px 12px rgba(4, 120, 87, 0.3); border-right: 4px solid var(--accent); }
.sidebar-nav .nav-label {
  font-size: 12px; color: var(--text-muted); margin: 24px 16px 12px; text-transform: uppercase; font-weight: 700; letter-spacing: 1px;
}

.sidebar-footer { padding: 24px; border-top: 1px solid var(--border); }
.sidebar-footer button {
  width: 100%; background: #F4F7FE; color: var(--text); border-radius: 12px; padding: 14px; font-weight: 700; border: none;
}
.sidebar-footer button:hover { background: rgba(238, 93, 80, 0.1); color: var(--danger); }

.main-content { flex: 1; margin-right: var(--sidebar-width); display: flex; flex-direction: column; }

.navbar {
  background: rgba(244, 247, 254, 0.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 20px 32px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50; border-bottom: 1px solid rgba(224, 229, 242, 0.5);
}
.navbar h1 { font-size: 24px; color: var(--text); font-weight: 700; }
.navbar .user-badge {
  display: flex; align-items: center; gap: 14px; font-size: 15px; background: var(--surface);
  padding: 10px 10px 10px 20px; border-radius: 50px; box-shadow: var(--shadow-sm); border: 1px solid var(--accent);
}
.navbar .user-badge .avatar {
  width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #a37c35);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.role-tag {
  font-size: 11px; padding: 2px 10px; border-radius: 12px; background: var(--accent-light); color: #87621c;
  font-weight: 800; display: inline-block; margin-top: 4px; border: 1px solid var(--accent);
}

.page-body { padding: 32px; max-width: 1600px; margin: 0 auto; width: 100%; }

/* ==================== البطاقات (Cards) ==================== */
.cards-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0px 12px 24px rgba(15, 23, 42, 0.08); }

.stat-card .label { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); display: flex; align-items: baseline; gap: 8px; }
.stat-card .sub { font-size: 13px; font-weight: 500; color: var(--text-muted); margin-top: 12px; display: inline-block; padding: 4px 0; border-top: 1px dashed var(--border); width: 100%; }

.panel {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px; margin-bottom: 32px; border: 1px solid var(--border);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;
}
.panel-header h3 { font-size: 18px; color: var(--text); font-weight: 700; }

/* ==================== الجداول ==================== */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); border-top: 3px solid var(--accent); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; background: var(--surface); }
th, td { padding: 16px 20px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #F8FAFC; color: var(--text-muted); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
tbody tr { transition: background 0.2s; }
tbody tr:hover { background: #F4F7FE; }
tbody tr:last-child td { border-bottom: none; }

.badge { padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 700; display: inline-block; }
.badge-buy { background: rgba(1, 181, 116, 0.1); color: var(--success); }
.badge-sell { background: rgba(238, 93, 80, 0.1); color: var(--danger); }
.badge-active { background: rgba(1, 181, 116, 0.1); color: var(--success); }
.badge-inactive { background: #F4F7FE; color: var(--text-muted); }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; align-items: center; background: #F4F7FE; padding: 16px; border-radius: 16px; }
.toolbar input, .toolbar select { padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-weight: 500; background: #fff; }

.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 24px; }
.pagination button {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 14px; font-weight: 600; color: var(--text-muted); transition: all 0.2s;
}
.pagination button:hover { background: #F4F7FE; color: var(--primary); border-color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: var(--shadow-btn); }

/* ==================== Modal ==================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(43, 54, 116, 0.4); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 200;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.3s ease; }
.modal {
  background: var(--surface); border-radius: 24px; width: 100%; max-width: 500px;
  padding: 32px; box-shadow: 0 20px 40px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto;
  transform: scale(0.95); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.show .modal { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-header h3 { font-size: 20px; color: var(--text); font-weight: 700; }
.modal-header .close-btn { font-size: 24px; color: var(--text-muted); background: none; border: none; padding: 4px; border-radius: 8px; transition: background 0.2s; }
.modal-header .close-btn:hover { background: #F4F7FE; color: var(--danger); }
.modal-actions { display: flex; gap: 12px; margin-top: 32px; }
.modal-actions .btn { flex: 1; }

/* ==================== استجابة الشاشات الصغيرة ==================== */
.menu-toggle { display: none; background: none; border: none; font-size: 24px; color: var(--primary); padding: 8px; border-radius: 8px; cursor: pointer; }
.menu-toggle:hover { background: #F4F7FE; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); box-shadow: -100vw 0 0 rgba(43, 54, 116, 0.4); }
  .main-content { margin-right: 0; }
  .menu-toggle { display: block; }
  .page-body { padding: 20px; }
  .navbar { padding: 16px 20px; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .cards-grid { grid-template-columns: 1fr; }
}

.empty-state { text-align: center; padding: 64px 24px; color: var(--text-muted); font-size: 16px; font-weight: 600; }
.loading { text-align: center; padding: 40px; color: var(--primary); font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 12px; }
.loading::after {
  content: ''; width: 20px; height: 20px; border: 3px solid #E0E5F2; border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
