:root {
  --color-primary: #005931;
  --color-on-primary: #fff;
  --color-surface: #f8f9fb;
  --color-surface-lowest: #fff;
  --color-on-surface: #191c1e;
  --color-outline-variant: #bfc9be;
  --font-ui: 'Cairo', sans-serif;
}

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

body {
  font-family: var(--font-ui);
  color: var(--color-on-surface);
  direction: rtl;
  min-height: 100vh;
}

.hidden { display: none !important; }

.text-success { color: #217346; }
.text-danger { color: #ba1a1a; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-outline-variant);
  border-radius: 8px;
  background: var(--color-surface-lowest);
  color: var(--color-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.btn:hover { background: #f3f4f6; }

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}

.btn-primary:hover { background: #217346; }

.btn-danger {
  background: #ba1a1a;
  color: #fff;
  border-color: #ba1a1a;
}

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.btn-block { width: 100%; justify-content: center; }

/* ─── Login ─── */
.portal-auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ebf3ed 0%, var(--color-surface) 50%, #e7e8ea 100%);
  padding: 1.5rem;
}

.portal-auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface-lowest);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

.portal-auth-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.portal-auth-brand h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
  margin-top: 0.75rem;
}

.portal-auth-brand p { font-size: 0.875rem; color: #58605c; margin-top: 0.25rem; }
.portal-auth-sub { font-size: 0.8rem !important; }

.portal-auth-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  margin-top: 0.85rem;
}

.portal-auth-form input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-outline-variant);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}

.portal-auth-form input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.portal-error {
  color: #ba1a1a;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.portal-auth-form .btn { margin-top: 1.25rem; }

.animate-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ─── Home ─── */
.portal-home-page { background: var(--color-surface); }

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--color-primary);
  color: var(--color-on-primary);
  gap: 1rem;
  flex-wrap: wrap;
}

.portal-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.portal-header-brand h1 { font-size: 1.15rem; }
.portal-header-brand p { font-size: 0.75rem; opacity: 0.85; }

.portal-header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.portal-header-user .btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.portal-header-user .btn:hover { background: rgba(255, 255, 255, 0.22); }

.portal-user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.85rem;
}

.portal-role-badge {
  font-size: 0.7rem;
  opacity: 0.85;
}

.portal-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.portal-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.portal-toolbar h2 { font-size: 1.25rem; color: var(--color-primary); }
.portal-toolbar p { font-size: 0.875rem; color: #58605c; margin-top: 0.25rem; }

.budgets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.budget-card {
  background: var(--color-surface-lowest);
  border: 1px solid var(--color-outline-variant);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.budget-card:hover {
  box-shadow: 0 4px 16px rgba(0, 89, 49, 0.1);
  border-color: var(--color-primary);
}

.budget-card--default { border-color: var(--color-primary); }

.budget-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #ebf3ed;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.budget-card-body h2 { font-size: 1.05rem; }

.budget-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: #58605c;
  margin-top: 0.35rem;
}

.budget-card-desc {
  font-size: 0.82rem;
  color: #58605c;
  margin-top: 0.25rem;
}

.budget-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: #ebf3ed;
  color: var(--color-primary);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.35rem;
}

.budget-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.portal-empty {
  text-align: center;
  color: #58605c;
  padding: 3rem;
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.portal-table th,
.portal-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--color-outline-variant);
  text-align: right;
}

.portal-table th { background: #f3f4f6; font-weight: 600; }

.users-table-wrap { max-height: 360px; overflow: auto; }

.swal-form label {
  display: block;
  text-align: right;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.swal-form .swal2-input,
.swal-form .swal2-select {
  margin: 0.35rem 0 0 !important;
  width: 100% !important;
}

/* ─── Budget app header extras ─── */
.btn-home-link {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}

.readonly-banner {
  background: #fff3cd;
  color: #856404;
  text-align: center;
  padding: 0.4rem;
  font-size: 0.82rem;
}

.user-role-chip {
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-inline-start: 0.5rem;
}

.portal-setup-banner {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  text-align: right;
}

/* ─── Budget editor: رجوع للرئيسية ─── */
.btn-back-link {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  font-weight: 600;
  gap: 0.35rem;
}

.btn-back-link:hover {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.sidebar-nav-back {
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-nav-back:hover {
  background: rgba(255, 255, 255, 0.18);
}
