/* ============================================================
   POSTIX — Interface utilisateur
   Design : compagnon professionnel, épuré, chaleureux
   ============================================================ */

:root {
    --px-bg:          #F7F7F5;
    --px-surface:     #FFFFFF;
    --px-border:      #E8E8E4;
    --px-text:        #1A1A18;
    --px-text-muted:  #6B6B65;
    --px-accent:      #2D6BE4;
    --px-accent-hover:#1F56C8;
    --px-success:     #1F7A4A;
    --px-danger:      #C53030;
    --px-sidebar-w:   220px;
    --px-radius:      10px;
    --px-radius-sm:   6px;
    --px-shadow:      0 1px 4px rgba(0,0,0,0.07);
    --px-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- Reset dans le scope Postix ---- */
#postix-app * { box-sizing: border-box; }
#postix-app { font-family: var(--px-font); color: var(--px-text); }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.postix-app {
    display: flex;
    min-height: 80vh;
    background: var(--px-bg);
    border-radius: var(--px-radius);
    overflow: hidden;
    border: 1px solid var(--px-border);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.postix-sidebar {
    width: var(--px-sidebar-w);
    background: var(--px-text);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 0;
    flex-shrink: 0;
}

.postix-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.postix-logo-icon { font-size: 16px; opacity: 0.7; }
.postix-logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

.postix-nav { list-style: none; margin: 0; padding: 12px 0; flex: 1; }
.postix-nav li { margin: 0; }

.postix-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.postix-nav-item:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}
.postix-nav-item.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
    border-left-color: var(--px-accent);
}
.postix-nav-icon { font-size: 13px; width: 18px; text-align: center; }

.postix-sidebar-footer { padding: 16px 18px; border-top: 1px solid rgba(255,255,255,0.08); }
.postix-pack-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: rgba(255,255,255,0.55);
}

/* ============================================================
   MAIN
   ============================================================ */
.postix-main {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.postix-panel { display: none; padding: 32px; }
.postix-panel.active { display: block; }

.postix-page-header { margin-bottom: 28px; }
.postix-page-header h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.postix-page-header p  { font-size: 14px; color: var(--px-text-muted); margin: 0; }

.postix-section { margin-bottom: 36px; }
.postix-section h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--px-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 14px;
}

/* ============================================================
   ONBOARDING
   ============================================================ */
.postix-onboarding { max-width: 680px; }
.postix-onboarding-header { margin-bottom: 32px; }
.postix-onboarding-header h1 { font-size: 26px; font-weight: 700; margin: 0 0 8px; }
.postix-onboarding-header p  { color: var(--px-text-muted); }

.postix-steps {}
.postix-step { display: none; }
.postix-step.active { display: block; }
.postix-step h2 { font-size: 17px; font-weight: 700; margin: 0 0 6px; }
.postix-step > p { color: var(--px-text-muted); font-size: 14px; margin: 0 0 20px; }

.postix-packs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.postix-pack-card {
    background: var(--px-surface);
    border: 2px solid var(--px-border);
    border-radius: var(--px-radius);
    padding: 18px 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.postix-pack-card:hover { border-color: var(--px-accent); }
.postix-pack-card.selected { border-color: var(--px-accent); background: #EEF4FF; }
.postix-pack-icon { font-size: 28px; line-height: 1; }
.postix-pack-name { font-size: 13px; font-weight: 600; }
.postix-pack-desc { font-size: 11px; color: var(--px-text-muted); line-height: 1.4; }

/* ============================================================
   SITUATIONS GRID
   ============================================================ */
.postix-situations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 24px;
}
.postix-situation-card {
    background: var(--px-surface);
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    padding: 14px 12px;
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    font-family: var(--px-font);
}
.postix-situation-card:hover {
    border-color: var(--px-accent);
    box-shadow: 0 2px 8px rgba(45,107,228,0.12);
    transform: translateY(-1px);
}
.postix-sit-icon { font-size: 22px; }
.postix-sit-label { font-size: 12px; font-weight: 600; line-height: 1.3; }

/* ============================================================
   FORMULAIRE
   ============================================================ */
.postix-form { max-width: 600px; }
.postix-field { margin-bottom: 16px; }
.postix-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--px-text);
}
.postix-field input[type="text"],
.postix-field input[type="email"],
.postix-field input[type="tel"],
.postix-field input[type="url"],
.postix-field input[type="number"],
.postix-field input[type="password"],
.postix-field select,
.postix-field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    font-size: 14px;
    font-family: var(--px-font);
    background: var(--px-surface);
    color: var(--px-text);
    transition: border-color 0.15s;
}
.postix-field input:focus,
.postix-field select:focus,
.postix-field textarea:focus {
    outline: none;
    border-color: var(--px-accent);
    box-shadow: 0 0 0 3px rgba(45,107,228,0.1);
}
.postix-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.postix-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
    font-size: 14px;
    cursor: pointer;
}

/* ============================================================
   BOUTONS
   ============================================================ */
.postix-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--px-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
    text-decoration: none;
    font-family: var(--px-font);
}
.postix-btn:hover { text-decoration: none; }
.postix-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.postix-btn-primary {
    background: var(--px-accent);
    color: #fff;
    border-color: var(--px-accent);
}
.postix-btn-primary:hover:not(:disabled) {
    background: var(--px-accent-hover);
    border-color: var(--px-accent-hover);
    color: #fff;
}

.postix-btn-secondary {
    background: var(--px-text);
    color: #fff;
    border-color: var(--px-text);
}

.postix-btn-outline {
    background: transparent;
    color: var(--px-text);
    border-color: var(--px-border);
}
.postix-btn-outline:hover:not(:disabled) {
    border-color: var(--px-text);
    color: var(--px-text);
}

.postix-btn-danger {
    background: transparent;
    color: var(--px-danger);
    border-color: var(--px-danger);
}
.postix-btn-sm { padding: 6px 12px; font-size: 12px; }

.postix-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.postix-btn-generate {
    padding: 12px 24px;
    font-size: 15px;
}
.postix-btn-icon { font-size: 12px; }

/* ============================================================
   NOUVELLE COM — ÉTAPES
   ============================================================ */
.postix-new-post-step { display: none; }
.postix-new-post-step.active { display: block; }
.postix-new-post-step h2 { font-size: 18px; font-weight: 700; margin: 0 0 20px; }

.postix-back-btn {
    background: none;
    border: none;
    color: var(--px-text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    margin-bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--px-font);
}
.postix-back-btn:hover { color: var(--px-text); }

/* ============================================================
   LOADING
   ============================================================ */
.postix-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 60px 0;
    color: var(--px-text-muted);
    font-size: 14px;
}
.postix-spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--px-border);
    border-top-color: var(--px-accent);
    border-radius: 50%;
    animation: postix-spin 0.8s linear infinite;
}
@keyframes postix-spin { to { transform: rotate(360deg); } }

/* ============================================================
   RÉSULTATS — ONGLETS RÉSEAUX
   ============================================================ */
.postix-network-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--px-border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.postix-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--px-text-muted);
    font-family: var(--px-font);
    transition: all 0.15s;
}
.postix-tab img { width: 15px; height: 15px; }
.postix-tab:hover { color: var(--px-text); }
.postix-tab.active {
    color: var(--px-accent);
    border-bottom-color: var(--px-accent);
}

.postix-tab-content { display: none; }
.postix-tab-content.active { display: block; }

.postix-result-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.postix-result-textarea {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    font-size: 14px;
    font-family: var(--px-font);
    line-height: 1.6;
    resize: vertical;
    min-height: 180px;
    background: var(--px-surface);
    color: var(--px-text);
}
.postix-result-textarea:focus {
    outline: none;
    border-color: var(--px-accent);
}

.postix-html-preview {
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    padding: 20px;
    background: var(--px-surface);
    min-height: 120px;
    font-size: 14px;
}
.postix-html-code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: #F0F0EE;
    padding: 14px;
    border-radius: var(--px-radius-sm);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 10px;
}

.postix-results-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--px-border);
}

/* ============================================================
   HISTORIQUE
   ============================================================ */
.postix-history-preview { display: flex; flex-direction: column; gap: 10px; }
.postix-history-list    { display: flex; flex-direction: column; gap: 10px; }

.postix-history-card,
.postix-history-item {
    background: var(--px-surface);
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.postix-history-meta,
.postix-history-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
}
.postix-history-situation,
.postix-history-item-sit { font-weight: 600; font-size: 13px; }
.postix-history-date,
.postix-history-item-date { font-size: 12px; color: var(--px-text-muted); }

.postix-history-preview-text,
.postix-history-item-preview {
    font-size: 13px;
    color: var(--px-text-muted);
    flex: 1;
    min-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.postix-status-published {
    font-size: 11px;
    font-weight: 700;
    color: var(--px-success);
    background: #E6F4ED;
    padding: 2px 8px;
    border-radius: 20px;
}
.postix-status-draft {
    font-size: 11px;
    color: var(--px-text-muted);
    background: var(--px-border);
    padding: 2px 8px;
    border-radius: 20px;
}

/* ============================================================
   RÉSEAUX
   ============================================================ */
.postix-networks-list { display: flex; flex-direction: column; gap: 12px; max-width: 560px; }
.postix-network-item {
    background: var(--px-surface);
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.postix-network-item.connected { border-color: #B3D9C0; background: #F4FBF7; }
.postix-network-info { display: flex; align-items: center; gap: 14px; }
.postix-network-logo { width: 28px; height: 28px; }
.postix-network-info strong { display: block; font-size: 14px; }
.postix-network-account { font-size: 12px; color: var(--px-text-muted); }
.postix-network-action { display: flex; align-items: center; gap: 10px; }
.postix-badge-connected { font-size: 12px; font-weight: 600; color: var(--px-success); }
.postix-badge-expired   { font-size: 12px; font-weight: 600; color: #B45309; background: #FEF3C7; padding: 2px 8px; border-radius: 20px; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.postix-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--px-text-muted);
}
.postix-empty span { font-size: 36px; display: block; margin-bottom: 16px; opacity: 0.3; }
.postix-empty p { margin: 0 0 20px; font-size: 15px; line-height: 1.6; }

/* ============================================================
   TOAST
   ============================================================ */
.postix-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--px-radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.3s;
    z-index: 99999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    font-family: var(--px-font);
}
.postix-toast.visible { opacity: 1; transform: translateY(0); }
.postix-toast-success { background: var(--px-success); }
.postix-toast-error   { background: var(--px-danger); }

/* ============================================================
   NOTICE CONNEXION
   ============================================================ */
.postix-notice {
    padding: 20px;
    background: var(--px-surface);
    border: 1px solid var(--px-border);
    border-radius: var(--px-radius-sm);
    font-size: 14px;
    color: var(--px-text-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 680px) {
    .postix-app { flex-direction: column; }
    .postix-sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; }
    .postix-logo { padding: 12px 16px; }
    .postix-nav { display: flex; padding: 0; }
    .postix-nav-item { padding: 10px 12px; font-size: 12px; border-left: none; border-bottom: 3px solid transparent; }
    .postix-nav-item.active { border-bottom-color: var(--px-accent); border-left: none; }
    .postix-sidebar-footer { display: none; }
    .postix-panel { padding: 20px 16px; }
    .postix-field-row { grid-template-columns: 1fr; }
    .postix-packs-grid { grid-template-columns: repeat(2, 1fr); }
    .postix-situations-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Nav désactivée pendant l'onboarding */
#postix-app[data-configured="0"] .postix-nav-item {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Badge clé non configurée */
.postix-badge-unconfigured {
    font-size: 12px;
    font-weight: 600;
    color: #6B6B65;
    background: #E8E8E4;
    padding: 2px 8px;
    border-radius: 20px;
}
