:root {
    --primary: #1a5f4a;           /* أخضر داكن */
    --primary-light: #2d8a6e;
    --primary-dark: #0f3d2e;
    --secondary: #c9a227;          /* ذهبي */
    --background: #faf8f5;         /* بيج فاتح */
    --surface: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #5a5a5a;
    --border: #e0dcd5;
    --success: #2d8a6e;
    --warning: #c9a227;
    --danger: #c44536;
    --info: #4a90a4;
    --sidebar-width: 250px;
    --header-height: 60px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', sans-serif;
}

body {
    background-color: var(--background);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.logo-container {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-text {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--secondary);
}

.nav-links {
    list-style: none;
    padding: 20px 0;
    flex: 1;
}

.nav-item {
    margin-bottom: 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 25px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

.nav-link:hover, .nav-link.active {
    background-color: rgba(255,255,255,0.1);
    color: white;
    border-right: 4px solid var(--secondary);
}

.nav-link i {
    margin-left: 15px;
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    margin-right: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 30px;
    transition: margin-right 0.3s ease, width 0.3s ease;
}

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

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--surface);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    transition: transform 0.2s;
}

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

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-left: 15px;
}

.stat-icon.revenue { background: #e8f5e9; color: var(--success); }
.stat-icon.bookings { background: #e3f2fd; color: var(--info); }
.stat-icon.expenses { background: #ffebee; color: var(--danger); }
.stat-icon.net { background: #fff8e1; color: var(--warning); }

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.stat-info .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background: var(--surface);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    height: 350px;
    position: relative;
}

.chart-container canvas {
    max-width: 100% !important;
    max-height: 280px !important;
}

.chart-container h3 {
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Tables */
.table-container {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 30px;
}

.table-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

th, td {
    padding: 15px 20px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: #f8f9fa;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
}

tr:hover {
    background-color: #fcfcfc;
}

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

/* Forms */
.form-group {
    margin-bottom: 10px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

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

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}
.btn-primary:hover { background-color: var(--primary-light); }

.btn-secondary {
    background-color: #e0e0e0;
    color: var(--text-primary);
}
.btn-secondary:hover { background-color: #d0d0d0; }

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

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

.action-btns {
    display: flex;
    gap: 5px;
}

/* Filters */
.filters-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    background: var(--surface);
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.filter-item {
    flex: 1;
    min-width: 200px;
}

/* Villa Selection */
.villa-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 10px;
}

.villa-option {
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    transition: all 0.2s;
}

.villa-option:hover {
    border-color: var(--primary-light);
    background-color: #f0f7f4;
}

.villa-option.selected {
    border-color: var(--primary);
    background-color: #e8f5e9;
    color: var(--primary);
}

.villa-option i {
    font-size: 2rem;
    margin-bottom: 10px;
    display: block;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-villa-1 { background: #e3f2fd; color: #1565c0; }
.badge-villa-2 { background: #f3e5f5; color: #7b1fa2; }
.badge-villa-3 { background: #fff3e0; color: #ef6c00; }
.badge-villa-4 { background: #e8f5e9; color: #2e7d32; }

.badge-confirmed { background: #e8f5e9; color: #2e7d32; }
.badge-pending { background: #fff8e1; color: #f57c00; }
.badge-cancelled { background: #ffebee; color: #c62828; }

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 10px;
}

.tab {
    padding: 12px 25px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 2000;
}

.toast {
    background: white;
    min-width: 300px;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-top: 10px;
    display: flex;
    align-items: center;
    border-right: 4px solid transparent;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { border-right-color: var(--success); }
.toast.error { border-right-color: var(--danger); }
.toast.info { border-right-color: var(--info); }

.toast i { margin-left: 10px; font-size: 1.2rem; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.info i { color: var(--info); }

/* Pages visibility */
section[id^="page-"] {
    display: none;
    animation: fadeIn 0.3s ease;
}

section[id^="page-"].active {
    display: block;
}

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-right: 0; width: 100%; }
    .mobile-menu-btn { display: block !important; }
    .villa-selector { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
}

/* --- Mobile enhancements (keeps desktop look, improves touch & spacing) --- */
@media (max-width: 768px) {
  body { overflow-x: hidden; }
  .main-content { padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-title { font-size: 1.4rem; }
  .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 10px; }
  .actions .form-control { width: 100% !important; }
  #custom-period-inputs { width: 100%; display: flex; flex-wrap: wrap; gap: 10px; margin-right: 0 !important; }
  #custom-period-inputs input { width: 100% !important; margin: 0 !important; }
  .cards-grid { gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-info .value { font-size: 1.35rem; }
  .filters-bar { padding: 12px; gap: 10px; }
  .filter-item { min-width: 100%; }
  th, td { padding: 10px 12px; font-size: 0.92rem; }
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 8px 10px; }
  .action-btns { gap: 8px; }
  .chart-container { height: 320px; padding: 16px; }
  .chart-container canvas { max-height: 240px !important; }
  .table-header { padding: 14px 16px; }
  .table-container { border-radius: 14px; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; width: 100%; }
  .modal { width: 94%; max-height: 92vh; }
  .modal-header, .modal-body, .modal-footer { padding: 14px 16px; }
  .villa-selector { gap: 10px; }
  .villa-option { padding: 14px 10px; }
}

/* Extra small phones */
@media (max-width: 420px) {
  .page-title { font-size: 1.25rem; }
  .stat-icon { width: 44px; height: 44px; font-size: 1.25rem; }
  .stat-info .value { font-size: 1.2rem; }
  th, td { padding: 9px 10px; font-size: 0.88rem; }
}

/* Better focus visibility for keyboard users */
:focus-visible {
  outline: 3px solid rgba(26, 95, 74, 0.35);
  outline-offset: 2px;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* --- Mobile detection class (JS adds .is-mobile) --- */
body.is-mobile {
  -webkit-text-size-adjust: 100%;
}
body.is-mobile .page-title { font-size: 1.35rem; }
body.is-mobile th, body.is-mobile td { font-size: 0.9rem; padding: 10px 12px; }
body.is-mobile .btn { padding: 10px 14px; }
body.is-mobile .btn-sm { padding: 8px 10px; }
body.is-mobile .form-control { font-size: 0.95rem; padding: 9px 12px; }
body.is-mobile .sidebar { box-shadow: -2px 0 14px rgba(0,0,0,0.12); }


/* Searchable nationality picker */
.searchable-select{
    position: relative;
}
.searchable-select .form-control{
    padding-left: 36px;
    cursor: pointer;
    background: #fff;
}
.searchable-select .select-caret{
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    font-size: 14px;
}
.nationality-list{
    margin-top: 12px;
    max-height: 55vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}
.nationality-item{
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display:flex;
    align-items:center;
    justify-content: space-between;
}
.nationality-item:last-child{ border-bottom: none; }
.nationality-item:hover{ background: rgba(0,0,0,0.03); }
.nationality-item.active{ background: rgba(26,95,74,0.10); font-weight: 700; }
.nationality-empty{
    padding: 16px;
    color: var(--text-secondary);
    text-align: center;
}


/* --- Login / Roles (added) --- */
#login-overlay{
  position: fixed;
  inset: 0;
  background: rgba(250,248,245,0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 16px;
}
.login-card{
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  overflow: hidden;
}
.login-card .login-head{
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(26,95,74,0.08), transparent);
}
.login-card .login-head h2{
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary);
  font-weight: 800;
}
.login-card .login-body{ padding: 18px 20px; }
.login-meta{
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.login-actions{
  display:flex;
  gap:10px;
  justify-content: flex-end;
  margin-top: 14px;
  flex-wrap: wrap;
}
.login-error{
  margin-top: 10px;
  color: var(--danger);
  font-weight: 700;
  display:none;
}
.badge-role{
  display:inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(26,95,74,0.12);
  color: var(--primary);
  font-weight: 800;
  font-size: 0.8rem;
  margin-inline-start: 8px;
}
#app-shell.hidden{
  display:none;
}
