:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe5f2;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --accent: #0369a1;
  --soft: #eaf1ff;
  --danger: #b91c1c;
  --shadow: 0 18px 40px rgba(30, 64, 175, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.mobile-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.menu-toggle,
.menu-overlay {
  display: none;
}

.sidebar {
  padding: 24px;
  color: white;
  background: #102a63;
  min-width: 0;
  overflow-x: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: white;
  display: block;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: none;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  font-size: 1.1rem;
}

.brand p,
.eyebrow {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.tab {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.8);
  background: transparent;
  text-align: left;
}

.tab.active,
.tab:hover {
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

main {
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.topbar .eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 1.9rem;
}

.primary,
.secondary,
.ghost,
.danger,
.import-control {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.primary {
  color: white;
  background: var(--brand);
}

.primary:hover {
  background: var(--brand-dark);
}

.secondary,
.import-control {
  color: var(--brand-dark);
  background: var(--soft);
}

.ghost {
  color: var(--brand-dark);
  background: transparent;
}

.danger {
  color: white;
  background: var(--danger);
}

.full {
  width: 100%;
}

.view {
  display: none;
  margin: 0;
  padding: 0;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metrics article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.metrics strong {
  font-size: 1.55rem;
}

.content-grid,
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.yearly-panel {
  margin-bottom: 20px;
}

.split {
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel h3 {
  margin: 0;
  font-size: 1.08rem;
}

.form-panel {
  position: sticky;
  top: 24px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
  outline: none;
}

input[type="date"],
input[type="month"] {
  display: block;
  height: 44px;
  line-height: 1.2;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value {
  min-height: 1.2em;
  text-align: left;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.signature-control {
  display: grid;
  gap: 10px;
}

.signature-preview {
  display: grid;
  min-height: 88px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fbff;
  overflow: hidden;
}

.signature-preview img {
  max-width: 100%;
  max-height: 110px;
  object-fit: contain;
}

.search {
  max-width: 220px;
}

.two-cols,
.three-cols {
  display: grid;
  gap: 12px;
}

.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.list {
  display: grid;
  gap: 12px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fbff;
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.item-title {
  margin: 0;
  font-weight: 800;
}

.item-subtitle,
.item-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.amount {
  color: var(--accent);
  font-weight: 800;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.item-actions button {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  color: var(--brand-dark);
  background: var(--soft);
  font-weight: 700;
}

.item-actions .delete {
  color: var(--danger);
  background: #fee2e2;
}

.empty-state:empty::before {
  content: "Aucune donnée pour le moment.";
  display: block;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.yearly-income {
  overflow-x: auto;
}

.yearly-table {
  min-width: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.yearly-row {
  display: grid;
  grid-template-columns: 0.8fr 0.9fr 1fr 1fr 1.2fr;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.yearly-row:first-child {
  border-top: 0;
}

.yearly-head {
  color: var(--muted);
  background: #f8fbff;
  font-size: 0.84rem;
  font-weight: 800;
}

.yearly-row strong:last-child {
  color: var(--accent);
}

.export-panel {
  max-width: 760px;
}

#exports-view.active {
  display: flex;
  align-items: flex-start;
}

.export-panel p {
  margin-top: 0;
  color: var(--muted);
  line-height: 1.6;
}

.export-email {
  margin-bottom: 16px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.import-control input {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 13px 16px;
  border-radius: 8px;
  color: white;
  background: #172033;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.58);
}

.document-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.58);
}

.document-preview-overlay[hidden],
.tutorial-overlay[hidden] {
  display: none;
}

.document-preview-dialog {
  display: grid;
  width: min(720px, 100%);
  max-height: min(82vh, 760px);
  border-radius: 8px;
  padding: 20px;
  background: white;
  box-shadow: 0 28px 70px rgba(30, 64, 175, 0.22);
}

.document-preview-dialog pre {
  min-height: 260px;
  max-height: 52vh;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: #f8fbff;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.55;
}

.document-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.tutorial-dialog {
  width: min(460px, 100%);
  border-radius: 8px;
  padding: 22px;
  background: white;
  box-shadow: 0 28px 70px rgba(30, 64, 175, 0.22);
}

.tutorial-step-count {
  margin-bottom: 10px;
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.tutorial-dialog h3 {
  margin: 0 0 10px;
  font-size: 1.28rem;
}

.tutorial-dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.tutorial-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    z-index: 1000;
    inset: 0 auto 0 0;
    width: 260px;
    height: 100vh;
    padding: 18px;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.18);
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .brand {
    margin-bottom: 24px;
  }

  .tabs {
    flex-direction: column;
    overflow: visible;
  }

  .tab {
    width: 100%;
    text-align: left;
  }

  .menu-overlay {
    position: fixed;
    z-index: 999;
    inset: 0;
    background: rgba(0, 0, 0, 0.38);
  }

  body.menu-open .menu-overlay {
    display: block;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 4px 14px rgba(30, 64, 175, 0.12);
    font-size: 1.25rem;
  }

  main {
    width: 100%;
    padding: 18px;
  }

  .metrics,
  .content-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }
}

@media (min-width: 981px) {
  .mobile-topbar-left {
    flex: 1;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-header,
  .item-top {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar .mobile-topbar-left {
    flex-direction: row;
    align-items: center;
  }

  .two-cols,
  .three-cols {
    grid-template-columns: 1fr;
  }

  .primary,
  .secondary,
  .ghost,
  .import-control {
    width: 100%;
  }

  .topbar-actions,
  .document-preview-actions,
  .tutorial-actions {
    width: 100%;
  }

  .document-preview-actions,
  .tutorial-actions {
    flex-direction: column;
  }
}
