:root {
  --mf-fs-100: clamp(0.95rem, 0.25vw + 0.9rem, 1rem);
  --mf-fs-200: clamp(1rem, 0.35vw + 0.92rem, 1.1rem);
  --mf-fs-300: clamp(1.15rem, 0.8vw + 1rem, 1.45rem);
  --mf-fs-400: clamp(1.35rem, 1.2vw + 1rem, 1.95rem);

  --mf-space-2: 0.5rem;
  --mf-space-3: 0.75rem;
  --mf-space-4: 1rem;
  --mf-space-5: 1.25rem;

  --mf-radius-sm: 12px;
  --mf-radius-md: 16px;
  --mf-shadow: 0 12px 30px rgba(16, 47, 96, 0.09);

  --mf-bg: #f4f8ff;
  --mf-surface: #ffffff;
  --mf-border: #d6e2f7;
  --mf-text: #13213d;
  --mf-muted: #5b6f95;
  --mf-primary: #1764db;
  --mf-focus: #7fb0ff;
}

* {
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
}

body {
  color: var(--mf-text);
  font-size: var(--mf-fs-100);
}

h1 {
  font-size: var(--mf-fs-400);
}

h2 {
  font-size: var(--mf-fs-300);
}

h3 {
  font-size: var(--mf-fs-200);
}

p,
li,
label,
input,
select,
textarea,
button,
a {
  font-size: max(16px, 1em);
}

input:not([type='checkbox']):not([type='radio']),
select,
textarea {
  min-height: 48px;
}

button,
.btn,
a.btn,
.nav-link,
.menu-btn,
[role='button'] {
  min-height: 44px;
}

button,
.btn,
input,
select,
textarea {
  border-radius: var(--mf-radius-sm);
}

:focus-visible {
  outline: 3px solid var(--mf-focus);
  outline-offset: 2px;
}

section,
.surface,
.hero-visual,
.card {
  border-radius: var(--mf-radius-md);
}

.container,
section,
.surface {
  width: 100%;
}

.main-shell,
.page-content,
section,
.surface,
.container {
  padding-left: clamp(16px, 4vw, 20px);
  padding-right: clamp(16px, 4vw, 20px);
}

.auth-page {
  padding: 16px;
}

.auth-page .auth-card {
  width: min(100%, 460px);
  margin-left: auto;
  margin-right: auto;
  padding-left: clamp(16px, 4vw, 26px);
  padding-right: clamp(16px, 4vw, 26px);
}

.container {
  max-width: 1240px;
  margin-left: auto;
  margin-right: auto;
}

@media (max-width: 1439px) {
  body.app-shell .main-shell,
  body.app-shell .page-content {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }
}

@media (min-width: 480px) {
  .auth-card,
  section,
  .surface {
    padding-top: var(--mf-space-5);
    padding-bottom: var(--mf-space-5);
  }
}

@media (max-width: 767px) {
  body.app-shell {
    font-size: 15px;
  }

  body.app-shell .main-shell {
    padding: 10px;
  }

  body.app-shell .page-content {
    margin-top: 10px;
    gap: 10px;
    padding-left: 0;
    padding-right: 0;
  }

  body.app-shell .surface,
  body.app-shell section.surface,
  body.legacy-page .page-content > section {
    padding: 10px;
    border-radius: 12px;
  }

  body.app-shell .topbar {
    position: sticky;
    top: 0;
    padding: 8px 10px;
    gap: 8px;
    border-radius: 10px;
  }

  body.app-shell .topbar__left,
  body.app-shell .topbar__right {
    gap: 8px;
  }

  body.app-shell .topbar__title {
    font-size: 1rem;
    line-height: 1.2;
  }

  body.app-shell #welcomeUser {
    display: none;
  }

  body.app-shell .menu-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  body.app-shell button,
  body.app-shell .btn,
  body.app-shell input:not([type='checkbox']):not([type='radio']),
  body.app-shell select,
  body.app-shell textarea {
    min-height: 40px;
  }

  body.app-shell input,
  body.app-shell select,
  body.app-shell textarea,
  body.app-shell button,
  body.app-shell .btn {
    font-size: 0.92rem;
  }

  body.app-shell label {
    margin: 6px 0 4px;
    font-size: 0.84rem;
  }

  body.legacy-page .legacy-form-grid,
  body.legacy-page .legacy-tools,
  body.legacy-page .legacy-actions,
  body.legacy-page .list-tools {
    gap: 8px;
  }

  body.legacy-page .legacy-block {
    padding: 8px;
  }

  body.legacy-page .line-section-title,
  body.legacy-page section > h2,
  body.legacy-page section > h3 {
    margin-bottom: 8px;
  }

  .table-wrap,
  #result,
  #usersResult,
  #unverifiedResult,
  #activityResult,
  #linesResult,
  #healthResult,
  #auditResult,
  #loginStatsResult,
  #trendResult {
    overflow: visible;
  }

  table,
  .data-table {
    width: 100%;
    min-width: 0 !important;
    border: 0;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
  }

  table thead,
  .data-table thead {
    display: none;
  }

  table tbody,
  .data-table tbody {
    display: grid;
    gap: 8px;
  }

  table tr,
  .data-table tr {
    display: block;
    border: 1px solid var(--mf-border);
    border-radius: var(--mf-radius-md);
    background: var(--mf-surface);
    box-shadow: var(--mf-shadow);
    padding: 8px;
  }

  table td,
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 3px;
    border-top: 0;
    text-align: left;
    word-break: break-word;
  }

  table td::before,
  .data-table td::before {
    content: attr(data-label);
    color: var(--mf-muted);
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 38%;
  }

  table td:last-child,
  .data-table td:last-child {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
  }

  table td:last-child::before,
  .data-table td:last-child::before {
    width: 100%;
    min-width: 100%;
    margin-bottom: 4px;
  }

  .list-tools,
  .legacy-tools,
  .inline-tools,
  .auth-actions,
  .dashboard-links {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (min-width: 768px) {
  .container,
  .main-shell,
  .page-content {
    padding-left: 20px;
    padding-right: 20px;
  }

  .auth-page .auth-card {
    width: min(100%, 520px);
  }
}

@media (min-width: 1024px) {
  .container,
  .main-shell,
  .page-content {
    padding-left: 24px;
    padding-right: 24px;
  }
}

.legacy-search-toggle {
  margin-bottom: 10px;
}

.search-params-panel[hidden] {
  display: none !important;
}

/* Pixel polish: Dashboard + Clients + Factures */
.topbar {
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(15, 47, 103, 0.08);
}

.topbar__right .btn,
.topbar__right .select-wrap select {
  min-height: 44px;
}

body[data-page='dashboard'] .surface h2,
body[data-page='app'] .surface h2 {
  margin-bottom: 6px;
}

body[data-page='dashboard'] .kpi-grid .card,
body[data-page='app'] .kpi-grid .card {
  border: 1px solid #d9e6fb;
  box-shadow: 0 10px 24px rgba(17, 56, 121, 0.08);
}

body[data-page='dashboard'] .kpi-grid .card .btn,
body[data-page='app'] .kpi-grid .card .btn {
  width: 100%;
}

body.legacy-page .legacy-block--form {
  background: linear-gradient(180deg, #fbfdff 0%, #f5f9ff 100%);
}

body.legacy-page .legacy-block--list {
  background: #ffffff;
}

body.legacy-page .legacy-field {
  padding: 8px;
  border: 1px solid #e3ebfa;
  border-radius: 12px;
  background: #fff;
}

body.legacy-page .legacy-field label {
  margin: 0;
  font-size: 0.9rem;
}

body.legacy-page .legacy-actions {
  padding-top: 6px;
}

body.legacy-page .legacy-search-toggle {
  margin-bottom: 10px;
}

body[data-page='clients'] .legacy-block--list .legacy-tools,
body[data-page='invoices'] .legacy-block--list .legacy-tools {
  background: linear-gradient(180deg, #f7fbff 0%, #eef5ff 100%);
}

@media (max-width: 767px) {
  body.legacy-page .legacy-actions .btn,
  body.legacy-page .legacy-actions button {
    width: 100%;
  }

  body.legacy-page .legacy-field {
    padding: 10px;
  }

  body[data-page='clients'] table tr,
  body[data-page='invoices'] table tr {
    border-left: 4px solid #8db6ff;
  }
}

@media (min-width: 768px) {
  body.legacy-page .legacy-form-grid {
    gap: 14px;
  }

  body[data-page='clients'] .legacy-form-grid,
  body[data-page='invoices'] .legacy-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
