/**
 * tabler.css
 * ProAppli Tabler v3 - Styles
 * Headers séparés, sommes, formules
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
                 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; padding: 8px 16px;
    background: linear-gradient(135deg, #1a7f37 0%, #2ea043 100%);
    border-radius: 6px; color: white;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; background: white; color: #1a7f37;
    font-weight: 900; font-size: 20px; border-radius: 4px;
    font-family: 'Segoe UI', Arial, sans-serif;
}
.header-title { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.header-right { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.header-file {
    padding: 2px 8px; background: rgba(255,255,255,0.2); border-radius: 4px;
    font-family: monospace; font-size: 11px;
}
.header-info { opacity: 0.9; }

h1 { color: #2c3e50; font-size: 24px; font-weight: 700; }

/* =========================================
   SYNC INDICATOR
   ========================================= */

.sync-indicator {
    position: fixed; top: 20px; right: 20px;
    padding: 12px 24px;
    background: #28a745; color: white;
    border-radius: 6px; font-weight: 600; font-size: 14px;
    opacity: 0; transition: opacity 0.3s ease;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}
.sync-indicator.show { opacity: 1; }
.sync-indicator.loading { background: #17a2b8; }
.sync-indicator.error { background: #dc3545; }

/* =========================================
   AI MODAL & FIELD PROPS
   ========================================= */

.btn-generate {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; padding: 10px 20px; font-weight: 600; white-space: nowrap;
    border: none; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.btn-generate:hover { background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%); }

.btn-ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important; border-color: #667eea !important; font-weight: 600;
}
.btn-ai:hover { opacity: 0.9; }

/* Field props modal rows */
.fp-row { margin-bottom: 10px; }
.fp-row label { display: block; font-size: 12px; color: #555; margin-bottom: 3px; font-weight: 500; }
.fp-row input[type="text"], .fp-row select {
    width: 100%; padding: 7px 10px; font-size: 13px;
    border: 1px solid #dee2e6; border-radius: 4px; box-sizing: border-box;
}
.fp-row input:focus, .fp-row select:focus { outline: none; border-color: #667eea; }
.fp-row-2col { display: flex; gap: 12px; }
.fp-row-2col > div { flex: 1; }
.fp-aggs { display: flex; gap: 10px; flex-wrap: wrap; }
.fp-aggs label { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; cursor: pointer; }

/* Inline column filter */
.col-filter {
    display: flex; align-items: center; gap: 4px;
    margin-top: 4px; padding: 2px;
}
.col-filter-select {
    font-size: 11px; padding: 2px 4px; border: 1px solid #667eea;
    border-radius: 3px; background: white; max-width: 120px;
}
.col-filter-close {
    cursor: pointer; color: #dc3545; font-size: 12px; font-weight: 700;
}
.col-filter-close:hover { color: #ff0000; }

/* Column menu separator */
.col-menu-sep { border-top: 1px solid #e9ecef; margin: 2px 0; padding: 0 !important; height: 0; cursor: default !important; }
.col-menu-sep:hover { background: transparent !important; }

/* Settings modal */
.settings-section { padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.settings-section:last-child { border-bottom: none; }
.settings-label { font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.settings-value { font-size: 14px; color: #333; }

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 10px 0;
}

.template-card {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; padding: 16px 10px;
    border: 2px solid #e1e4e8; border-radius: 10px;
    cursor: pointer; transition: all 0.15s;
    background: #fff;
}
.template-card:hover {
    border-color: #667eea; background: #f0f4ff;
    transform: translateY(-2px); box-shadow: 0 4px 12px rgba(102,126,234,0.15);
}
.template-icon { font-size: 28px; }
.template-name { font-weight: 700; font-size: 13px; color: #24292e; text-align: center; }
.template-fields { font-size: 11px; color: #8b949e; }

/* File System API */
.btn-fs { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.btn-fs:hover { background: #ffc107; color: #533f03; }

/* Mode badges (used in header + settings) */
.status-mode {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 10px; border-radius: 4px; font-weight: 700; font-size: 11px;
    white-space: nowrap;
}
.status-server { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.status-fs { background: #cce5ff; color: #004085; border: 1px solid #b8daff; }
.status-enterprise { background: #e2e3f1; color: #383d6e; border: 1px solid #c8cbe9; }
.status-demo { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.fs-disconnect { cursor: pointer; color: #721c24; font-weight: 700; margin-left: 4px; }
.fs-disconnect:hover { color: #f00; }

/* =========================================
   TOOLBAR
   ========================================= */

.toolbar {
    display: flex; gap: 5px; align-items: center;
    margin-bottom: 10px; padding: 10px;
    background: #f8f9fa; border-radius: 6px; flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-label { font-size: 13px; color: #666; font-weight: 500; }

.filename-input {
    width: 150px; padding: 6px 10px; font-size: 13px;
    border: 1px solid #dee2e6; border-radius: 4px;
}
.filename-input:focus { outline: none; border-color: #007bff; }

.toolbar-separator { width: 1px; height: 24px; background: #dee2e6; margin: 0 8px; }

.btn-tool {
    padding: 8px 12px; background: white;
    border: 1px solid #dee2e6; color: #495057; font-size: 13px;
}
.btn-tool:hover { background: #e9ecef; }
.btn-tool.active { background: #007bff; color: white; border-color: #007bff; }
.btn-tool:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-save { background: #28a745; color: white; border-color: #28a745; }
.btn-save:hover { background: #218838; }
.btn-excel { background: #217346; color: white; border-color: #217346; }
.btn-excel:hover { background: #1e6b3e; }
.btn-copy { background: #6c757d; color: white; border-color: #6c757d; }
.btn-copy:hover { background: #545b62; }
.btn-col { background: #17a2b8; color: white; border-color: #17a2b8; }
.btn-col:hover { background: #138496; }
.btn-local { background: #6f42c1; color: white; border-color: #6f42c1; }
.btn-local:hover { background: #5a32a3; }

/* =========================================
   EDITOR SECTIONS
   ========================================= */

.editor-section { margin-bottom: 10px; }
.editor-section.hidden { display: none; }

textarea {
    width: 100%; height: 500px;
    font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
    font-size: 13px; line-height: 1.5;
    padding: 12px; border: 1px solid #dee2e6; border-radius: 6px;
    resize: vertical; background: #fff; color: #212529;
    transition: border-color 0.2s, box-shadow 0.2s;
    white-space: pre; overflow-x: auto; word-wrap: normal;
}
textarea:focus {
    outline: none; border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.html-container {
    min-height: 400px; padding: 15px;
    background: white; border: 1px solid #dee2e6;
    border-radius: 6px; overflow-x: auto;
}

.empty-state {
    color: #999; text-align: center;
    padding: 40px 20px; font-style: italic;
}

/* =========================================
   TABLE
   ========================================= */

table {
    width: 100%; border-collapse: collapse;
    margin: 10px 0; background: white; font-size: 14px;
}
thead { background: #f8f9fa; }

th, td {
    border: 1px solid #dee2e6;
    padding: 8px 12px; text-align: left;
    transition: background-color 0.2s;
}

th {
    font-weight: 600; color: #495057; background: #e9ecef;
    white-space: nowrap; user-select: none;
    position: relative;
    padding-right: 45px;
}

.th-label {
    display: block;
    font-weight: 700;
    font-size: 13px;
    color: #24292e;
    line-height: 1.2;
}

.th-name-small {
    display: block;
    font-size: 10px;
    color: #8b949e;
    font-weight: 400;
    font-family: 'Courier New', monospace;
    opacity: 0.8;
}

td { color: #212529; min-height: 38px; height: 38px; }

td:focus {
    outline: none; background: #e3f2fd;
    box-shadow: inset 0 0 0 2px #007bff;
}

/* Navigation Excel-like */
.cell-nav-selected {
    outline: 2px solid #4285f4 !important;
    outline-offset: -2px;
    background-color: #e8f0fe !important;
    box-shadow: none !important;
}

.cell-nav-editing {
    outline: 2px solid #1a73e8 !important;
    outline-offset: -2px;
    background-color: #fff !important;
    box-shadow: inset 0 0 0 1px #1a73e8 !important;
}
td:hover { background: #f1f3f5; }

/* =========================================
   HEADER : nom éditable + hint + tri séparés
   ========================================= */

.th-name {
    display: inline;
    cursor: text;
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.2s;
}

.th-name:hover {
    border-bottom-color: #667eea;
}

.th-name:focus {
    border-bottom-color: #007bff;
    background: rgba(0, 123, 255, 0.05);
    border-radius: 2px;
    padding: 0 2px;
}

.col-type-hint {
    font-size: 10px;
    color: #667eea;
    font-weight: 400;
    margin-left: 6px;
    opacity: 0.7;
    vertical-align: middle;
}

.sort-icon {
    font-size: 14px;
    opacity: 0.35;
    cursor: pointer;
    transition: opacity 0.2s, color 0.2s;
    user-select: none;
    line-height: 1;
}

.sort-icon:hover {
    opacity: 1;
    color: #667eea;
}

/* Actions header : tri + menu */
.th-actions {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    gap: 2px;
    align-items: center;
}

.col-menu-trigger {
    font-size: 16px;
    font-weight: 700;
    opacity: 0.3;
    cursor: pointer;
    transition: opacity 0.2s;
    user-select: none;
    line-height: 1;
    padding: 0 2px;
}

.col-menu-trigger:hover {
    opacity: 1;
    color: #667eea;
}

/* Menu contextuel colonne */
.col-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 100;
    min-width: 170px;
    overflow: hidden;
}

.col-menu.show { display: block; }

.col-menu div {
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    font-weight: 400;
    color: #333;
}

.col-menu div:hover { background: #f0f4ff; }

.col-menu-danger { color: #dc3545 !important; border-top: 1px solid #f0f0f0; }
.col-menu-danger:hover { background: #fff5f5 !important; }

/* Liste fichiers locaux */
.local-file-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
}

.local-file-item {
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.local-file-item:last-child { border-bottom: none; }
.local-file-item:hover { background: #f0f4ff; }

/* =========================================
   CELL INPUTS ENRICHIS
   ========================================= */

.cell-input {
    width: 100%; padding: 4px 6px;
    border: 1px solid transparent; border-radius: 4px;
    font-size: 13px; font-family: inherit;
    background: transparent;
    transition: border-color 0.2s, background 0.2s;
}
.cell-input:hover { border-color: #dee2e6; background: #f8f9fa; }
.cell-input:focus {
    outline: none; border-color: #667eea; background: white;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

.cell-input-select { cursor: pointer; appearance: auto; min-width: 80px; }
.cell-input-date, .cell-input-time, .cell-input-datetime { font-family: monospace; }
.cell-date, .cell-time, .cell-datetime { padding: 4px 8px; }

/* Checkbox */
.cell-checkbox-wrap, .cell-boolean { text-align: center; padding: 4px; }
.checkbox-label {
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.cell-checkbox { width: 18px; height: 18px; cursor: pointer; accent-color: #667eea; }

/* Radio */
.cell-radio { padding: 4px 8px; }
.radio-label {
    display: inline-flex; align-items: center; gap: 3px;
    margin-right: 8px; cursor: pointer; font-size: 12px;
}
.radio-label input[type="radio"] { accent-color: #667eea; }

/* Textarea */
.cell-input-textarea { min-height: 24px; height: 24px; resize: vertical; font-size: 12px; line-height: 1.4; overflow: hidden; transition: height 0.15s; }
.cell-input-textarea:focus { min-height: 60px; height: auto; overflow: auto; }

/* Formule */
.cell-formula {
    background: #f0f4ff; color: #495057;
    font-style: italic; position: relative;
    font-family: 'Courier New', monospace;
}
.cell-formula::after {
    content: 'ƒ'; position: absolute; top: 2px; right: 4px;
    font-size: 10px; color: #667eea; opacity: 0.5;
}

/* Rating */
.cell-rating { text-align: center; white-space: nowrap; user-select: none; }
.star {
    cursor: pointer; font-size: 18px;
    transition: color 0.15s, transform 0.15s; display: inline-block;
}
.star:hover { transform: scale(1.2); }
.star-filled { color: #f5a623; }
.star-empty { color: #ddd; }

/* Color */
.cell-color { display: flex; align-items: center; gap: 6px; padding: 4px 8px; }
.cell-input-color {
    width: 28px; height: 28px; border: 1px solid #dee2e6;
    border-radius: 4px; padding: 0; cursor: pointer;
}

/* Number */
.cell-number { text-align: right; font-family: 'Courier New', monospace; }

/* Image */
.cell-image { padding: 4px; }
.cell-img-preview {
    max-width: 60px; max-height: 40px; border-radius: 4px;
    margin-right: 6px; vertical-align: middle;
}
.cell-input-url { font-size: 11px; }

/* =========================================
   LIGNE DE SOMME (tfoot)
   ========================================= */

tfoot { background: #f0f4ff; }

.sum-row td {
    font-weight: 700;
    color: #24292e;
    border-top: 3px double #667eea;
    font-family: 'Courier New', monospace;
    text-align: right;
    font-size: 14px;
}

.cell-sum {
    background: #e8edff;
    position: relative;
}

.cell-sum::before {
    content: 'Σ ';
    color: #667eea;
    font-size: 11px;
    opacity: 0.7;
}

.cell-sum-empty {
    background: transparent;
    border-top-color: #dee2e6;
}

/* =========================================
   BUTTONS
   ========================================= */

.btn {
    padding: 10px 20px; cursor: pointer; border: none;
    border-radius: 6px; font-size: 14px; font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
   LOADING
   ========================================= */

.loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: none; justify-content: center; align-items: center;
    z-index: 9999; backdrop-filter: blur(4px);
}
.loading-overlay.show { display: flex; }

.loading-content {
    text-align: center; padding: 30px;
    background: white; border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1); max-width: 300px;
}
.loading-spinner {
    width: 60px; height: 60px; margin: 0 auto 20px;
    border: 4px solid #f3f3f3; border-top: 4px solid #667eea;
    border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.loading-text { font-size: 16px; font-weight: 600; color: #495057; margin-bottom: 8px; }
.loading-subtext { font-size: 13px; color: #6c757d; }
.loading-text-dots::after { content: ''; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots { 0%,20%{content:''} 40%{content:'.'} 60%{content:'..'} 80%,100%{content:'...'} }

/* =========================================
   ERROR MODAL
   ========================================= */

.error-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); display: flex;
    justify-content: center; align-items: center;
    z-index: 10000; opacity: 0; transition: opacity 0.3s ease;
}
.error-modal.show { opacity: 1; }

.error-modal-content {
    background: white; border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 600px; width: 90%; max-height: 80vh;
    overflow-y: auto; animation: slideDown 0.3s ease;
}
@keyframes slideDown { from{transform:translateY(-50px);opacity:0} to{transform:translateY(0);opacity:1} }

.error-header {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white; padding: 20px; border-radius: 12px 12px 0 0;
    display: flex; align-items: center; gap: 15px;
}
.error-icon { font-size: 32px; }
.error-header h3 { margin: 0; font-size: 20px; }
.error-body { padding: 25px; }
.error-message { font-size: 15px; color: #495057; line-height: 1.6; margin: 0 0 15px; }
.error-details { margin-top: 15px; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 6px; padding: 10px; }
.error-details summary { cursor: pointer; font-weight: 600; color: #495057; font-size: 13px; padding: 5px; }
.error-details pre {
    margin: 10px 0 0; padding: 15px; background: #fff;
    border: 1px solid #dee2e6; border-radius: 4px;
    overflow-x: auto; font-size: 12px; font-family: 'Courier New', monospace;
}
.error-footer { padding: 20px; border-top: 1px solid #dee2e6; text-align: right; }
.error-footer .btn {
    padding: 10px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; border: none; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;
}

/* =========================================
   FOOTER
   ========================================= */

.footer {
    margin-top: 30px; padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px; color: white; text-align: center;
}
.footer-content { max-width: 800px; margin: 0 auto; }
.footer-brand { font-size: 14px; margin-bottom: 10px; }
.footer-brand strong { font-size: 16px; }
.footer-info {
    font-size: 12px; opacity: 0.9; display: flex; flex-wrap: wrap;
    justify-content: center; align-items: center; gap: 8px;
}
.footer-separator { opacity: 0.5; }
.footer-email { color: white; text-decoration: none; }
.footer-email:hover { text-decoration: underline; }
.footer-company { font-weight: 600; }

/* =========================================
   SCROLLBAR
   ========================================= */

textarea::-webkit-scrollbar, .html-container::-webkit-scrollbar { width: 8px; height: 8px; }
textarea::-webkit-scrollbar-track, .html-container::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
textarea::-webkit-scrollbar-thumb, .html-container::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
textarea::-webkit-scrollbar-thumb:hover, .html-container::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* =========================================
   RESPONSIVE
   ========================================= */

@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 15px; }
    h1 { font-size: 20px; }
    textarea { height: 300px; font-size: 12px; }
    th, td { padding: 6px 8px; font-size: 12px; }
    .toolbar { flex-wrap: wrap; }
    .toolbar-separator { display: none; }
    .filename-input { width: 100px; }
    .header { flex-wrap: wrap; gap: 8px; }
    .footer-info { flex-direction: column; gap: 5px; }
    .footer-separator { display: none; }
}

/* Agrégations */
.agg-row td {
    font-weight: 600;
    color: #24292e;
    border-top: 3px double #667eea;
    font-family: 'Courier New', monospace;
    text-align: right;
    font-size: 13px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #e8edff 0%, #f0f4ff 100%);
    vertical-align: top;
}

.agg-line {
    padding: 2px 0;
}

.agg-line + .agg-line {
    border-top: 1px dotted #c0c8e8;
    margin-top: 2px;
    padding-top: 4px;
}

.agg-label {
    color: #667eea;
    font-size: 10px;
    font-weight: 500;
    margin-right: 6px;
    text-transform: uppercase;
}

.agg-value {
    color: #1a1a2e;
    font-weight: 700;
}

.cell-agg-empty {
    background: transparent;
    border-top-color: #dee2e6;
}

.cell-currency {
    text-align: right;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

/* Phantom row — ligne fantôme pour ajout facile */
.phantom-body { background: transparent; }

.phantom-row td {
    background: #fafbfc;
    border: 1px dashed #d0d7de;
    color: #adb5bd;
    min-height: 32px;
    height: 36px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: center;
}

.phantom-row td:hover {
    background: #f0f4ff;
    border-color: #667eea;
}

.phantom-row td::after {
    content: '+';
    color: #c0c8d8;
    font-size: 14px;
    font-weight: 300;
    pointer-events: none;
}
