/* TD Devis IA - mobile first */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1a1a1a;
    background: #f5f5f7;
    line-height: 1.5;
}

/* Login */
body.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.td-login {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 360px;
}
.td-login h1 { margin: 0 0 1.5rem; font-size: 1.5rem; }
.td-login label { display: block; margin-bottom: 1rem; font-size: 0.9rem; }
.td-login input { width: 100%; padding: 0.6rem; border: 1px solid #ddd; border-radius: 6px; font-size: 1rem; margin-top: 0.3rem; }

/* Header */
.td-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: #fff;
    border-bottom: 1px solid #e5e5ea;
    position: sticky;
    top: 0;
    z-index: 10;
}
.td-header h1 { margin: 0; font-size: 1.1rem; }

/* Tabs */
.td-tabs {
    display: flex;
    gap: 0.3rem;
    padding: 0.5rem 1rem;
    background: #fff;
    border-bottom: 1px solid #e5e5ea;
    overflow-x: auto;
}
.td-tab {
    padding: 0.5rem 0.9rem;
    background: transparent;
    border: 1px solid #d1d1d6;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    color: #333;
}
.td-tab.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }

/* Panels */
.td-panel { display: none; padding: 1rem; }
.td-panel.active { display: block; }

/* Cartes */
.td-carte {
    background: #fff;
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.td-carte h2 { margin: 0 0 0.8rem; font-size: 1.05rem; }

/* Boutons */
.td-btn {
    background: #1a1a1a;
    color: #fff;
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}
.td-btn:hover { background: #333; }
.td-btn:disabled { background: #999; cursor: wait; }
.td-btn-secondaire {
    background: #fff;
    color: #1a1a1a;
    border: 1px solid #d1d1d6;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}
.td-btn-lien {
    background: none;
    border: none;
    color: #007aff;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Formulaires */
textarea, input[type="file"] {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #d1d1d6;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
}
textarea { min-height: 90px; resize: vertical; }

/* Chat */
#td-chat-messages {
    background: #fff;
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
    max-height: 55vh;
    overflow-y: auto;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.td-msg {
    padding: 0.7rem 0.9rem;
    border-radius: 10px;
    margin-bottom: 0.7rem;
    max-width: 90%;
    word-wrap: break-word;
}
.td-msg-user {
    background: #007aff;
    color: #fff;
    margin-left: auto;
}
.td-msg-ai {
    background: #f0f0f5;
    color: #1a1a1a;
}
/* Rendu markdown dans les messages IA */
.td-msg-ai h1, .td-msg-ai h2, .td-msg-ai h3, .td-msg-ai h4 {
    margin: 0.8rem 0 0.4rem;
    line-height: 1.3;
}
.td-msg-ai h1 { font-size: 1.15rem; }
.td-msg-ai h2 { font-size: 1.05rem; }
.td-msg-ai h3 { font-size: 0.98rem; }
.td-msg-ai h4 { font-size: 0.92rem; color: #555; }

.td-msg-ai p { margin: 0.4rem 0; }
.td-msg-ai ul, .td-msg-ai ol { margin: 0.4rem 0; padding-left: 1.3rem; }
.td-msg-ai li { margin: 0.2rem 0; }
.td-msg-ai li > p { margin: 0.2rem 0; }

.td-msg-ai strong { color: #1a1a1a; }
.td-msg-ai code {
    background: #e6e6ec;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.td-msg-ai pre {
    background: #1a1a1a;
    color: #f5f5f5;
    padding: 0.7rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.82rem;
    margin: 0.6rem 0;
}
.td-msg-ai pre code { background: none; padding: 0; color: inherit; }

.td-msg-ai blockquote {
    border-left: 3px solid #007aff;
    padding: 0.3rem 0.8rem;
    margin: 0.6rem 0;
    color: #555;
    background: #f5f8ff;
    border-radius: 0 6px 6px 0;
}

.td-msg-ai hr {
    border: none;
    border-top: 1px solid #d1d1d6;
    margin: 0.8rem 0;
}

/* Tableaux markdown */
.td-msg-ai table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6rem 0;
    font-size: 0.85rem;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    display: block;
    overflow-x: auto;
}
.td-msg-ai thead {
    background: #1a1a1a;
    color: #fff;
}
.td-msg-ai th, .td-msg-ai td {
    padding: 0.5rem 0.7rem;
    text-align: left;
    border-bottom: 1px solid #e5e5ea;
    vertical-align: top;
}
.td-msg-ai th { font-weight: 600; }
.td-msg-ai tbody tr:hover { background: #f7f7fa; }
.td-msg-ai tbody tr:last-child td { border-bottom: none; }

@media (min-width: 1000px) {
    .td-msg-ai table { display: table; }
}

/* Facture item */
.td-facture {
    border: 1px solid #e5e5ea;
    border-radius: 8px;
    padding: 0.8rem;
    margin-bottom: 0.7rem;
}
.td-facture-entete {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.td-facture-entete strong { font-size: 0.95rem; }
.td-facture-entete small { color: #666; font-size: 0.8rem; display: block; }
.td-prestation {
    font-size: 0.85rem;
    padding: 0.3rem 0;
    border-top: 1px dashed #eee;
}
.td-prestation:first-of-type { border-top: none; }
.td-prestation .prix { color: #007aff; font-weight: 600; }

/* Indication */
.td-indication {
    background: #fffbea;
    border: 1px solid #ffe58f;
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.td-supprimer {
    background: none;
    border: none;
    color: #d00;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
}

.td-status { font-size: 0.85rem; color: #666; margin: 0.5rem 0 0; }
.td-status.erreur { color: #d00; }
.td-status.succes { color: #0a7f2e; }

.td-vide { color: #888; font-style: italic; font-size: 0.9rem; }

/* Desktop */
@media (min-width: 1000px) {
    .td-header, .td-tabs { padding-left: 2rem; padding-right: 2rem; }
    .td-panel { padding: 1.5rem 2rem; max-width: 1100px; margin: 0 auto; }
    .td-header h1 { font-size: 1.3rem; }
    #td-chat-messages { max-height: 60vh; }
    .td-msg { max-width: 75%; }
}


.td-scan-logs {
    list-style: none;
    padding: 0.5rem 0.8rem;
    margin: 0.5rem 0 0;
    background: #f7f7fa;
    border-radius: 6px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.85rem;
    font-family: ui-monospace, monospace;
}
.td-scan-logs li { padding: 0.15rem 0; }