:root {
  color-scheme: dark;
  --background: #1c1c21;
  --foreground: #f4f4f5;
  --muted: #27272c;
  --muted-foreground: #b4b4bb;
  --border: #3f3f46;
  --input: #3f3f46;
  --ring: #d4d4d8;
  --primary: #f4f4f5;
  --primary-foreground: #18181b;
  --secondary: #2e2e35;
  --secondary-foreground: #f4f4f5;
  --destructive: #f87171;
  --destructive-foreground: #18181b;
  --card: #232329;
  --card-foreground: #f4f4f5;
  --radius: 0.125rem;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  --font-sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --sidebar-width: 15rem;
  --sidebar-bg: #1a1a1f;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  background:
    radial-gradient(ellipse 70% 45% at 0% -10%, #2a2a35 0%, transparent 55%),
    radial-gradient(ellipse 50% 35% at 100% 0%, #262630 0%, transparent 50%),
    var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  align-items: start;
}

.mobile-topbar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.icon-btn.mobile-nav-close {
  display: none;
}

.desktop-only {
  display: inline-flex;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-sizing: border-box;
}

.brand {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  padding: 0.25rem 0.5rem;
}

.brand span {
  color: var(--muted-foreground);
  font-weight: 500;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 0.925rem;
  min-height: 2.5rem;
}

.nav a:hover,
.nav a.is-active {
  background: var(--muted);
  color: var(--foreground);
  text-decoration: none;
}

.nav .icon,
.btn .icon,
.icon {
  display: inline-flex;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.nav .icon svg,
.btn .icon svg,
.icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-fill svg {
  fill: currentColor;
  stroke: none;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted-foreground);
}

.sidebar-user .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--foreground);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--foreground);
  text-decoration: none;
  flex-shrink: 0;
}

.icon-btn.is-active,
.icon-btn:hover {
  background: #3f3f46;
  text-decoration: none;
}

.role-crown {
  color: #fbbf24;
  display: inline-flex;
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.role-crown svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.main {
  padding: 1.75rem 2rem 3rem;
  max-width: 1100px;
  width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.page-header p {
  margin: 0.35rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.925rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 2.25rem;
  padding: 0 0.9rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  text-decoration: none;
  opacity: 0.94;
}

.btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}

.btn-logout {
  background: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
  width: 100%;
}

.btn-logout:hover {
  background: #3f3f46;
}

.btn-destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
}

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.card-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.card-desc {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.stat-label {
  color: var(--muted-foreground);
  font-size: 0.8rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-field label {
  font-size: 0.875rem;
  font-weight: 500;
}

.form-field .help {
  font-size: 0.8rem;
  color: var(--muted-foreground);
}

.form-field .error {
  font-size: 0.8rem;
  color: var(--destructive);
}

.input,
.select,
.textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="url"],
input[type="file"],
select,
textarea {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: #1f1f24;
  color: var(--foreground);
  font: inherit;
  font-size: 0.875rem;
}

input[type="file"] {
  height: auto;
  padding: 0.45rem 0.5rem;
}

textarea,
.textarea {
  height: auto;
  min-height: 5rem;
  padding: 0.6rem 0.75rem;
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
  border-color: var(--ring);
}

select[multiple],
.select[multiple] {
  height: auto;
  min-height: 8rem;
  padding: 0.4rem 0.5rem;
  overflow-y: auto;
}

select[multiple] option,
.select[multiple] option {
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius);
}

/* Dropdown multi-select */
.ms-dropdown {
  position: relative;
  width: 100%;
}

.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: #1f1f24;
  color: var(--foreground);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
}

.ms-trigger:hover {
  border-color: var(--border);
}

.ms-trigger:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
  border-color: var(--ring);
}

.ms-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-summary.is-placeholder {
  color: var(--muted-foreground);
}

.ms-caret {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--muted-foreground);
  border-bottom: 1.5px solid var(--muted-foreground);
  transform: rotate(45deg);
  margin-top: -0.2rem;
  flex-shrink: 0;
}

.ms-panel {
  position: absolute;
  z-index: 35;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 14rem;
  overflow-y: auto;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

.ms-panel[hidden] {
  display: none;
}

.ms-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--foreground);
}

.ms-option:hover {
  background: var(--muted);
}

.ms-option input {
  width: auto;
  height: auto;
  margin: 0;
  accent-color: var(--foreground);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

table.data th {
  font-weight: 550;
  color: var(--muted-foreground);
  background: var(--muted);
}

table.data tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 1.35rem;
  padding: 0 0.45rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--muted);
  font-size: 0.7rem;
  font-weight: 550;
  color: var(--muted-foreground);
  text-transform: lowercase;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.message {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.875rem;
}

.message.success {
  border-color: #14532d;
  background: #052e16;
  color: #bbf7d0;
}

.message.error {
  border-color: #7f1d1d;
  background: #450a0a;
  color: #fecaca;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

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

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
}

.auth-card .sub {
  margin: 0 0 1.25rem;
  color: var(--muted-foreground);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted-foreground);
}

.field-grid {
  display: grid;
  gap: 0.75rem;
}

.field-row-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--card);
}

.org-switch select {
  max-width: 12rem;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted-foreground);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(24, 24, 27, 0.5);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input {
  width: auto;
  height: auto;
}

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: min(100%, 440px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  background: var(--card);
  color: var(--card-foreground);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--secondary);
  color: var(--foreground);
  text-decoration: none;
  cursor: pointer;
  padding: 0;
}

.icon-btn-sm:hover {
  background: #3f3f46;
  text-decoration: none;
}

.icon-btn-sm .icon {
  width: 0.95rem;
  height: 0.95rem;
}

.label-hint {
  cursor: help;
  border-bottom: 1px dotted var(--muted-foreground);
}

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.party-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 700px) {
  .party-grid {
    grid-template-columns: 1fr;
  }
}

.party-grid .card {
  margin: 0;
}

/* Product filter bar */
.filters-bar {
  display: grid;
  grid-template-columns: minmax(10rem, 1.4fr) repeat(3, minmax(8.5rem, 1fr)) auto;
  gap: 0.75rem;
  align-items: end;
}

.filters-bar-invoice {
  grid-template-columns: minmax(10rem, 1.6fr) minmax(10rem, 1.2fr) minmax(8rem, 0.9fr) auto;
}

@media (max-width: 900px) {
  .filters-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .filters-bar {
    grid-template-columns: 1fr;
  }
}

.date-range {
  position: relative;
}

.date-range-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: #1f1f24;
  color: var(--foreground);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
}

.date-range-trigger:hover {
  border-color: var(--border);
}

.date-range-trigger:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
  border-color: var(--ring);
}

.date-range-trigger .icon {
  width: 1rem;
  height: 1rem;
  color: var(--muted-foreground);
  flex-shrink: 0;
}

.date-range-trigger .value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-range-trigger .value.is-placeholder {
  color: var(--muted-foreground);
}

.date-range-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 17.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.date-range-panel[hidden] {
  display: none;
}

.date-range-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.date-range-nav .month-label {
  font-size: 0.875rem;
  font-weight: 600;
}

.date-range-hint {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.date-range-weekdays,
.date-range-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.15rem;
}

.date-range-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted-foreground);
  padding: 0.2rem 0;
}

.date-range-days button {
  height: 1.85rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}

.date-range-days button:hover:not(:disabled) {
  background: var(--muted);
}

.date-range-days button:disabled {
  color: transparent;
  cursor: default;
}

.date-range-days button.in-range {
  background: rgba(244, 244, 245, 0.08);
  border-radius: 0;
}

.date-range-days button.range-start,
.date-range-days button.range-end,
.date-range-days button.selected {
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: var(--radius);
}

.date-range-days button.range-start.range-end {
  border-radius: var(--radius);
}

.date-range-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.field-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.btn-sm {
  height: 1.85rem;
  padding: 0 0.65rem;
  font-size: 0.8rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ——— Smartphone / small screens ——— */
@media (max-width: 860px) {
  body.nav-locked {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    position: sticky;
    top: 0;
    z-index: 30;
    height: 3.25rem;
    padding: 0 0.75rem;
    padding-top: env(safe-area-inset-top, 0);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
  }

  .mobile-brand {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .desktop-only {
    display: none !important;
  }

  .icon-btn.mobile-nav-close {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.55);
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(18rem, 86vw);
    height: 100vh;
    max-height: 100dvh;
    padding-top: calc(1rem + env(safe-area-inset-top, 0));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }

  .main {
    padding: 1rem 0.85rem 2.5rem;
    padding-bottom: calc(2.5rem + env(safe-area-inset-bottom, 0));
    max-width: none;
  }

  .page-header {
    margin-bottom: 1rem;
    gap: 0.75rem;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .page-header .row,
  .page-header > .btn,
  .page-header > a.btn {
    width: 100%;
  }

  .page-header .row .btn,
  .page-header > a.btn {
    flex: 1;
    min-width: 0;
  }

  .card {
    padding: 1rem;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .filters-bar {
    grid-template-columns: 1fr;
  }

  .filters-bar .row {
    width: 100%;
  }

  .filters-bar .row .btn {
    flex: 1;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    margin-left: -0.15rem;
    margin-right: -0.15rem;
  }

  table.data {
    min-width: 36rem;
    font-size: 0.8125rem;
  }

  table.data th,
  table.data td {
    padding: 0.65rem 0.7rem;
    white-space: nowrap;
  }

  .btn {
    min-height: 2.5rem;
  }

  .icon-btn,
  .icon-btn-sm,
  .mobile-nav-toggle {
    width: 2.5rem;
    height: 2.5rem;
  }

  .input,
  .select,
  .textarea,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="url"],
  input[type="search"],
  input[type="file"],
  select,
  textarea,
  .ms-trigger,
  .date-range-trigger {
    min-height: 2.5rem;
    font-size: 1rem; /* avoid iOS zoom on focus */
  }

  .org-switch select {
    max-width: none;
    width: 100%;
  }

  .modal {
    width: calc(100vw - 1.5rem);
    max-width: none;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    margin: auto;
    padding: 1rem;
  }

  .date-range-panel {
    left: 0;
    right: 0;
    min-width: 0;
    width: 100%;
  }

  .date-range-days button {
    height: 2.35rem;
    font-size: 0.875rem;
  }

  .field-grid {
    grid-template-columns: 1fr !important;
  }

  .auth-shell {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  }

  .auth-card {
    width: 100%;
  }

  .messages {
    margin-bottom: 0.75rem;
  }

  .message {
    font-size: 0.8125rem;
  }
}

@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 1.15rem;
  }
}

