/* Pontiva App CSS - matches landing page design system */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Sans:wght@400;500;600&display=swap');

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

:root {
  --ink: #0a0f1a;
  --paper: #fafaf8;
  --accent: #1a5cff;
  --accent-light: #e8efff;
  --accent-hover: #1449d6;
  --warm: #ff6b35;
  --warm-light: #fff3ee;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --muted: #6b7280;
  --border: #e5e7eb;
  --card: #ffffff;
  --sidebar-w: 260px;
}

body {
  font-family: 'DM Sans', sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
}

h1, h2, h3, h4, h5 {
  font-family: 'Space Grotesk', sans-serif;
  line-height: 1.2;
}

/* LAYOUT */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: white;
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.4rem;
  color: white;
  text-decoration: none;
  padding: 0 1.5rem;
  display: block;
  margin-bottom: 2rem;
}

.sidebar-logo span { color: var(--accent); }

.sidebar-section {
  padding: 0 0.75rem;
  margin-bottom: 1.5rem;
}

.sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.4);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: white;
}

.sidebar-link.active {
  background: var(--accent);
  color: white;
}

.sidebar-link .icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
}

.sidebar-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  padding: 0.1rem 0.5rem;
  border-radius: 100px;
  font-size: 0.75rem;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 2rem 2.5rem;
  max-width: calc(100vw - var(--sidebar-w));
}

/* PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.8rem;
  letter-spacing: -0.5px;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-warm {
  background: var(--warm);
  color: white;
}
.btn-warm:hover { background: #e55d2d; }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #047857; }

.btn-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger-light); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 1.6rem; font-size: 1rem; }

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem;
}

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

.card-header h3 {
  font-size: 1rem;
  letter-spacing: -0.3px;
}

/* STATS ROW */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.stat-card .stat-value.accent { color: var(--accent); }
.stat-card .stat-value.warm { color: var(--warm); }
.stat-card .stat-value.success { color: var(--success); }

/* TABLE */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}

td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tr:hover td {
  background: rgba(26, 92, 255, 0.02);
}

.amount {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  text-align: right;
}

/* STATUS BADGES */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-draft { background: var(--border); color: var(--muted); }
.badge-validated { background: var(--success-light); color: var(--success); }
.badge-paid { background: var(--accent-light); color: var(--accent); }
.badge-pending { background: var(--warning-light); color: var(--warning); }

/* FORMS */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
}

.form-group .hint {
  font-size: 0.75rem;
  color: var(--muted);
}

input, select, textarea {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  background: white;
  transition: border-color 0.15s;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 92, 255, 0.1);
}

textarea { resize: vertical; min-height: 80px; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 15, 26, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 2rem;
  width: 90%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 80px rgba(0,0,0,0.15);
}

.modal h2 {
  font-size: 1.3rem;
  letter-spacing: -0.3px;
  margin-bottom: 1.5rem;
}

/* JOURNAL ENTRY DISPLAY */
.journal-entry {
  background: var(--accent-light);
  border-radius: 12px;
  padding: 1.25rem;
  margin-top: 1rem;
}

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

.journal-entry .je-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.95rem;
}

.je-lines {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.je-lines th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  font-size: 0.7rem;
  border-bottom: 1px solid rgba(26, 92, 255, 0.15);
}

.je-lines td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid rgba(26, 92, 255, 0.08);
  background: transparent;
}

.je-lines .debit { color: var(--accent); font-weight: 600; }
.je-lines .credit { color: var(--success); font-weight: 600; }

/* INVOICE LINE EDITOR */
.line-items {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.line-item {
  display: grid;
  grid-template-columns: 2fr 80px 80px 100px 80px 100px 40px;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.line-item:last-child { border-bottom: none; }

.line-item.header {
  background: var(--paper);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.5rem 0.8rem;
}

.line-item input {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  border-radius: 6px;
}

.line-item .remove-line {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  border-radius: 6px;
  font-size: 1rem;
}

.line-item .remove-line:hover { background: var(--danger-light); }

.add-line-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 0 0 12px 12px;
  width: 100%;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  transition: all 0.15s;
}

.add-line-btn:hover { background: var(--accent-light); border-color: var(--accent); }

/* INVOICE TOTALS */
.invoice-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  margin: 1rem 0;
}

.invoice-totals .total-row {
  display: flex;
  gap: 2rem;
  align-items: baseline;
  font-size: 0.9rem;
}

.invoice-totals .total-label {
  color: var(--muted);
  min-width: 120px;
  text-align: right;
}

.invoice-totals .total-value {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  min-width: 100px;
  text-align: right;
}

.invoice-totals .total-row.grand {
  font-size: 1.1rem;
  padding-top: 0.5rem;
  border-top: 2px solid var(--ink);
}

/* EMPTY STATES */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.2rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.empty-state p {
  max-width: 400px;
  margin: 0 auto 1.5rem;
  font-size: 0.95rem;
}

/* ARROW BRIDGE (invoice -> accounting) */
.arrow-bridge-app {
  text-align: center;
  padding: 1rem 0;
  color: var(--accent);
}

.arrow-bridge-app::before {
  content: "↓ Écriture comptable auto-générée ↓";
  font-size: 0.8rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--ink);
  color: white;
  padding: 0.8rem 1.2rem;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* CLICKABLE ROW */
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: var(--accent-light) !important; }

/* SETUP WIZARD */
.setup-wizard {
  max-width: 700px;
  margin: 3rem auto;
}

.setup-wizard h1 {
  text-align: center;
  margin-bottom: 0.5rem;
}

.setup-wizard .setup-subtitle {
  text-align: center;
  color: var(--muted);
  margin-bottom: 2.5rem;
  font-size: 1rem;
}

/* ========== AI CHAT WIDGET ========== */

/* Floating Action Button */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26, 92, 255, 0.35);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 500;
}

.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(26, 92, 255, 0.45);
}

.chat-fab.active {
  background: var(--ink);
  box-shadow: 0 4px 20px rgba(10, 15, 26, 0.35);
}

.chat-fab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s;
}

.chat-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: var(--warm);
  border-radius: 50%;
  border: 2px solid white;
}

/* Chat Panel */
.chat-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  width: 400px;
  height: 560px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  z-index: 499;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.chat-header-status {
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.chat-close:hover {
  background: var(--border);
  color: var(--ink);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Welcome Screen */
.chat-welcome {
  text-align: center;
  padding: 1.5rem 0.5rem;
}

.chat-welcome-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.chat-welcome h4 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

.chat-welcome p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.chat-suggestion {
  padding: 0.45rem 0.85rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
}

.chat-suggestion:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* Message Bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
}

.chat-msg-user {
  align-items: flex-end;
}

.chat-msg-assistant {
  align-items: flex-start;
}

.chat-msg-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  max-width: 100%;
}

.chat-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-msg-bubble {
  max-width: 85%;
  padding: 0.7rem 1rem;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chat-msg-bubble.user {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 6px;
}

.chat-msg-bubble.assistant {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.chat-msg-text {
  white-space: pre-wrap;
}

.chat-msg-text strong {
  font-weight: 600;
}

.chat-msg-text ul, .chat-msg-text ol {
  margin: 0.3rem 0;
  padding-left: 1.25rem;
}

.chat-msg-text li {
  margin-bottom: 0.2rem;
}

.chat-msg-text pre.chat-code {
  background: var(--ink);
  color: #e8efff;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.8rem;
  overflow-x: auto;
  margin: 0.5rem 0;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

.chat-msg-text code.chat-inline-code {
  background: rgba(26, 92, 255, 0.08);
  color: var(--accent);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.82rem;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

/* Typing indicator */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: chatTyping 1.4s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat Input Area */
.chat-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.88rem;
  font-family: 'DM Sans', sans-serif;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--paper);
  transition: border-color 0.15s;
}

.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 92, 255, 0.08);
}

.chat-input-row textarea::placeholder {
  color: var(--muted);
}

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.chat-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat-send:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: default;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr; }
  .line-item { grid-template-columns: 1fr 1fr; }

  .chat-panel {
    width: calc(100vw - 1rem);
    height: calc(100vh - 6rem);
    bottom: 5rem;
    right: 0.5rem;
    border-radius: 16px;
  }

  .chat-fab {
    bottom: 1rem;
    right: 1rem;
  }
}
