:root {
  --bg: #0f0d1a;
  --panel: #171428;
  --card: #1e1a33;
  --line: rgba(255,255,255,0.08);
  --text: #f5f3ff;
  --muted: rgba(245,243,255,0.65);
  --primary: #7F77DD;
  --primary-deep: #534AB7;
  --danger: #e35d6a;
  --ok: #1D9E75;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 70% 40% at 10% 0%, rgba(127,119,221,0.25), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.is-login {
  overflow: hidden;
}

body.is-login #app-view {
  display: none !important;
}

body.is-app #login-view {
  display: none !important;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 20;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(127,119,221,0.28), transparent 55%),
    var(--bg);
}

.login-card, .panel, .table-wrap, dialog {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(10px);
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
}

.brand { text-align: center; margin-bottom: 22px; }
.brand h1 { margin: 10px 0 6px; font-size: 1.8rem; }
.brand p, .muted, .hint { color: var(--muted); }
.hint { font-size: 0.82rem; margin: 8px 0 16px; }

.brand-mark {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary-deep), var(--primary));
  font-size: 1.8rem;
  box-shadow: 0 12px 30px rgba(83,74,183,0.35);
}
.brand-mark.sm { width: 40px; height: 40px; font-size: 1.1rem; margin: 0; }

label { display: block; font-size: 0.85rem; font-weight: 700; margin: 12px 0 6px; }
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  color-scheme: dark;
}
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
select option,
select optgroup {
  background-color: #1a1630;
  color: #f5f3ff;
}
select option:checked,
select option:hover {
  background-color: #534AB7;
  color: #ffffff;
}
input[type="file"] {
  padding: 10px;
  font-size: 0.85rem;
}
input[type="file"]::file-selector-button {
  margin-right: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(127,119,221,0.2);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
textarea { resize: vertical; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
}
.btn.primary {
  background: linear-gradient(135deg, var(--primary-deep), var(--primary));
  color: white;
  width: 100%;
  margin-top: 8px;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn.danger {
  background: rgba(227,93,106,0.15);
  color: #ffb4bc;
}
.btn.small { padding: 8px 10px; font-size: 0.8rem; width: auto; }

.password-field {
  position: relative;
}
.password-field input {
  padding-right: 48px;
}
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
}
.password-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

.error { color: #ffb4bc; margin-top: 10px; font-size: 0.9rem; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: rgba(0,0,0,0.2);
}
.sidebar-brand {
  display: flex; gap: 10px; align-items: center; padding: 6px 8px;
}
.sidebar-brand span { display: block; color: var(--muted); font-size: 0.75rem; }
nav { display: grid; gap: 6px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}
.nav-item.active, .nav-item:hover {
  background: rgba(127,119,221,0.15);
  color: white;
}

.main { padding: 22px; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0 0 4px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.top-actions .btn.primary { width: auto; margin: 0; }
#search { min-width: 220px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.center { text-align: center; }
.product-name { font-weight: 800; }
.product-brand { color: var(--muted); font-size: 0.82rem; }
.price { color: #cfc9ff; font-weight: 800; }
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(29,158,117,0.15);
  color: #9FE1CB;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge.out { background: rgba(227,93,106,0.15); color: #ffb4bc; }
.row-actions { display: flex; gap: 8px; }

dialog {
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0;
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  background: #1a1630;
  color-scheme: dark;
  overflow: hidden;
}
dialog::backdrop { background: rgba(0,0,0,0.65); }
#product-form {
  padding: 22px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding-bottom: 88px;
}
.grid-2, .grid-3 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.dialog-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 16px -22px -22px;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent, #1a1630 28%);
  border-top: 1px solid var(--line);
}
.dialog-actions .btn.primary { width: auto; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { display: flex; flex: 1; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Demandes de devis */
.nav-item .badge {
  margin-left: 6px;
  padding: 2px 7px;
  background: rgba(227, 93, 106, 0.2);
  color: #ffb4bc;
  font-size: 0.7rem;
}
.row-new { background: rgba(250, 199, 117, 0.06); }
.quote-details {
  max-width: 320px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}
.quote-status {
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: inherit;
  font-weight: 700;
  font-size: 0.82rem;
}
.quote-status:disabled { opacity: 0.5; }
