/* ========== Thème moderne Orange & Vert ========== */
:root {
  --sidebar-width: 260px;
  --topbar-height: 56px;
  --footer-height: 48px;
  /* Orange */
  --oc-orange-50: #fff4e6;
  --oc-orange-100: #ffe0b8;
  --oc-orange-200: #ffcc8a;
  --oc-orange-300: #ffb35c;
  --oc-orange-400: #ff9f1c;
  --oc-orange-500: #e85d04;
  --oc-orange-600: #d44d00;
  --oc-orange-700: #b33d00;
  --oc-orange-800: #8c2e00;
  --oc-orange-900: #662200;
  /* Vert */
  --oc-green-50: #e8f5e9;
  --oc-green-100: #c8e6c9;
  --oc-green-200: #a5d6a7;
  --oc-green-300: #81c784;
  --oc-green-400: #66bb6a;
  --oc-green-500: #40916c;
  --oc-green-600: #2d6a4f;
  --oc-green-700: #1b4332;
  --oc-green-800: #0f3323;
  --oc-green-900: #052014;
  /* Sémantique thème */
  --oc-primary: var(--oc-orange-500);
  --oc-primary-hover: var(--oc-orange-600);
  --oc-primary-light: var(--oc-orange-50);
  --oc-accent: var(--oc-green-500);
  --oc-accent-hover: var(--oc-green-600);
  --oc-accent-light: var(--oc-green-50);
  --oc-sidebar-bg: linear-gradient(180deg, #0f3323 0%, #1b4332 50%, #2d6a4f 100%);
  --oc-topbar-bg: #fff;
  --oc-topbar-border: rgba(0,0,0,.06);
  --oc-footer-bg: #f0f4f0;
  --oc-card-radius: 12px;
  --oc-btn-radius: 10px;
  --oc-shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --oc-shadow: 0 4px 12px rgba(0,0,0,.08);
  --oc-shadow-lg: 0 8px 24px rgba(0,0,0,.1);
}

/* Bootstrap overrides pour le thème */
.btn-primary {
  background-color: var(--oc-primary) !important;
  border-color: var(--oc-primary) !important;
  border-radius: var(--oc-btn-radius);
  font-weight: 600;
  padding: 0.5rem 1rem;
  transition: background-color .2s, transform .15s;
}
.btn-primary:hover {
  background-color: var(--oc-primary-hover) !important;
  border-color: var(--oc-primary-hover) !important;
  transform: translateY(-1px);
}
.btn-success {
  background-color: var(--oc-accent) !important;
  border-color: var(--oc-accent) !important;
  border-radius: var(--oc-btn-radius);
  font-weight: 600;
}
.btn-success:hover {
  background-color: var(--oc-accent-hover) !important;
  border-color: var(--oc-accent-hover) !important;
}
.btn-outline-primary {
  border-color: var(--oc-primary);
  color: var(--oc-primary);
  border-radius: var(--oc-btn-radius);
}
.btn-outline-primary:hover {
  background-color: var(--oc-primary-light);
  border-color: var(--oc-primary);
  color: var(--oc-primary-hover);
}
.card {
  border-radius: var(--oc-card-radius);
  box-shadow: var(--oc-shadow-sm);
  border: 1px solid rgba(0,0,0,.06);
}

/* ========== Structure layout ========== */
html, body { height: 100%; margin: 0; }
#app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--topbar-height);
}

/* ---------- Topbar ---------- */
.app-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--oc-topbar-bg);
  border-bottom: 1px solid var(--oc-topbar-border);
  box-shadow: var(--oc-shadow-sm);
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 1rem 0 0;
}
.app-topbar .brand {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 1.25rem;
  background: var(--oc-sidebar-bg);
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  gap: 0.5rem;
}
.app-topbar .brand .bi-box-seam { font-size: 1.4rem; color: var(--oc-orange-400); }
.app-topbar .page-title {
  padding-left: 1.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1a1a1a;
}
.app-topbar .topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.app-topbar .org-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  background: var(--oc-accent-light);
  color: var(--oc-green-700);
  font-weight: 500;
}
.app-topbar .user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #333;
}
.app-topbar .btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--oc-btn-radius);
  border: 1px solid var(--oc-orange-200);
  background: #fff;
  color: var(--oc-orange-600);
  transition: background .2s, color .2s;
}
.app-topbar .btn-logout:hover {
  background: var(--oc-orange-50);
  color: var(--oc-orange-700);
}
.app-topbar .btn-login {
  padding: 0.45rem 1rem;
  font-weight: 600;
  border-radius: var(--oc-btn-radius);
  background: var(--oc-primary) !important;
  border-color: var(--oc-primary) !important;
  color: #fff !important;
}
.app-topbar .btn-login:hover { opacity: .95; transform: translateY(-1px); }

/* Toggle sidebar mobile */
.app-topbar .btn-sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--oc-btn-radius);
  border: 1px solid var(--oc-topbar-border);
  background: #fff;
  color: #333;
}
@media (max-width: 991.98px) {
  .app-topbar .brand { width: auto; min-width: auto; padding-left: 1rem; }
  .app-topbar .brand span:not(.bi) { display: none; }
  .app-topbar .page-title { display: none; }
  .app-topbar .btn-sidebar-toggle { display: inline-flex; }
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--oc-sidebar-bg);
  z-index: 1025;
  overflow-y: auto;
  transition: transform .25s ease, box-shadow .25s ease;
}
.app-sidebar .nav {
  padding: 0.75rem 0.5rem;
}
.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1rem;
  margin-bottom: 0.2rem;
  border-radius: 10px;
  color: rgba(255,255,255,.88) !important;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background .2s, color .2s;
}
.app-sidebar .nav-link .bi {
  font-size: 1.15rem;
  opacity: .95;
}
.app-sidebar .nav-link:hover {
  background: rgba(255,255,255,.12);
  color: #fff !important;
}
.app-sidebar .nav-link.active {
  background: var(--oc-orange-500);
  color: #fff !important;
  font-weight: 600;
}
.app-sidebar .nav-link.active .bi { color: #fff; }
.app-sidebar .nav-link.disabled {
  opacity: .5;
  pointer-events: none;
  cursor: not-allowed;
}
.app-sidebar .nav-link-parent {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(255,255,255,.7) !important;
  margin-top: 0.5rem;
}
.app-sidebar .nav-link-parent .bi-chevron-down {
  transition: transform .2s;
}
.app-sidebar .nav-link-parent[aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
}
.app-sidebar .submenu {
  border-left: 2px solid rgba(255,255,255,.2);
  margin-left: 1.5rem;
  padding-left: 0.5rem;
  margin-bottom: 0.25rem;
}
.app-sidebar .submenu .nav-link {
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
}
.app-sidebar .sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.15);
  margin: 0.5rem 1rem;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .app-sidebar.show {
    transform: translateX(0);
    box-shadow: var(--oc-shadow-lg);
  }
  .app-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1020;
    top: var(--topbar-height);
  }
  .app-sidebar-overlay.show { display: block; }
}

/* ---------- Main content ---------- */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--topbar-height) - var(--footer-height));
  display: flex;
  flex-direction: column;
  background: #f6f8f8;
}
.app-main .main-inner {
  flex: 1;
  padding: 1.5rem 1.5rem 2rem;
}
@media (max-width: 991.98px) {
  .app-main { margin-left: 0; }
}

/* ---------- Footer ---------- */
.app-footer {
  margin-left: var(--sidebar-width);
  height: var(--footer-height);
  background: var(--oc-footer-bg);
  border-top: 1px solid rgba(0,0,0,.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #5f6b6b;
}
.app-footer a { color: var(--oc-green-600); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
@media (max-width: 991.98px) {
  .app-footer { margin-left: 0; }
}

/* ========== Composants modernes ========== */
.app-card {
  background: #fff;
  border-radius: var(--oc-card-radius);
  box-shadow: var(--oc-shadow-sm);
  border: 1px solid rgba(0,0,0,.06);
  overflow: hidden;
}
.app-card .card-header {
  background: linear-gradient(135deg, var(--oc-green-50) 0%, #fff 100%);
  border-bottom: 1px solid rgba(0,0,0,.06);
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: #1a1a1a;
}
.btn-app-primary {
  background: var(--oc-primary);
  color: #fff;
  border: none;
  border-radius: var(--oc-btn-radius);
  font-weight: 600;
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background .2s, transform .15s;
}
.btn-app-primary:hover {
  background: var(--oc-primary-hover);
  color: #fff;
  transform: translateY(-1px);
}
.btn-app-success {
  background: var(--oc-accent);
  color: #fff;
  border: none;
  border-radius: var(--oc-btn-radius);
  font-weight: 600;
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-app-success:hover { background: var(--oc-accent-hover); color: #fff; }
.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background .2s, transform .1s;
}
.btn-icon:hover { transform: scale(1.05); }
.btn-icon .bi { font-size: 1.1rem; }

/* ========== Pages (conservation des règles métier) ========== */
.invoice-card { width: 98%; max-width: 1600px; margin: 20px auto; border-radius: var(--oc-card-radius); box-shadow: var(--oc-shadow); }
.invoice-form-shell { max-width: 1600px; margin: 0 auto; padding: 0 .5rem; width: 100%; }
.invoice-form-shell .invoice-card { width: 100%; max-width: 100%; margin: 10px auto; }
.invoice-card .card-body { padding: 1.5rem; }
.btn-equal { min-width: 160px; border-radius: var(--oc-btn-radius); }
.table-responsive { background: #fff; border-radius: 10px; overflow: hidden; }

.invoice-header .form-label,
.invoice-lines .form-label,
.invoice-lines .table th,
.invoice-lines .table td,
.invoice-footer { font-size: 0.85rem; }
.invoice-card .form-control-sm { font-size: 0.85rem; padding: .35rem .5rem; border-radius: 8px; }
.invoice-lines .table td.amount { font-weight: 600; text-align: right; }
.invoice-footer #invoiceTotal { font-size: 1.05rem; }

.invoice-header .form-label { font-size: 0.75rem; }
.invoice-header .form-control,
.invoice-header .form-control-sm,
.invoice-header .form-select,
.invoice-header .form-select-sm,
.invoice-header textarea {
  width: 100%;
  font-size: 0.75rem !important;
  border-radius: 8px;
}
.invoice-header-panel {
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 10px;
  background: #fff;
  padding: 0.75rem;
}
.invoice-header-panel > h6 {
  border-bottom: 1px solid rgba(0,0,0,.08);
  padding-bottom: 0.35rem;
  margin-bottom: 0.6rem;
  font-weight: 700;
  color: var(--oc-green-700);
}
.invoice-header textarea.form-control,
.invoice-header textarea.form-control-sm { min-height: 72px; resize: vertical; }

@media (max-width: 767.98px) {
  .invoice-card { width: 100%; padding: 0 0.5rem; }
  .invoice-card .card-body { padding: 1rem; }
  .invoice-form-shell { max-width: 100%; padding: 0; }
}
@media (min-width: 1200px) {
  .invoice-form-shell { max-width: 1600px; }
  .invoice-form-shell .invoice-card { max-width: 100%; }
}

#linesTable input.form-control,
#linesTable input.form-control-sm {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: .2rem .35rem !important;
  font-size: .8rem !important;
  height: auto !important;
  border-radius: 4px;
}
#linesTable td { padding: .3rem .45rem !important; vertical-align: middle; }
#linesTable th.col-taxcode,
#linesTable td.col-taxcode { min-width: 220px; }
#linesTable td.col-taxcode .tax { min-width: 200px; }
#linesTable input.form-control:focus,
#linesTable input.form-control-sm:focus { outline: none !important; box-shadow: none !important; }
#linesTable td.amount { font-size: .9rem; }
.ref { width: 14ch !important; max-width: 100%; }
.designation { width: 34ch !important; max-width: 100%; }
.otherCode { width: 15ch !important; max-width: 100%; }
.otherRate { width: 8ch !important; max-width: 8ch; }
.qty { width: 8ch !important; max-width: 100%; }
.price { width: 12ch !important; max-width: 100%; }
.tax { width: 8ch !important; max-width: 8ch; }
.discount { width: 6ch !important; max-width: 6ch; }
.other-tax { color: var(--oc-green-600); font-weight: 500; }
.invoice-lines .table thead th { font-size: 0.72rem; }

.invoices-list-table th,
.invoices-list-table td { padding: .24rem .38rem !important; font-size: .70rem; vertical-align: middle; }
.invoices-list-table th { font-size: .66rem; font-weight: 600; }
.invoices-list-table .badge { font-size: .62rem; padding: .18rem .35rem; border-radius: 6px; }
.invoices-list-table .btn.btn-sm { padding: .12rem .3rem; font-size: .62rem; border-radius: 8px; }
.invoices-list-toolbar .form-control,
.invoices-list-toolbar .form-select { font-size: .7rem; min-height: 1.7rem; padding: .16rem; border-radius: 8px; }
.invoices-list-toolbar .btn { font-size: .68rem; padding: .16rem .45rem; border-radius: 8px; }
.list-action-icon-btn {
  width: 2rem !important; min-width: 2rem !important; height: 2rem !important;
  padding: 0 !important; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.list-action-icon-btn .bi { font-size: .9rem; }
.invoices-list-title { font-size: 1.05rem; font-weight: 600; margin-bottom: .6rem; }
.invoices-pagination .page-link { font-size: .62rem !important; padding: .08rem .3rem !important; min-width: 1.35rem; border-radius: 6px; }

.settings-card { border: 1px solid rgba(45,106,79,.2) !important; border-radius: var(--oc-card-radius); }
.settings-card .card-title { font-size: .98rem; font-weight: 600; }
.settings-card .form-label { font-size: .78rem; margin-bottom: .22rem; color: #5f6670; }
.settings-card .form-control,
.settings-card .form-select { border-radius: 10px; }
.settings-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .02em; color: #5f6670; border-bottom-width: 1px; }
.settings-table td { font-size: .78rem; padding: .5rem; }
.settings-table tbody tr:hover { background: var(--oc-green-50); }
.societe-form-card .form-control,
.societe-form-card .form-select,
.societe-form-card textarea { border-radius: .65rem; }
.societe-section-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: #5f6670; font-weight: 700; margin-bottom: .45rem; }
.societe-logo-preview {
  width: 96px; height: 96px; object-fit: cover; border-radius: .75rem;
  border: 1px solid rgba(45,106,79,.25); background: #fff;
}

.dashboard-card {
  border-radius: var(--oc-card-radius);
  box-shadow: var(--oc-shadow-sm);
  border: 1px solid rgba(0,0,0,.06);
  transition: transform .16s ease, box-shadow .16s ease;
}
.dashboard-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--oc-shadow);
}
.dashboard-card .card-body { position: relative; padding: 1.25rem 1.35rem; }
.dashboard-card-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: #5f6b6b; margin-bottom: 0.2rem;
}
.dashboard-card .card-title { font-size: 1rem; font-weight: 700; color: #1a1a1a; }
.dashboard-card-value { font-size: 2rem; line-height: 1.1; font-weight: 700; color: #1a1a1a; }
.dashboard-card-link { color: transparent; }
.dashboard-card-vente {
  background: linear-gradient(135deg, var(--oc-orange-50) 0%, #fff 100%);
  border-color: rgba(232,93,4,.2);
}
.dashboard-card-achat {
  background: linear-gradient(135deg, var(--oc-green-50) 0%, #fff 100%);
  border-color: rgba(45,106,79,.2);
}
.dashboard-card-total {
  background: #fff;
  border-color: rgba(0,0,0,.08);
}

.invoice-readonly .form-control:disabled,
.invoice-readonly .form-select:disabled,
.invoice-readonly textarea:disabled {
  background-color: var(--bs-secondary-bg);
  color: var(--bs-secondary-color);
  opacity: 1;
  cursor: not-allowed;
}
.invoice-readonly .btn:disabled { opacity: .7; cursor: not-allowed; }
.invoice-readonly #linesTable td,
.invoice-readonly #linesTable th,
.invoice-readonly .invoice-footer { color: var(--bs-secondary-color); }
