/* ============================================================
   Webman — Design system (legifrance-inspired)
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */

:root {
  --primary:        #2563eb;
  --primary-dark:   #1e40af;
  --primary-light:  #dbeafe;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --success:        #10b981;
  --success-light:  #dcfce7;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;

  --text:           #111827;
  --text-muted:     #6b7280;
  --bg:             #f1f5f9;
  --bg-card:        #ffffff;
  --border:         #c4c9d4;
  --border-light:   #e5e7eb;
  --bg-hover:       #f8fafc;

  --sidebar-bg:     #0f172a;
  --sidebar-active: #1d4ed8;
  --sidebar-text:   rgba(255,255,255,.65);
  --sidebar-muted:  rgba(255,255,255,.3);

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Consolas', 'Monaco', 'Courier New', monospace;

  --radius-sm: .375rem;
  --radius:    .5rem;
  --radius-lg: .75rem;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 1px 4px rgba(0,0,0,.07);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);

  /* Aliases de compatibilité (utilisés dans les templates inline) */
  --color-primary:      var(--primary);
  --color-danger:       var(--danger);
  --color-success:      var(--success);
  --color-warning:      var(--warning);
  --color-text:         var(--text);
  --color-text-muted:   var(--text-muted);
  --color-bg:           var(--bg);
  --color-bg-secondary: var(--bg-hover);
  --color-border:       var(--border);
  --color-surface:      var(--bg-card);
  --color-bg-alt:       #0d1117;
}

[data-theme="dark"] {
  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --bg:           #0d1521;
  --bg-card:      #1e293b;
  --border:       #334155;
  --border-light: #273549;
  --bg-hover:     #263347;
}

/* ── Reset ─────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: .9375rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4, h5 { margin: 0 0 .75rem; font-weight: 700; line-height: 1.25; color: var(--text); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 1rem; }

code {
  font-family: var(--mono);
  background: var(--primary-light);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .82em;
  color: var(--primary-dark);
}
[data-theme="dark"] code { background: rgba(37,99,235,.25); color: #93c5fd; }

/* ── App shell ─────────────────────────────────────────────── */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  scrollbar-width: none;
}
.app-sidebar::-webkit-scrollbar { display: none; }

.sidebar-hd {
  padding: 18px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #ffffff;
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: .01em;
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; color: #fff; }
.sidebar-brand svg { color: #60a5fa; flex-shrink: 0; }

.sidebar-theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,.07);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: rgba(255,255,255,.5);
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sidebar-theme-btn:hover { background: rgba(255,255,255,.12); color: white; }

#icon-moon { display: none; }
[data-theme="dark"] #icon-sun  { display: none; }
[data-theme="dark"] #icon-moon { display: block; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-section {
  display: block;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--sidebar-muted);
  padding: 14px 10px 5px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background .12s, color .12s;
  margin-bottom: 1px;
}
.sidebar-link svg { flex-shrink: 0; opacity: .7; }
.sidebar-link:hover { background: rgba(255,255,255,.08); color: white; text-decoration: none; }
.sidebar-link:hover svg { opacity: 1; }
.sidebar-link.active { background: var(--sidebar-active); color: white; }
.sidebar-link.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.07);
  padding: 10px 8px 14px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 4px;
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  background: var(--sidebar-active);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.sidebar-user-info { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.sidebar-user-email {
  font-size: .75rem;
  color: rgba(255,255,255,.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: .68rem;
  color: var(--sidebar-muted);
  text-transform: capitalize;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(239,68,68,.6);
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 500;
  transition: background .12s, color .12s;
  text-align: left;
}
.sidebar-logout:hover { background: rgba(239,68,68,.1); color: #f87171; }

/* ── Main area ─────────────────────────────────────────────── */

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-topbar {
  display: none;
  align-items: center;
  align-self: stretch;
  gap: 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 11px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-topbar-title {
  font-weight: 600;
  font-size: .95rem;
  color: var(--text);
}

.app-burger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: color .12s;
}
.app-burger:hover { color: var(--text); }

.app-content {
  padding: 28px 32px;
  flex: 1;
  width: 100%;
  max-width: 960px;
}

.app-content--center {
  max-width: 440px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Login page : centrage vertical dans l'écran entier */
.app-main:only-child .app-content--center {
  min-height: 100vh;
}

.app-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}
.app-overlay.visible { display: block; }

/* ── Page header ───────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 2px;
}

.page-header p {
  font-size: .875rem;
  color: var(--text-muted);
  margin: 0;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Cards ─────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: visible;
  margin-bottom: 20px;
  padding: 20px;
}

.card-title {
  display: block;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  margin: -20px -20px 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}

.card-body { margin: -20px; padding: 20px; }

/* ── Dashboard grid ────────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}

.dashboard-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .12s;
}

.dashboard-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 4px 16px rgba(37,99,235,.1);
  transform: translateY(-1px);
  text-decoration: none;
  color: var(--text);
}

.dashboard-card-icon {
  width: 40px;
  height: 40px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
}
[data-theme="dark"] .dashboard-card-icon { background: rgba(37,99,235,.2); color: #60a5fa; }
.dashboard-card-icon svg { width: 20px; height: 20px; }

.dashboard-card-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.dashboard-card-desc {
  font-size: .78rem;
  color: var(--text-muted);
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: .45rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; color: white; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }

.btn-danger {
  background: var(--danger-light);
  color: #991b1b;
  border-color: #fca5a5;
}
.btn-danger:hover { background: var(--danger); color: white; border-color: var(--danger); text-decoration: none; }

.btn-sm {
  padding: .28rem .65rem;
  font-size: .8rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: .65rem 1.5rem;
  font-size: 1rem;
}

/* ── Forms ─────────────────────────────────────────────────── */

.form-group { margin-bottom: 1.1rem; }

label {
  display: block;
  margin-bottom: .3rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  display: block;
  width: 100%;
  padding: .48rem .75rem;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-control::placeholder { color: var(--text-muted); opacity: .7; }

textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control    { cursor: pointer; }

small, .form-control + small {
  display: block;
  margin-top: .3rem;
  font-size: .78rem;
  color: var(--text-muted);
}

/* ── Password toggle ──────────────────────────────────────── */

.password-wrap { position: relative; }

.password-wrap .form-control { padding-right: 2.5rem; }

.password-toggle {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  padding: .25rem;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color .15s, background-color .15s;
}

.password-toggle:hover  { color: var(--text); background: var(--bg-hover, rgba(0,0,0,.05)); }
.password-toggle:focus  { outline: 2px solid var(--primary, #2563eb); outline-offset: 1px; }

/* ── Tables ────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

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

.table th {
  background: var(--bg-hover);
  padding: 10px 14px;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  color: var(--text);
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-hover); }

/* ── Alerts ────────────────────────────────────────────────── */

.alert {
  padding: .875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  margin-bottom: 16px;
  font-size: .875rem;
  line-height: 1.5;
}

.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-success { background: var(--success-light); color: #065f46; border-color: #6ee7b7; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--primary-light); color: #1e40af; border-color: #93c5fd; }

/* ── Badges ────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .55rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-blue   { background: var(--primary-light); color: var(--primary-dark); }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-green  { background: var(--success-light); color: #065f46; }
.badge-red    { background: var(--danger-light);  color: #991b1b; }
.badge-yellow { background: var(--warning-light); color: #92400e; }

[data-theme="dark"] .badge-gray { background: rgba(255,255,255,.1); color: var(--text-muted); }
[data-theme="dark"] .badge-blue { background: rgba(37,99,235,.25); color: #93c5fd; }

/* ── Login / guest pages ───────────────────────────────────── */

.app-content--center .card {
  box-shadow: var(--shadow-md);
}

/* ── Code editor (nginx/config textarea) ───────────────────── */

textarea[spellcheck="false"][name="config"] {
  background: #0d1117 !important;
  color: #e2e8f0 !important;
  caret-color: #60a5fa;
}

/* ── Details/summary used as toggle buttons ────────────────── */

details > summary { cursor: pointer; user-select: none; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* Confirmation panels inside cards */
.confirm-panel {
  margin-top: .75rem;
  padding: 1rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

hr { border: none; border-top: 1px solid var(--border-light); margin: 1.25rem 0; }

.text-muted { color: var(--text-muted); font-size: .875rem; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Site detail — info grid ───────────────────────────────── */

.site-info-grid { margin: 0; padding: 0; }

.site-info-row {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.site-info-row:last-child { border-bottom: none; }

.site-info-row dt {
  width: 120px;
  flex-shrink: 0;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}

.site-info-row dd {
  margin: 0;
  font-size: .9rem;
  color: var(--text);
}

/* ── Site detail — action rows ─────────────────────────────── */

.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border-light);
  transition: background .1s;
}
.action-row:last-of-type { border-bottom: none; }

.action-row-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.action-row-body {
  flex: 1;
  min-width: 0;
}
.action-row-body strong {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1px;
}
.action-row-body span {
  font-size: .775rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.action-row-cta { flex-shrink: 0; }

.action-row--danger {
  border-top: 1px solid var(--border-light);
}
.action-row--danger .action-row-icon {
  background: var(--danger-light);
  color: #b91c1c;
}
.action-row--danger .action-row-body strong { color: #b91c1c; }

/* ── Input group (prefix/suffix) ──────────────────────────── */

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group-prefix {
  display: flex;
  align-items: center;
  padding: .48rem .75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: .875rem;
  font-family: var(--mono);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.input-group .form-control {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    transition: left .22s ease;
    height: 100vh;
  }
  .app-sidebar.open { left: 0; }
  .app-topbar { display: flex; }
  .app-content { padding: 16px; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .page-header { margin-bottom: 16px; }
}

@media (max-width: 480px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .app-content--center { padding: 24px 16px; }
}
