/* ERP Immobilier — Portail & Téléchargements
   Design system extracted verbatim from erp/app/lib/core/theme.dart,
   erp/app/lib/shell/menu.dart, erp/app/lib/screens/dashboard.dart,
   and erp/app/lib/widgets/common.dart (Material 2 / Invoice Ninja tokens). */

@font-face {
  font-family: 'Roboto';
  src: url('assets/fonts/Roboto-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto';
  src: url('assets/fonts/Roboto-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto';
  src: url('assets/fonts/Roboto-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto';
  src: url('assets/fonts/Roboto-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'IBMPlexSansArabic';
  src: url('assets/fonts/IBMPlexSansArabic-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBMPlexSansArabic';
  src: url('assets/fonts/IBMPlexSansArabic-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBMPlexSansArabic';
  src: url('assets/fonts/IBMPlexSansArabic-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBMPlexSansArabic';
  src: url('assets/fonts/IBMPlexSansArabic-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Dim constants from theme.dart */
  --radius: 2px;
  --bar-height: 56px;
  --menu-width: 210px;

  /* Tokens.light(accentChoices['Anthracite'] = Color(0xFF454544)) */
  --canvas: #F3F4F6;
  --surface: #FFFFFF;
  --surface-alt: #EDEEF0;
  --border: #DFDFDF;
  --border-strong: #C4C4C4;
  --text: #212121;
  --muted: #616161;
  --faint: #9E9E9E;
  --accent: #454544;
  --accent-hover: #2F2E2E;
  --accent-soft: rgba(69, 69, 68, 0.11);
  --selected: #EDEEF0;
  --hover: #F7F7F7;
  --header: #454544;
  --sidebar: #454544;
  --footer: #161616;
  --create: #4C9A1C;
  --create-hover: #3F8216;

  /* Solid status blocks */
  --solid-neutral: #64748B;
  --solid-success: #4C9A1C;
  --solid-warning: #CD8900;
  --solid-danger: #B93700;

  /* Soft tone pairs */
  --tone-neutral-fg: #454544;
  --tone-neutral-bg: #EDEEF0;
  --tone-success-fg: #047857;
  --tone-success-bg: #E5F6EE;
  --tone-warning-fg: #B45309;
  --tone-warning-bg: #FEF3DC;

  /* Material 2 flat elevation */
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  --banner-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  --btn-shadow: 0 1px 2px rgba(0, 0, 0, 0.20);
  --snackbar-bg: #323232;

  --font-sans: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  /* Tokens.darkTheme(accentChoices['Anthracite'] = Color(0xFF454544)) */
  --canvas: #000000;
  --surface: #1B1C1E;
  --surface-alt: #26272A;
  --border: #393A3C;
  --border-strong: #4A4B4E;
  --text: #EEEEEE;
  --muted: #B0B0B0;
  --faint: #7A7A7A;
  --accent: #454544;
  --accent-hover: #575756;
  --accent-soft: rgba(255, 255, 255, 0.10);
  --selected: #26272A;
  --hover: #222326;
  --header: #222325;
  --sidebar: #1B1C1E;
  --footer: #000000;
  --create: #407535;
  --create-hover: #4C8A3F;

  --solid-neutral: #5B6675;
  --solid-success: #407535;
  --solid-warning: #A87000;
  --solid-danger: #8B3D40;

  --tone-neutral-fg: #C7C7C7;
  --tone-neutral-bg: #2A2B2E;
  --tone-success-fg: #4ADE9B;
  --tone-success-bg: #0F2A20;
  --tone-warning-fg: #F5B74F;
  --tone-warning-bg: #33260D;

  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.50);
  --banner-shadow: 0 1px 3px rgba(0, 0, 0, 0.50);
  --btn-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

html[lang="ar"] {
  --font-sans: 'IBMPlexSansArabic', 'Roboto', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background-color: var(--canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

body {
  display: flex;
  flex-direction: column;
}

button,
input,
a {
  font-family: inherit;
}

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

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ── Top App Bar (matches MenuPanel top cell + PageHeader, 56px) ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--bar-height);
  display: flex;
  align-items: stretch;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.topbar-brand {
  width: var(--menu-width);
  flex-shrink: 0;
  background-color: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #000000;
  color: #FFFFFF;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-main {
  flex: 1;
  min-width: 0;
  background-color: var(--header);
  color: #FFFFFF;
  padding: 0 12px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.header-btn {
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.header-btn:hover {
  background-color: rgba(255, 255, 255, 0.14);
}

.header-btn:focus-visible {
  outline: 2px solid #FFFFFF;
  outline-offset: -2px;
}

.icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

/* ── Main Centered Column (single viewport, centered, no scroll on desktop) ── */
.page-main {
  flex: 1;
  width: 100%;
  max-width: 852px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

/* ── Web Portal Card (matches _TreasuryCard flat header card) ── */
.portal-card {
  background-color: var(--header);
  color: #FFFFFF;
  border-radius: var(--radius);
  box-shadow: var(--banner-shadow);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.portal-card-info {
  flex: 1 1 260px;
  min-width: 0;
}

.portal-eyebrow {
  margin: 0 0 4px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
}

.portal-heading {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.25;
  color: #FFFFFF;
}

.portal-desc {
  margin: 0 0 10px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.88);
  max-width: 58ch;
}

.portal-url-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background-color: rgba(0, 0, 0, 0.18);
  border-radius: var(--radius);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  max-width: 100%;
}

.portal-url-text {
  direction: ltr;
  unicode-bidi: isolate;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-copy-btn {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  padding: 3px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease;
}

.portal-copy-btn:hover {
  color: #FFFFFF;
  background-color: rgba(255, 255, 255, 0.14);
}

.portal-card-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.portal-meta {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.78);
}

/* ── Buttons (matches FilledButton / OutlinedButton in theme.dart) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn-create {
  background-color: var(--create);
  color: #FFFFFF;
  box-shadow: var(--btn-shadow);
}

.btn-create:hover {
  background-color: var(--create-hover);
}

.btn-accent {
  background-color: var(--accent);
  color: #FFFFFF;
  box-shadow: var(--btn-shadow);
}

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

.btn-outline {
  background-color: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 400;
}

.btn-outline:hover {
  background-color: var(--hover);
}

.btn-lg {
  height: 46px;
  padding: 0 22px;
  font-size: 15px;
}

/* ── SectionCard (matches SectionCard in common.dart) ── */
.section-card {
  background-color: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.section-card-head {
  padding: 12px 18px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 400;
  color: var(--text);
}

.section-card-meta {
  font-size: 13px;
  color: var(--muted);
}

/* ── Download List Rows (matches TodoCard / EntityListTile) ── */
.dl-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dl-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  border-inline-start: 3px solid transparent;
  transition: background-color 120ms ease;
}

.dl-row:last-child {
  border-bottom: 0;
}

.dl-row:hover {
  background-color: var(--hover);
}

.dl-row.is-current {
  background-color: var(--selected);
  border-inline-start-color: var(--create);
}

.dl-row.is-current:hover {
  background-color: var(--selected);
}

.dl-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--tone-neutral-bg);
  color: var(--tone-neutral-fg);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.dl-row.is-current .dl-icon {
  background-color: var(--tone-success-bg);
  color: var(--tone-success-fg);
}

.dl-info {
  flex: 1;
  min-width: 0;
}

.dl-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dl-name {
  font-size: 15.5px;
  font-weight: 500;
  color: var(--text);
}

.dl-sub {
  margin-top: 2px;
  font-size: 13.5px;
  color: var(--muted);
}

.dl-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.dl-file-meta {
  text-align: end;
  min-width: 0;
}

.dl-filename {
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 13px;
  color: var(--text);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dl-filesize {
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 12px;
  color: var(--muted);
}

/* ── StatusChip (matches StatusChip in common.dart: solid block, 2px radius) ── */
.status-chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 400;
  color: #FFFFFF;
  background-color: var(--solid-neutral);
  white-space: nowrap;
}

.status-chip--success {
  background-color: var(--solid-success);
}

.card-note {
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  background-color: var(--surface-alt);
  font-size: 13.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-note svg {
  flex-shrink: 0;
  color: var(--tone-success-fg);
}

/* ── Minimal Footer ── */
.page-footer {
  text-align: center;
  font-size: 12.5px;
  color: var(--faint);
  padding-top: 4px;
}

/* ── Floating SnackBar (matches snackBarTheme in theme.dart) ── */
.snackbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
  width: max-content;
  background-color: var(--snackbar-bg);
  color: #FFFFFF;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
  transition: opacity 180ms ease, transform 180ms ease;
}

.snackbar.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* ── Responsive (matches Dim.mobileWidth = 700px) ── */
@media (max-width: 700px) {
  .topbar-brand {
    width: auto;
    background-color: var(--header);
    border-inline-end: 0;
    color: #FFFFFF;
    padding-inline-end: 4px;
  }

  .topbar-title {
    display: none;
  }

  .topbar-main {
    justify-content: flex-end;
    padding-inline-start: 0;
  }

  .page-main {
    justify-content: flex-start;
    padding: 12px 12px 24px;
  }

  .portal-card {
    padding: 16px;
    gap: 14px;
  }

  .portal-card-info {
    flex: 1 1 100%;
    max-width: 100%;
  }

  .portal-card-actions {
    width: 100%;
    align-items: stretch;
  }

  .portal-card-actions .btn {
    width: 100%;
  }

  .portal-meta {
    text-align: center;
  }

  .section-card-head {
    padding: 12px 14px 10px;
  }

  .dl-row {
    flex-wrap: wrap;
    padding: 14px;
    gap: 10px 12px;
  }

  .dl-right {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
  }

  .dl-file-meta {
    text-align: start;
    flex: 1 1 140px;
    min-width: 0;
  }

  .dl-right .btn {
    flex-shrink: 0;
  }

  .card-note {
    padding: 10px 14px;
  }
}

@media (max-width: 480px) {
  .dl-row {
    padding: 12px 14px;
    gap: 8px 12px;
  }

  .dl-right {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .dl-file-meta {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
  }

  .dl-right .btn {
    width: 100%;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
