:root {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-sidebar: #121a24;
    --border: #2a3544;
    --text: #e8edf4;
    --text-muted: #8b9cb3;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

a:hover {
    text-decoration: underline;
}

/* Layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    flex-shrink: 0;
}

.sidebar-brand a {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    text-decoration: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 2rem;
    flex: 1;
}

.sidebar-nav a {
    color: var(--text-muted);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--bg-card);
    color: var(--text);
}

.sidebar-user {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-name {
    font-weight: 600;
}

.admin-main {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-x: auto;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(145deg, #0f1419 0%, #1a2744 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.login-card h1 {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
}

.login-subtitle {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
}

/* Typography */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
}

.flex-between {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.text-muted {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    background: transparent;
    font-family: inherit;
}

.btn:hover {
    text-decoration: none;
    filter: brightness(1.08);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: #fff;
}

.btn-secondary {
    background: #334155;
    color: #fff;
}

.btn-outline {
    border-color: var(--border);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.page-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Forms */
.form label {
    display: block;
    margin-bottom: 1rem;
}

.form label span {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form input,
.form select,
.form textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}

.field-hint {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.form-card {
    max-width: 560px;
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.inline-form {
    display: inline;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid var(--success);
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-active {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.status-inactive {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
}

.status-maintenance {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.priority-basse {
    background: #334155;
    color: #cbd5e1;
}

.priority-normale {
    background: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.priority-haute {
    background: rgba(245, 158, 11, 0.25);
    color: #fcd34d;
}

.priority-urgente {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.badge-role {
    background: var(--border);
    color: var(--text-muted);
    width: fit-content;
}

/* Project grid */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.project-card-screenshot {
    margin-top: 0.75rem;
}
.project-card-screenshot img {
    width: 100%;
    height: auto;
    max-height: 160px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.project-card h2 {
    margin: 0;
    font-size: 1.1rem;
}

.project-domain {
    color: var(--primary);
    font-size: 0.9rem;
    margin: 0.35rem 0;
}

.project-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.project-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.stat-pill {
    font-size: 0.8rem;
    background: var(--bg);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.stat-muted {
    color: var(--text-muted);
}

.project-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-card);
    color: var(--text-muted);
    font-weight: 600;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* Kanban */
.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.filters-bar label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.filters-bar select {
    min-width: 180px;
    padding: 0.45rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.kanban-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(240px, 1fr));
    gap: 1rem;
    align-items: start;
}

.kanban-column {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 200px;
}

.kanban-column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.kanban-column-header h2 {
    margin: 0;
    font-size: 0.95rem;
}

.kanban-count {
    background: var(--bg);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8rem;
}

.kanban-cards {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.kanban-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

.kanban-card h3 {
    margin: 0.35rem 0;
    font-size: 0.95rem;
}

.kanban-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.kanban-project {
    color: var(--text-muted);
}

.kanban-desc,
.kanban-due,
.kanban-assigned {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0.25rem 0;
}

.kanban-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
    align-items: center;
}

.status-select {
    font-size: 0.75rem;
    padding: 0.25rem;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* AI */
.form-group-block {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.ai-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.ai-result-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.ai-result-panel h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.ai-result-text {
    width: 100%;
    min-height: 280px;
    padding: 0.75rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    resize: vertical;
}

.recent-generations {
    margin-top: 2rem;
}

.draft-list {
    list-style: none;
    padding: 0;
}

.draft-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Responsive */
@media (max-width: 1024px) {
    .kanban-board {
        grid-template-columns: repeat(2, 1fr);
    }
    .ai-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    .admin-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        margin-top: 0;
        margin-left: 1rem;
    }
    .sidebar-user {
        margin-top: 0;
        border: none;
        flex-direction: row;
        align-items: center;
    }
    .kanban-board {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   Navigation — icônes + badge non-lus
   ========================================================================= */

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav a svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-nav a:hover svg,
.sidebar-nav a.active svg {
    opacity: 1;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    line-height: 1.4;
}

/* =========================================================================
   Dashboard — améliorations cards
   ========================================================================= */

.project-card-title {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.project-domain-badge {
    font-size: 0.75rem;
    color: var(--primary);
    font-family: monospace;
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    text-decoration: none;
    color: var(--text);
    cursor: default;
}

.stat-pill-alert {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    cursor: pointer;
    transition: background 0.15s;
}

.stat-pill-alert:hover {
    background: rgba(239, 68, 68, 0.25);
    text-decoration: none;
}

.badge-unread {
    background: var(--danger);
    color: #fff;
    text-decoration: none;
}

.badge-unread:hover {
    opacity: 0.85;
    text-decoration: none;
}

.btn-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 0.3rem;
    border-radius: 999px;
    line-height: 1;
}

/* =========================================================================
   Hub Messages — layout deux colonnes
   ========================================================================= */

.msg-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    height: calc(100vh - 130px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.msg-sidebar {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-card);
}

.msg-filters {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.msg-filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.msg-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    flex: 1;
    min-width: 100px;
}

.msg-select-inline {
    background: var(--bg);
    font-size: 0.82rem;
    flex: none;
}

.msg-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.msg-empty {
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.msg-item {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}

.msg-item:hover {
    background: rgba(255,255,255,0.04);
}

.msg-item.msg-active {
    background: rgba(59, 130, 246, 0.12);
    border-left: 3px solid var(--primary);
}

.msg-item.msg-unread .msg-sender {
    font-weight: 700;
    color: var(--text);
}

.msg-item.msg-unread::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.msg-item {
    position: relative;
}

.msg-item-link {
    display: block;
    padding: 0.75rem 0.85rem 0.75rem 1.1rem;
    text-decoration: none;
    color: inherit;
}

.msg-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.msg-sender {
    font-size: 0.88rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-item-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.msg-project {
    color: var(--primary);
    font-size: 0.72rem;
}

.msg-subject {
    color: var(--text-muted);
}

.msg-preview {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    opacity: 0.7;
}

/* Message statut badges */
.msg-status-nouveau {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.msg-status-en_cours {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

.msg-status-traite {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.badge-subject {
    background: var(--border);
    color: var(--text-muted);
}

/* =========================================================================
   Hub Messages — panneau détail
   ========================================================================= */

.msg-detail {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg);
}

.msg-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
    color: var(--text-muted);
}

.msg-detail-empty-icon {
    opacity: 0.3;
}

.msg-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.msg-detail-meta h2 {
    margin: 0 0 0.3rem;
    font-size: 1.1rem;
}

.msg-detail-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.msg-detail-info a {
    color: var(--primary);
}

.msg-detail-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.msg-body {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.msg-body-text {
    font-size: 0.95rem;
    line-height: 1.7;
    white-space: pre-wrap;
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.msg-note-section,
.msg-reply-section {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.msg-note-section h3,
.msg-reply-section h3 {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.msg-note-area {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.6;
    resize: vertical;
    margin-bottom: 0.6rem;
}

.msg-note-area:focus {
    outline: none;
    border-color: var(--primary);
}

.msg-note-form,
.msg-reply-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.msg-reply-label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.msg-input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
}

.msg-input-readonly {
    opacity: 0.6;
    cursor: not-allowed;
}

.inline-form {
    display: inline-flex;
    align-items: center;
}

/* =========================================================================
   Responsive — messages
   ========================================================================= */

@media (max-width: 900px) {
    .msg-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .msg-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 40vh;
    }

    .msg-detail {
        min-height: 60vh;
    }
}

/* =========================================================================
   Kanban — Drag & Drop
   ========================================================================= */

.kanban-card[draggable="true"] {
    cursor: grab;
}

.kanban-card.dragging {
    opacity: 0.4;
    cursor: grabbing;
    transform: rotate(2deg);
}

.kanban-cards.drag-over {
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    border-radius: 6px;
    outline: 2px dashed var(--primary);
    outline-offset: 2px;
}

/* =========================================================================
   Dashboard — Widget Stats Nginx
   ========================================================================= */

.nginx-stats-widget {
    margin-top: 2rem;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.widget-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.nginx-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

.nginx-stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}

.nginx-stat-card:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 5%, var(--bg));
}

.nginx-stat-domain {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nginx-stat-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
}
