/* =============================================================================
   DRM Admin — Design System
   ============================================================================= */

*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }

:root {
  --primary:      #0056b3;
  --accent:       #0078d4;
  --success:      #28a745;
  --warning:      #e0a800;
  --danger:       #dc3545;
  --muted:        #6c757d;
  --bg:           #f4f6f9;
  --surface:      #ffffff;
  --border:       #dee2e6;
  --text:         #212529;
  --text-muted:   #6c757d;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.07);
  --shadow-md:    0 2px 8px rgba(0,0,0,.10);
  --shadow-lg:    0 4px 16px rgba(0,0,0,.14);
  --radius:       6px;
  --radius-sm:    4px;
  /* Aliases for backward-compat with older inline styles */
  --primary-color:    #0056b3;
  --secondary-color:  #4a4a4a;
  --accent-color:     #0078d4;
  --success-color:    #28a745;
  --warning-color:    #e0a800;
  --error-color:      #dc3545;
  --background-color: #f4f6f9;
}

/* =============================================================================
   Body + background watermark
   ============================================================================= */

body {
  min-height: 100vh;
  background-color: var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("/web/static/images/cea_logo.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  pointer-events: none;
  z-index: -1;
  opacity: 0.04;
}

/* =============================================================================
   Navigation
   ============================================================================= */

nav.container {
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem !important;
  padding: 0.5rem 1rem;
}

nav.container ul {
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
  gap: 0.25rem;
}

nav.container ul li {
  list-style: none;
  display: inline-block;
  margin-right: 0.6rem;
}

/* =============================================================================
   Page header — responsive title + action bar
   ============================================================================= */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header-title { flex: 1 1 0; min-width: 0; }
.page-header-title h1 { margin-bottom: 0.25rem; }
.page-header-title p  { margin: 0; }

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

.page-header-actions > button,
.page-header-actions > .btn,
.page-header-actions > a.primary,
.page-header-actions > a.secondary,
.page-header-actions > a.success,
.page-header-actions > a.danger,
.page-header-actions > a.contrast {
  min-height: 2.45rem;
  height: 2.45rem;
  margin: 0;
  padding: 0 1rem;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  line-height: 1.4;
  border-width: 2px;
}

/* =============================================================================
   Cards / Articles
   ============================================================================= */

article {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--primary);
  max-width: 100%;
}

dialog article { border-left: 2px solid var(--primary); }

article h1,
article h2,
article h3 {
  color: var(--primary);
  margin-top: 0;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
}

article h1 { font-size: 1.75rem; border-bottom: 2px solid var(--primary); }
article h2 { font-size: 1.3rem;  border-bottom: 1px solid var(--border); }
article h3 { font-size: 1.05rem; border-bottom: none; margin-bottom: 0.5rem; }

/* =============================================================================
   Tables
   ============================================================================= */

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
}

thead {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
}

thead th {
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.12s;
}

tbody tr:hover { background-color: rgba(0,86,179,.04); }

tbody td {
  padding: 0.6rem 0.85rem;
  vertical-align: middle;
  text-align: left;
  font-size: 0.85rem;
}

/* Two-column key/value info tables */
.info-table { margin: 0; }
.info-table tbody tr:hover { background: none; }
.info-table td:first-child {
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  width: 11rem;
}

/* Override Pico's text-align: center !important on th/td */
th, td { text-align: left !important; }

/* Centrer uniquement les colonnes badge / icônes */
.col-center { text-align: center !important; }

/* =============================================================================
   Button system — works on <button> and <a>
   ============================================================================= */

button,
.btn,
a.primary, a.secondary, a.success, a.danger, a.contrast {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.14s, border-color 0.14s, color 0.14s, box-shadow 0.14s;
  white-space: nowrap;
  line-height: 1.4;
  vertical-align: middle;
  box-sizing: border-box;
}

/* Primary */
button.primary, a.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
button.primary:hover, a.primary:hover {
  background: #004494;
  border-color: #004494;
  box-shadow: 0 2px 6px rgba(0,86,179,.3);
  color: white;
}

/* Secondary */
button.secondary, a.secondary {
  background: white;
  color: var(--primary);
  border-color: var(--primary);
}
button.secondary:hover, a.secondary:hover {
  background: var(--primary);
  color: white;
}

/* Success */
button.success, a.success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}
button.success:hover, a.success:hover {
  background: #218838;
  border-color: #218838;
  color: white;
}

/* Danger / contrast */
button.contrast, button.danger, a.contrast, a.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
button.contrast:hover, button.danger:hover,
a.contrast:hover, a.danger:hover {
  background: #b02030;
  border-color: #b02030;
  color: white;
}

/* Small variant */
button.btn-sm, a.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.78rem; }

/* Icon-only action buttons inside tables */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  padding: 0;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  border: none !important;
  outline: none !important;
  cursor: pointer;
  transition: filter 0.12s;
  background: none;
  line-height: 1;
  box-shadow: none !important;
  /* Neutralise le margin-bottom que Pico ajoute aux <button> : sans cela un
     bouton d'action (ex. supprimer) est décalé verticalement par rapport aux
     liens <a> voisins dans .action-buttons. */
  margin: 0;
  vertical-align: middle;
}

.action-btn.view     { background: rgba(0,86,179,.10); color: var(--primary); }
.action-btn.edit     { background: rgba(224,168,0,.18); color: #7d5a00; }
.action-btn.resolve  { background: rgba(40,167,69,.12); color: #1a6e30; }
.action-btn.download { background: rgba(0,120,212,.10); color: var(--accent); }
.action-btn.delete   { background: rgba(220,53,69,.12); color: var(--danger); }
.action-btn:hover    { filter: brightness(0.82); }

.action-buttons { display: flex; gap: 0.25rem; align-items: center; }
.company-row-actions { justify-content: flex-start; }

.dashboard-actions-cell {
  vertical-align: middle !important;
}

.dashboard-row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  height: 2rem;
  min-height: 2rem;
  margin: 0;
}

.dashboard-row-actions form {
  display: contents;
  margin: 0;
}

/* =============================================================================
   Champ GUID masqué (modal « Nouveau logiciel ») — gabarit fantôme xxxx
   ============================================================================= */

.guid-field { position: relative; }

.guid-field input,
.guid-ghost {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.93rem;
  letter-spacing: 1px;
  padding: 0.55rem 0.75rem;
  border: 2px solid transparent;
  box-sizing: border-box;
  width: 100%;
}

/* L'input est au-dessus, fond transparent pour laisser voir le gabarit. */
.guid-field input { position: relative; z-index: 1; background: transparent; }

/* Gabarit fantôme derrière : même métrique que l'input, non interactif. */
.guid-ghost {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  color: var(--text-muted);
  white-space: pre;
  overflow: hidden;
}
/* La portion déjà saisie occupe la place exacte mais reste invisible : c'est le
   texte réel de l'input (au-dessus) qui s'affiche à cet endroit. */
.guid-ghost .filled { visibility: hidden; }

.guid-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; margin-bottom: 0.75rem; }
.guid-actions button { flex: 1; margin: 0; }

/* Crash filter form */
.crash-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.crash-filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-start;
  padding-bottom: 0;
}

.crash-filter-actions > button,
.crash-filter-actions > a {
  display: inline-flex !important;
  width: 8.9rem;
  min-width: 8.9rem;
  height: 3rem !important;
  min-height: 3rem !important;
  margin: 0 !important;
  padding: 0 1rem !important;
  justify-content: center;
  align-items: center;
  line-height: 1.2 !important;
  box-sizing: border-box;
}

.notification-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.notification-header-actions form {
  display: contents;
  margin: 0;
}

.notification-header-actions button,
.notification-header-actions a {
  display: inline-flex !important;
  width: 15.5rem;
  min-width: 15.5rem;
  height: 3.35rem !important;
  min-height: 3.35rem !important;
  margin: 0 !important;
  padding: 0 1rem !important;
  justify-content: center;
  align-items: center;
  line-height: 1.2 !important;
  box-sizing: border-box;
}

.notification-body {
  white-space: pre-wrap;
  line-height: 1.6;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0,86,179,.035);
  color: var(--text);
}

/* =============================================================================
   Badges
   ============================================================================= */

.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.badge.success,  .badge.resolved   { background: rgba(40,167,69,.14);  color: #1a6e30; }
.badge.warning,  .badge.medium     { background: rgba(224,168,0,.18);   color: #7d5a00; }
.badge.error,    .badge.unresolved { background: rgba(220,53,69,.14);   color: #b02030; }
.badge.info                        { background: rgba(0,120,212,.12);   color: #0056b3; }
.badge.secondary                   { background: rgba(74,74,74,.12);    color: #4a4a4a; }
.badge.critical                    { background: rgba(220,53,69,.22);   color: #7a0000; font-weight: 800; }
.badge.high                        { background: rgba(220,120,53,.18);  color: #8a3000; }
.badge.low                         { background: rgba(40,167,69,.12);   color: #1a6e30; }
.badge.acknowledged                { background: rgba(224,168,0,.18);   color: #7d5a00; }

/* =============================================================================
   Forms
   ============================================================================= */

form { display: block; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--secondary-color);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  transition: border-color 0.14s, box-shadow 0.14s;
  box-sizing: border-box;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,86,179,.12);
}

/* =============================================================================
   Stat cards
   ============================================================================= */

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform 0.14s, box-shadow 0.14s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 8.3rem;
  margin: 0;
  /* Les cartes cliquables sont des <button> : autoriser le retour à la ligne
     du libellé (comme les cartes <div>) au lieu du white-space:nowrap hérité. */
  white-space: normal;
}

button.stat-card {
  width: 100%;
  color: inherit;
  cursor: pointer;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card h3 {
  font-size: 2rem;
  color: var(--primary);
  margin: 0.35rem 0;
  font-weight: 700;
  border: none;
  padding: 0;
}

.stat-card p {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: normal;
  overflow-wrap: break-word;
}

/* =============================================================================
   Machine detail actions
   ============================================================================= */

.activation-actions {
  display: flex;
  align-items: center;
}

.activation-actions form {
  display: inline-flex;
  margin: 0;
}

.activation-revoke-btn {
  min-height: 1.45rem;
  height: 1.45rem;
  margin: 0;
  padding: 0 0.55rem;
  font-size: 0.72rem;
  line-height: 1;
  border-width: 1px;
}

.machine-page-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.machine-action-slot {
  display: inline-flex;
  margin: 0;
}

.machine-page-actions .machine-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12rem;
  height: 2.75rem;
  min-height: 2.75rem;
  margin: 0;
  padding: 0 0.85rem;
  font-size: 0.88rem;
  line-height: 1.2;
}

.machine-list-actions {
  justify-content: flex-start;
}

.machine-delete-dialog article {
  max-width: 38rem;
}

.machine-delete-warning {
  border-left: 4px solid var(--danger);
  background: rgba(220,53,69,.08);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
}

.machine-delete-warning p {
  margin: 0.55rem 0 0;
}

.machine-delete-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.machine-delete-footer button {
  margin: 0;
}

/* =============================================================================
   Tabs
   ============================================================================= */

[role="tablist"] {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
  padding: 0;
  list-style: none;
}

[role="tablist"] li { list-style: none; padding: 0; }

[role="tab"] {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  transition: color 0.14s, border-color 0.14s;
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: -2px;
}

[role="tab"]:hover { color: var(--primary); }
[role="tab"].tab-active,
[role="tab"][aria-selected="true"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

/* =============================================================================
   Loading
   ============================================================================= */

.loading-spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid rgba(0,86,179,.15);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin .9s linear infinite;
}

.loading-spinner-sm { width: 14px; height: 14px; border-width: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
  gap: 0.75rem;
}

/* =============================================================================
   Utilities
   ============================================================================= */

.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 0.85rem; }
.mono        { font-family: Consolas, "Courier New", monospace; }
.mt-1        { margin-top: 1rem; }
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 900px) {
  .dashboard-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  article { padding: 1rem; }

  .dashboard-stats { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .stat-card h3    { font-size: 1.6rem; }

  .page-header         { flex-direction: column; align-items: stretch; }
  .page-header-actions { justify-content: flex-start; flex-wrap: wrap; }

  nav.container ul li { margin-right: 0.3rem; }

  button, .btn, a.primary, a.secondary, a.success, a.danger, a.contrast {
    font-size: 0.82rem;
    padding: 0.4rem 0.75rem;
  }
}

@media (max-width: 480px) {
  .dashboard-stats { grid-template-columns: 1fr 1fr; }
}
