/* واتساب مبهم — واجهة الإدارة */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font-ar); background: var(--color-bg); color: var(--color-text); }
a { color: var(--secondary); text-decoration: none; }
a:hover { color: var(--secondary-deep); }

.app-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; background: var(--secondary-deep); color: #fff;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-brand { padding: 1.25rem; border-bottom: 1px solid rgba(255,255,255,.1); text-align: center; }
.sidebar-brand img { height: 48px; }
.sidebar-brand h1 { font-size: 1rem; margin: .5rem 0 0; font-weight: 700; }
.sidebar-brand p { font-size: .75rem; opacity: .7; margin: .25rem 0 0; }
.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.nav-section-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; opacity: .5; padding: .75rem 1.25rem .35rem; }
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1.25rem; color: rgba(255,255,255,.85); transition: var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { border-right: 3px solid var(--primary); }
.sidebar-user { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; opacity: 1; }
.sidebar-logout { width: 100%; justify-content: center; color: #fff !important; border-color: rgba(255,255,255,.3) !important; }
.sidebar-toggle { display: none; position: fixed; top: 1rem; left: 1rem; z-index: 1001; background: var(--secondary); color: #fff; border: none; border-radius: 8px; padding: .5rem; cursor: pointer; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 999; }
.sidebar-overlay.show { display: block; }
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.widget-card { background: var(--color-surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); }
.widget-card h3 { margin: 0 0 1rem; font-size: .95rem; display: flex; align-items: center; gap: .5rem; }
.health-item { display: flex; justify-content: space-between; padding: .4rem 0; font-size: .9rem; border-bottom: 1px solid #f3f4f6; }
.health-ok { color: #065f46; font-weight: 600; }
.health-bad { color: #991b1b; font-weight: 600; }
.notification-item { padding: .75rem; border-radius: var(--radius-sm); margin-bottom: .5rem; background: #f9fafb; border-right: 3px solid var(--primary); }
.notification-item.unread { background: color-mix(in srgb, var(--primary) 8%, #fff); }
.notification-item.danger { border-right-color: #dc2626; }
.progress-bar { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: .35rem; }
.progress-bar-fill { height: 100%; background: var(--secondary); border-radius: 999px; }

.template-builder { display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; }
.wa-preview { background: #e5ddd5; border-radius: var(--radius); padding: 1rem; min-height: 400px; }
.wa-preview-bubble { background: #fff; border-radius: 8px; padding: .75rem; max-width: 280px; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.wa-preview-header { font-weight: 700; margin-bottom: .5rem; }
.wa-preview-footer { font-size: .75rem; color: #667781; margin-top: .5rem; }
.wa-preview-btn { display: block; text-align: center; color: #00a5f4; padding: .5rem; border-top: 1px solid #f0f0f0; margin-top: .5rem; font-size: .85rem; }

.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-bar a { padding: .35rem .75rem; border-radius: 999px; font-size: .85rem; background: #f3f4f6; color: var(--color-text); }
.filter-bar a.active { background: var(--secondary); color: #fff; }

@media (max-width: 768px) {
  .sidebar-toggle { display: block; }
  .sidebar { position: fixed; top: 0; right: -280px; height: 100vh; z-index: 1000; transition: right .3s; width: 280px; }
  .sidebar.open { right: 0; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .template-builder { grid-template-columns: 1fr; }
  .inbox-layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.page-header {
  background: var(--color-surface); padding: 1rem 1.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--brand-dark) 8%, transparent);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.page-header h2 { margin: 0; font-size: 1.25rem; }
.page-content { padding: 1.5rem; flex: 1; }

.card {
  background: var(--color-surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 1.25rem; margin-bottom: 1rem;
}
.card-title { font-size: 1rem; font-weight: 700; margin: 0 0 1rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--color-surface); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow-sm); border-right: 4px solid var(--primary);
}
.stat-card.green { border-right-color: var(--secondary); }
.stat-card.wa { border-right-color: var(--whatsapp); }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--secondary-deep); }
.stat-label { font-size: .85rem; color: var(--color-text-muted); margin-top: .25rem; }

.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .5rem 1rem; border-radius: var(--radius-sm); border: none;
  font-family: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: var(--transition); text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--brand-dark); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-deep); }
.btn-outline { background: transparent; border: 1px solid var(--secondary); color: var(--secondary); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem 1rem; text-align: right; border-bottom: 1px solid color-mix(in srgb, var(--brand-dark) 6%, transparent); }
th { font-weight: 700; color: var(--color-text-muted); font-size: .85rem; }

.badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #f3f4f6; color: #6b7280; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .9rem; }
.form-control {
  width: 100%; padding: .6rem .85rem; border: 1px solid #d1d5db;
  border-radius: var(--radius-sm); font-family: inherit; font-size: .9rem;
  background: var(--color-surface);
}
.form-control:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--secondary) 15%, transparent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-check { display: flex; align-items: center; gap: .5rem; }

.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }

/* Inbox */
.inbox-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; min-height: 70vh; }
.conversation-list { background: var(--color-surface); border-radius: var(--radius); overflow: hidden; }
.conversation-item {
  display: block; padding: 1rem; border-bottom: 1px solid #f3f4f6;
  color: inherit; transition: var(--transition);
}
.conversation-item:hover, .conversation-item.active { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.conversation-item .name { font-weight: 700; }
.conversation-item .preview { font-size: .85rem; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item .time { font-size: .75rem; color: var(--color-text-muted); }
.unread-badge { background: var(--whatsapp); color: #fff; border-radius: 999px; padding: .1rem .45rem; font-size: .7rem; }

.chat-panel { background: var(--color-surface); border-radius: var(--radius); display: flex; flex-direction: column; }
.chat-header { padding: 1rem 1.25rem; border-bottom: 1px solid #f3f4f6; font-weight: 700; }
.chat-messages { flex: 1; padding: 1rem; overflow-y: auto; max-height: 60vh; }
.message { max-width: 75%; margin-bottom: .75rem; padding: .65rem 1rem; border-radius: var(--radius); font-size: .9rem; line-height: 1.5; }
.message.inbound { background: #f3f4f6; margin-left: auto; border-bottom-right-radius: 4px; }
.message.outbound { background: color-mix(in srgb, var(--whatsapp) 12%, #fff); margin-right: auto; border-bottom-left-radius: 4px; }
.message .meta { font-size: .7rem; color: var(--color-text-muted); margin-top: .25rem; }
.chat-compose { padding: 1rem; border-top: 1px solid #f3f4f6; display: flex; gap: .5rem; }
.chat-compose textarea { flex: 1; resize: none; min-height: 44px; }

/* Auth */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--secondary-deep), var(--secondary)); }
.auth-card { background: var(--color-surface); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-card .logo { text-align: center; margin-bottom: 1.5rem; }
.auth-card .logo img { height: 56px; }
.auth-card h1 { text-align: center; margin: 0 0 .25rem; font-size: 1.25rem; }
.auth-card .subtitle { text-align: center; color: var(--color-text-muted); font-size: .85rem; margin-bottom: 1.5rem; }

.code-block { background: #1a1a1a; color: #e5e7eb; padding: .75rem 1rem; border-radius: var(--radius-sm); font-family: monospace; font-size: .85rem; word-break: break-all; }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.1); font-size: .8rem; }

@media (max-width: 768px) {
  .app-layout { flex-direction: row; }
}
