/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --bg: #f0f9ff;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-light: #64748b;
  --border: #e2e8f0;
  --border-focus: #0284c7;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --radius: 8px;
  --radius-sm: 5px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* === LAYOUT === */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* === LOGIN === */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #0c4a6e 60%, #0284c7 100%);
  min-height: 100vh;
}

.login-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

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

.login-logo .logo-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 32px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  font-size: 13px;
  color: var(--text-light);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 8px;
  min-height: 20px;
}

/* === NAVBAR === */
.navbar {
  background: linear-gradient(90deg, #0f172a, #0369a1);
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  flex-wrap: nowrap;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.nav-logo {
  font-size: 22px;
}

.nav-title {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.nav-menu {
  display: flex;
  gap: 2px;
  flex: 1;
  justify-content: center;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-menu::-webkit-scrollbar { display: none; }

.nav-item {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: all .15s;
}

.nav-item:hover { background: rgba(255,255,255,.1); color: white; }
.nav-item.active { background: rgba(255,255,255,.2); color: white; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.nav-username {
  font-size: 13px;
  color: rgba(255,255,255,.8);
}

.nav-role {
  font-size: 11px;
  background: rgba(255,255,255,.15);
  padding: 2px 8px;
  border-radius: 20px;
  color: rgba(255,255,255,.9);
  font-weight: 600;
  text-transform: uppercase;
}

/* === MAIN CONTENT === */
.main-content {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

.page { display: none; }
.page.active { display: block; }

/* === PAGE HEADER === */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}

/* === CARDS GRID === */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border: 1px solid var(--border);
  transition: box-shadow .15s;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.card-title {
  font-weight: 600;
  font-size: 15px;
}

.card-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 10px;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* === TABLE === */
.table-wrap {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead { background: #f8fafc; }

th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* === FORMS === */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: white;
  color: var(--text);
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(2,132,199,.12);
}

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

.checkbox-group {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  border: 1px solid #bae6fd;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  accent-color: var(--primary);
}

.checkbox-group label {
  margin: 0;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover:not(:disabled) { background: #15803d; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-light);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text); }

.btn-sm {
  padding: 5px 11px;
  font-size: 13px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 12px;
}

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

.btn-icon {
  padding: 6px 8px;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-light);
}
.btn-icon:hover:not(:disabled) { background: #f1f5f9; }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-admin { background: #dbeafe; color: #1d4ed8; }
.badge-operator { background: #d1fae5; color: #065f46; }
.badge-administrateur { background: #ede9fe; color: #5b21b6; }
.badge-societaire { background: #e0f2fe; color: #0369a1; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-error { background: var(--danger-light); color: var(--danger); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-partial { background: #fef9c3; color: #854d0e; }

/* === CONSENT INDICATOR === */
.consent-ok { color: var(--success); font-weight: 600; }
.consent-no { color: var(--danger); font-weight: 600; }

/* === SEARCH BAR === */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 380px;
}

/* === SMS SEND PANEL === */
.sms-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
  max-width: 640px;
}

.recipients-preview {
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-light);
  border: 1px solid var(--border);
  margin-top: 8px;
}

.char-counter {
  text-align: right;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

.char-counter.warn { color: var(--warning); }
.char-counter.over { color: var(--danger); }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p { font-size: 15px; }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-lg { max-width: 700px; }

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

.modal-header h3 { font-size: 17px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-light);
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
}
.modal-close:hover { background: #f1f5f9; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

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

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  transition: opacity .3s;
  max-width: 340px;
}

.toast.hidden { display: none; }
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }

/* === HISTORY LOG === */
.log-message {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === MEMBER PICKER === */
.mp-search {
  width: 100%;
  margin-bottom: 6px;
}

.mp-list {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  background: white;
}

.mp-row {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
  user-select: none;
  transition: background .1s;
}

.mp-row:last-child { border-bottom: none; }
.mp-row:hover:not(.mp-selected) { background: #f0f9ff; }
.mp-row.mp-selected { background: var(--primary); color: white; }

.mp-count {
  font-size: 12px;
  color: var(--text-light);
  margin: 6px 0;
  min-height: 18px;
}

.mp-count.has-selection { color: var(--primary); font-weight: 600; }

/* === GROUP DETAIL === */
.group-members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.group-member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* === SECTION TABS === */
.section-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.section-tab {
  padding: 8px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}

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

/* === ADMIN ONLY HIDDEN === */
body:not(.is-admin) .admin-only { display: none !important; }

/* === RESPONSIVE === */
@media (max-width: 640px) {
  .navbar { padding: 0 10px; }
  .nav-title { display: none; }
  .nav-item { padding: 6px 10px; font-size: 13px; }
  .nav-username { display: none; }
  .main-content { padding: 16px 10px; }
  .cards-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
  .modal { max-width: 100%; margin: 0; border-radius: 12px 12px 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .sms-panel { padding: 16px; }
}
