/* =====================================================================
   Smart AAC Builder — Feuille de styles principale
   ===================================================================== */

:root {
  --primary:        #1F4E79;
  --primary-light:  #BDD7EE;
  --primary-pale:   #EAF2F8;
  --secondary:      #9E1F1F;
  --success:        #2E7D32;
  --warning:        #B27300;
  --danger:         #C62828;
  --gray-50:        #F8F9FA;
  --gray-100:       #F1F3F5;
  --gray-200:       #E9ECEF;
  --gray-300:       #DEE2E6;
  --gray-400:       #CED4DA;
  --gray-500:       #ADB5BD;
  --gray-600:       #6C757D;
  --gray-700:       #495057;
  --gray-800:       #343A40;
  --gray-900:       #212529;
  --radius:         8px;
  --radius-lg:      12px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,0.05);
  --shadow:         0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg:      0 8px 24px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Noto Sans Arabic", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--gray-900); margin-top: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.brand {
  display: flex; align-items: center; gap: 0.5rem;
  color: #fff; font-weight: 700; font-size: 1.1rem;
}
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 1.5rem; }
.topnav {
  display: flex; gap: 1.25rem;
  flex: 1;
  margin-left: 1rem;
}
.topnav a {
  color: rgba(255,255,255,0.85);
  font-weight: 500;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}
.topnav a:hover {
  color: #fff;
  text-decoration: none;
  border-bottom-color: rgba(255,255,255,0.5);
}
.user-menu { display: flex; align-items: center; gap: 0.75rem; }
.user-info { color: #fff; font-size: 0.9rem; line-height: 1.2; text-align: right; }
.user-info .user-role {
  display: block;
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
}

.main {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 2rem;
}

.footer {
  text-align: center;
  color: var(--gray-600);
  padding: 1.5rem;
  border-top: 1px solid var(--gray-200);
  margin-top: 2rem;
}

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}
.card-title {
  font-size: 1.1rem; font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--gray-800);
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #16385a; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-lg { padding: 0.8rem 1.4rem; font-size: 1.05rem; }
.btn-secondary { background: var(--gray-600); }
.btn-secondary:hover { background: var(--gray-700); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #1B5E20; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8E1F1F; }
.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-pale); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
  color: var(--gray-700);
  font-size: 0.92rem;
}
.form-control {
  display: block; width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,78,121,0.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table th, .table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--gray-200);
  text-align: left;
}
.table th {
  background: var(--gray-100);
  color: var(--gray-700);
  font-weight: 600;
  font-size: 0.9rem;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }

/* ---------- Alerts / Badges ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.alert-success { background: #E8F5E9; color: var(--success); border: 1px solid #C8E6C9; }
.alert-danger  { background: #FFEBEE; color: var(--danger);  border: 1px solid #FFCDD2; }
.alert-warning { background: #FFF8E1; color: var(--warning); border: 1px solid #FFECB3; }
.alert-info    { background: var(--primary-pale); color: var(--primary); border: 1px solid var(--primary-light); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--gray-200);
  color: var(--gray-700);
}
.badge-success { background: #C8E6C9; color: var(--success); }
.badge-warning { background: #FFE0B2; color: var(--warning); }
.badge-danger  { background: #FFCDD2; color: var(--danger); }
.badge-info    { background: var(--primary-light); color: var(--primary); }
.priority-1 { background: #FFCDD2; color: var(--danger); }
.priority-2 { background: #FFE0B2; color: var(--warning); }
.priority-3 { background: var(--gray-200); color: var(--gray-700); }

/* ---------- Login / Register ---------- */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #16385a 100%);
  padding: 1rem;
}
.auth-card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 0.25rem;
}
.auth-card .subtitle {
  text-align: center;
  color: var(--gray-600);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.auth-card .btn { width: 100%; justify-content: center; }
.auth-card .auth-footer {
  text-align: center;
  margin-top: 1rem;
  color: var(--gray-600);
  font-size: 0.9rem;
}

/* ---------- Board editor ---------- */
.editor-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}
.board-grid {
  display: grid;
  gap: 6px;
  background: var(--gray-100);
  padding: 8px;
  border-radius: var(--radius);
  border: 2px dashed var(--gray-300);
}
.board-cell {
  aspect-ratio: 1;
  background: #fff;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  text-align: center;
  padding: 0.4rem;
  transition: transform 0.1s, box-shadow 0.15s;
  position: relative;
  user-select: none;
  min-height: 80px;
}
.board-cell:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.board-cell.empty {
  background: var(--gray-100);
  border-style: dashed;
  color: var(--gray-500);
  font-size: 0.8rem;
}
.board-cell .cell-icon {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}
.board-cell .cell-img {
  max-width: 70%; max-height: 70%;
  object-fit: contain;
  margin-bottom: 0.25rem;
}
.board-cell .cell-text {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}
.board-cell .cell-remove {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--gray-300);
  width: 22px; height: 22px;
  border-radius: 50%;
  display: none;
  align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--danger);
}
.board-cell:hover .cell-remove { display: flex; }
.board-cell .cell-remove:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- Child mode (large, accessible) ---------- */
.child-mode {
  background: #FAFAFC;
  min-height: 100vh;
}
.child-header {
  background: #fff;
  padding: 1rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.child-header h2 { margin: 0; color: var(--primary); }
.child-board {
  display: grid;
  gap: 12px;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}
.child-cell {
  aspect-ratio: 1;
  background: #fff;
  border: 3px solid var(--gray-300);
  border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 1rem;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
  min-height: 140px;
}
.child-cell:hover {
  transform: scale(1.04);
  box-shadow: var(--shadow-lg);
}
.child-cell.active {
  border-color: var(--primary);
  background: var(--primary-pale);
  transform: scale(1.06);
}
.child-cell .cell-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.child-cell .cell-img { max-width: 65%; max-height: 65%; object-fit: contain; margin-bottom: 0.5rem; }
.child-cell .cell-text {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  font-family: "Noto Sans Arabic", "Segoe UI", sans-serif;
}
.child-toast {
  position: fixed;
  top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.9);
  background: rgba(31, 78, 121, 0.95);
  color: #fff;
  padding: 1.5rem 3rem;
  border-radius: var(--radius-lg);
  font-size: 3rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}
.child-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin-top: 0; color: var(--primary); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1rem;
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--gray-600); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; gap: 0.5rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; }

[dir="rtl"] { direction: rtl; }

/* ---------- Stat cards ---------- */
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1rem;
  text-align: center;
}
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}
.stat-label { color: var(--gray-600); font-size: 0.9rem; }

@media (max-width: 700px) {
  .topbar-inner { flex-wrap: wrap; }
  .topnav { width: 100%; margin-left: 0; gap: 1rem; flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
}
