:root {
  --bg: #f8fafc;
  --bg-muted: #f1f5f9;
  --surface: #ffffff;
  --card: rgba(255, 255, 255, 0.7);
  --card-border: rgba(255, 255, 255, 0.5);
  --card-soft: #f8fafc;
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --muted: #64748b;
  --text: #0f172a;
  --accent: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  --accent-contrast: #ffffff;
  --radius: 12px;
  --font-main: 'Poppins', sans-serif;
}

:root[data-theme='dark'] {
  --bg: #0f172a;
  --bg-muted: #1e293b;
  --surface: #1e293b;
  --card: rgba(30, 41, 59, 0.7);
  --card-border: rgba(255, 255, 255, 0.05);
  --card-soft: #334155;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --muted: #94a3b8;
  --text: #f8fafc;
  --accent: #60a5fa;
  --accent-gradient: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
  --accent-contrast: #0f172a;
}

* {
  box-sizing: border-box;
  font-family: var(--font-main), system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html,
body,
#app-container {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  /* Prevent text selection */
  -webkit-user-select: none;
}

/* Allow selection in inputs */
input,
textarea,
[contenteditable] {
  user-select: text;
  -webkit-user-select: text;
}

#app-container {
  position: relative;
  display: flex;
}

/* Sidebar */
#sidebar {
  width: 250px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
  flex-shrink: 0;
}

#sidebar.collapsed {
  width: 80px;
  padding: 20px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
  padding: 0 4px;
}

.logo {
  width: 40px;
  height: 40px;
  background: var(--accent-gradient);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 4px 6px rgba(59, 130, 246, 0.2);
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.025em;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
}

#sidebar.collapsed .brand-title {
  opacity: 0;
  pointer-events: none;
  display: none;
}

#nav-region {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#nav-region a,
#nav-region .nav-logout {
  padding: 12px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
  font-weight: 500;
  background: transparent;
  width: 100%;
  border: none;
  cursor: pointer;
}

#nav-region a:hover,
#nav-region .nav-logout:hover {
  background: var(--bg-muted);
  color: var(--text);
}

#nav-region a.active {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

.icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.label {
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s;
}

#sidebar.collapsed .label {
  opacity: 0;
  display: none;
}

#toggle-sidebar {
  margin-top: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

#toggle-sidebar:hover {
  background: var(--bg-muted);
  color: var(--text);
}

/* Main Area */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  margin-left: 0;
  /* managed by flex layout */
}

/* Topbar */
#topbar {
  height: 80px;
  /* Increased height */
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40px;
  /* Glassmorphism */
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

:root[data-theme='dark'] #topbar {
  background: rgba(15, 23, 42, 0.9);
}

#toggle-sidebar-top {
  display: none;
}

.left {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 100%;
}

.left .search {
  display: flex;
  align-items: center;
}

.left .search input {
  background: var(--bg-muted);
  border: 1px solid transparent;
  /* Removed visible border unless focused */
  padding: 12px 20px;
  border-radius: 99px;
  /* Fuller rounding */
  width: 350px;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.left .search input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
  outline: none;
}

/* Modern Select Styling */
select.modern-input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.25rem;
  padding-right: 3rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  background-color: var(--surface);
  /* Ensure contrast */
}

select.modern-input:hover {
  border-color: var(--accent);
  background-color: var(--card-soft);
}

select.modern-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  outline: none;
}

select.modern-input option {
  padding: 12px;
  background: var(--surface);
  color: var(--text);
}

.right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.top-actions {
  display: flex;
  gap: 12px;
}

#topbar button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  cursor: pointer;
  position: relative;
}

#topbar button:hover {
  background: var(--bg-muted);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  border: 2px solid var(--surface);
}

.profile {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-left: 24px;
  border-left: 2px solid var(--border);
  height: 40px;
}

.profile img {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

#profile-name {
  font-weight: 600;
  font-size: 0.95rem;
}

/* Main Content */
#main-content {
  flex: 1;
  padding: 40px;
  /* More padding around content */
  overflow-y: auto;
  scroll-behavior: smooth;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 50px;
  /* More space below header */
}

.page-eyebrow {
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 0 0 8px 0;
}

h2 {
  font-size: 2rem;
  font-weight: 800;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.page-subtitle {
  margin: 12px 0 0 0;
  color: var(--muted);
  font-size: 1rem;
  max-width: 600px;
  line-height: 1.5;
}

/* Cards & Glassmorphism */
.card {
  background: var(--card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  /* Larger radius */
  box-shadow: var(--shadow);
  padding: 30px;
  margin-bottom: 30px;
  /* More space between cards */
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.12);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.card-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.card-subtitle {
  margin: 6px 0 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

/* KPIs */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 30px;
  /* Increased gap */
  margin-bottom: 50px;
  /* Separation from grid */
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.3s ease;
}

.kpi:hover {
  transform: translateY(-4px);
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-gradient);
}

.kpi:nth-child(2)::before {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

/* Orange */
.kpi:nth-child(3)::before {
  background: linear-gradient(135deg, #10b981, #059669);
}

/* Green */
.kpi:nth-child(4)::before {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}

/* Red */

.kpi-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
}

.kpi-subtext {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 30px;
  /* Increased gap */
  margin-bottom: 50px;
  /* Space between grid and stack */
}

.dashboard-grid .card {
  margin-bottom: 0;
  height: 100%;
}

.card.stretch {
  grid-column: span 6;
}

/* 50% width on layout */
.dashboard-grid>.card:not(.stretch) {
  grid-column: span 3;
}

/* 25% width */

@media (max-width: 1200px) {
  .card.stretch {
    grid-column: span 12;
  }

  .dashboard-grid>.card:not(.stretch) {
    grid-column: span 6;
  }
}

@media (max-width: 768px) {

  .dashboard-grid>.card,
  .card.stretch {
    grid-column: span 12;
  }

  #sidebar {
    position: fixed;
    height: 100%;
    transform: translateX(-100%);
  }

  #sidebar.collapsed {
    transform: translateX(0);
    width: 250px;
  }

  /* Re-use logic for mobile open? No, logic needs update for full mobile drawer. Keeping simple for now */
  #main-area {
    margin-left: 0 !important;
  }

  #toggle-sidebar-top {
    display: block;
  }
}

/* Dashboard Stack (Calendar etc) */
.dashboard-stack {
  display: flex;
  flex-direction: column;
  gap: 50px;
  /* Increased gap between stacked items */
}

/* Lists */
.data-list li,
.simple-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.data-list li:hover {
  background: rgba(0, 0, 0, 0.01);
  padding-left: 8px;
  padding-right: 8px;
  margin: 0 -8px;
  border-radius: 6px;
  border-bottom-color: transparent;
}

.data-label {
  color: var(--text);
  font-weight: 500;
}

.data-meta,
.item-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-card .card-header {
  align-items: center;
}

.calendar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.calendar-body {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.calendar-grid {
  flex: 2;
  min-width: 320px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-cell {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--card-soft);
}

.calendar-cell--muted {
  opacity: 0.5;
}

.calendar-cell.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.calendar-date {
  font-weight: 600;
  font-size: 13px;
}

.calendar-pills {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-pill {
  display: inline-flex;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.15);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.calendar-pill.task-pill {
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
}

.calendar-side {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calendar-events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 300px;
  overflow: auto;
}

.calendar-events-list li {
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.calendar-events-list li:last-child {
  border-bottom: none;
}

.calendar-events-list .empty {
  font-style: italic;
  color: var(--muted);
  justify-content: flex-start;
}

.chart-canvas {
  width: 100%;
  height: 260px;
  display: block;
}

.calendar-event-info {
  flex: 1;
}

.calendar-event-title {
  font-weight: 600;
  font-size: 14px;
}

.calendar-event-date {
  font-size: 12px;
  color: var(--muted);
}

.calendar-event-chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted);
}

.calendar-events-list button {
  border: none;
  background: transparent;
  color: #ef4444;
  cursor: pointer;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  align-items: stretch
}

.dashboard-grid--two {
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

.simple-list {
  list-style: none;
  padding: 0;
  margin: 0
}

.simple-list li {
  padding: 6px 4px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04)
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px
}

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer
}

input,
select,
textarea {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  transition: border-color .15s, background .15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.kanban {
  display: flex;
  gap: 12px
}

.column {
  flex: 1
}

.column h4 {
  margin: 0 0 8px 0
}

.items {
  min-height: 120px;
  background: var(--card-soft);
  padding: 8px;
  border-radius: 8px;
  border: 1px dashed var(--border)
}

.task {
  background: var(--card-soft);
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  cursor: grab
}

.task .meta {
  font-size: 12px;
  color: var(--muted)
}

.task .task-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px
}

.task .task-title {
  font-weight: 600
}

.task .task-assignees {
  font-size: 12px;
  color: var(--muted)
}

.task.dragging {
  opacity: 0.5;
  transform: scale(0.98)
}

/* action buttons inside a task (icon-only, subtle) */
.task .task-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end
}

.task .task-actions button {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer
}

.task .task-actions button:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--text)
}

.task .task-actions svg {
  display: block;
  width: 14px;
  height: 14px
}

/* topbar icon buttons */
#topbar button {
  background: transparent;
  border: 0;
  padding: 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer
}

#topbar button:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text)
}

#topbar button svg {
  width: 18px;
  height: 18px
}

/* assignee chip */
.assignee {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 12px;
  margin-right: 6px;
  display: inline-block
}

/* Column header */
.column h4 {
  background: transparent;
  padding: 8px 6px;
  margin: 0 0 8px 0;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.04);
  font-size: 15px
}

/* Drag over highlight */
.items.drag-over {
  outline: 2px dashed rgba(37, 99, 235, 0.16);
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.02), transparent)
}

/* Modal form */
#modals {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none
}

#modals .modal {
  pointer-events: auto;
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 30px 60px rgba(2, 6, 23, 0.2);
  max-width: 720px;
  width: 100%
}

.modal .form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px
}

.modal .form-row.form-row-column {
  flex-direction: column;
  align-items: flex-start;
}

.modal .form-row.form-row-column label {
  width: 100%;
  margin-bottom: 6px;
}

.modal .form-row label {
  width: 130px;
  color: var(--muted)
}

.modal input,
.modal textarea,
.modal select {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 100%
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.modal textarea {
  min-height: 100px
}

.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px
}

.modal .btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border)
}


table {
  width: 100%;
  border-collapse: collapse
}

th,
td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid var(--border)
}

/* Prospects table tweaks */
.prospect-row {
  cursor: pointer
}

.prospect-row:hover {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.02), transparent)
}

.p-actions {
  width: 72px;
  display: flex;
  justify-content: flex-end
}

.p-actions button {
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer
}

.p-actions button i {
  width: 14px;
  height: 14px
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px
}

.form-row label {
  width: 120px;
  color: var(--muted)
}

.totals {
  margin-top: 8px
}

.form-actions {
  margin-top: 10px
}

#footer {
  padding: 12px;
  text-align: center;
  color: var(--muted)
}

/* Modal area */
#modals {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none
}

#modals .modal {
  pointer-events: auto;
  background: var(--card);
  padding: 16px;
  border-radius: 10px;
  box-shadow: 0 20px 40px rgba(2, 6, 23, 0.2);
  max-width: 720px;
  width: 100%
}

@media(max-width:900px) {
  .dashboard-grid {
    grid-template-columns: 1fr
  }

  #sidebar {
    display: none
  }

  #main-area {
    margin-left: 0
  }
}

/* collapsed sidebar visual tweaks */
#sidebar.collapsed .brand-title {
  display: none
}

#sidebar.collapsed #nav-region a {
  padding-left: 6px;
  justify-content: center
}

#sidebar.collapsed #nav-region a .label {
  display: none
}

#sidebar.collapsed #nav-region .nav-logout .label {
  display: none
}

#sidebar.collapsed #nav-region .nav-logout {
  padding-left: 6px;
  justify-content: center
}

#sidebar.collapsed .logo {
  margin: 0 auto
}

/* when sidebar is collapsed, show a tooltip with the link title on hover */
#sidebar.collapsed #nav-region a {
  position: relative
}

#sidebar.collapsed #nav-region a:hover::after,
#sidebar.collapsed #nav-region .nav-logout:hover::after {
  content: attr(title);
  position: absolute;
  left: 78px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--card);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.12);
  border: 1px solid var(--border);
  white-space: nowrap;
  z-index: 60;
}

#sidebar.collapsed #nav-region .nav-logout {
  position: relative
}

/* ensure main-area content has comfortable top spacing when sidebar is fixed */
@media(min-width:901px) {
  #topbar {
    padding-left: 12px;
    padding-right: 24px
  }
}

/* Quote editor: two-column layout */
.two-col {
  display: flex;
  gap: 16px;
  align-items: stretch
}

.two-col .card.left {
  flex: 1 1 55%;
  min-width: 300px
}

.two-col .card.right {
  flex: 1 1 45%;
  min-width: 280px
}

/* Make the left and right cards fill available vertical space and scroll internally if content overflows */
.two-col .card.left,
.two-col .card.right {
  height: calc(100vh - 160px);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.two-col .card.left .form-row {
  flex: 0 0 auto
}

.two-col .card.right .quote-preview {
  flex: 1 1 auto
}

/* Keep the form content left-aligned and constrain width so it starts from the left */
.two-col .card.left {
  align-items: stretch
}

.two-col .card.left .form-body {
  width: 720px;
  max-width: 100%;
  padding-left: 8px
}

.two-col .card.left h3 {
  margin: 0 0 14px 0;
  padding-left: 8px;
  font-size: 18px
}

.two-col .card.left .form-row.inline label {
  width: 100px
}

.two-col .card.left .form-actions {
  padding-left: 8px
}

.quote-preview .quote-sheet {
  background: var(--card);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text)
}

.quote-preview table td,
.quote-preview table th {
  padding: 6px;
  border-bottom: 1px solid var(--border)
}

.quotes-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px
}

.q-actions button {
  background: transparent;
  border: 0;
  padding: 6px;
  margin-left: 6px;
  cursor: pointer;
  color: var(--muted)
}

.q-actions button:hover {
  color: var(--text)
}

/* Button variants */
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 0;
  padding: 8px 12px;
  border-radius: 8px
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px
}

.btn-link {
  background: transparent;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  padding: 6px
}

@media(max-width:900px) {
  .two-col {
    flex-direction: column
  }

  .two-col .card.left,
  .two-col .card.right {
    min-width: unset;
    height: auto
  }
}

/* Ensure form rows in the left card are stacked and do not overflow into the preview */
.two-col .card.left .form-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin-bottom: 12px
}

.two-col .card.left .form-row label {
  width: auto;
  margin-bottom: 6px
}

.two-col .card.left .form-row input,
.two-col .card.left .form-row textarea,
.two-col .card.left .form-row select {
  width: 100%;
  box-sizing: border-box
}

/* If you want compact fields on the same line, use .form-row.inline */
.two-col .card.left .form-row.inline {
  flex-direction: row;
  align-items: center;
  gap: 10px
}

.two-col .card.left .form-row.inline label {
  width: 120px;
  margin-bottom: 0
}

/* Global Search Dropdown */
.search {
  position: relative;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  margin-top: 6px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-item:hover {
  background: rgba(37, 99, 235, 0.08);
}

.search-result-item:last-child {
  border-bottom: none;
}

.sr-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.sr-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.sr-type {
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
}

/* Preload state to prevent FOUC */
html.preload-sidebar-collapsed #sidebar {
  width: 70px !important;
  transition: none !important;
}

html.preload-sidebar-collapsed #main-area {
  margin-left: 70px !important;
  transition: none !important;
}

html.preload-sidebar-collapsed #sidebar .brand-title {
  display: none !important;
}

html.preload-sidebar-collapsed #sidebar #nav-region a .label {
  display: none !important;
}

html.preload-sidebar-collapsed #sidebar .logo {
  margin: 0 auto !important;
}

html.preload-sidebar-collapsed #sidebar #nav-region a {
  padding-left: 6px !important;
  justify-content: center !important;
}

html.preload-sidebar-collapsed #sidebar #nav-region .nav-logout .label {
  display: none !important;
}

html.preload-sidebar-collapsed #sidebar #nav-region .nav-logout {
  padding-left: 6px !important;
  justify-content: center !important;
}

/* Notification Dropdown */
.notification-dropdown {
  position: absolute;
  top: 60px;
  right: 20px;
  width: 320px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  z-index: 100;
  display: none;
  flex-direction: column;
  max-height: 400px;
  overflow-y: auto;
}

.notification-dropdown.active {
  display: flex;
}

.notification-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notification-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.notification-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  transition: background 0.2s;
}

.notification-item:hover {
  background: rgba(37, 99, 235, 0.08);
}

.notification-item:last-child {
  border-bottom: none;
}

.notification-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notification-icon.warning {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.notification-content {
  flex: 1;
}

.notification-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.notification-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.notification-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Quick search dropdown */
.quick-search-dropdown {
  position: absolute;
  z-index: 200;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  padding: 6px;
  display: none;
}

.quick-search-dropdown.active {
  display: block;
}

.quick-search-item {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quick-search-item .label {
  font-weight: 600;
  color: var(--text);
}

.quick-search-item .desc {
  font-size: 12px;
  color: var(--muted);
}

.quick-search-item:hover,
.quick-search-item.active {
  background: rgba(37, 99, 235, 0.12);
}

.quick-search-empty {
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* -------- Paramètres -------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 4px 0;
}

.page-subtitle {
  margin: 4px 0 0 0;
  color: var(--muted);
  max-width: 480px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.role-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
}

.settings-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.settings-card--wide {
  grid-column: 1 / -1;
}

.settings-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.card-subtitle {
  margin: 4px 0 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.form-field span {
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.switch-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.switch-field p {
  margin: 4px 0 0 0;
  color: var(--muted);
  font-size: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.2);
  transition: .2s;
  border-radius: 999px;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .2s;
  border-radius: 50%;
}

.switch input:checked+.slider {
  background: var(--accent);
}

.switch input:checked+.slider:before {
  transform: translateX(20px);
}

.branding-block {
  display: flex;
  gap: 18px;
  align-items: stretch;
  flex-wrap: wrap;
  width: 100%;
}

.logo-preview {
  width: 140px;
  height: 140px;
  border: 1px dashed rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.02);
  padding: 12px;
}

.logo-preview img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 12px;
  margin-bottom: 6px;
}

.branding-block .form-grid {
  flex: 1;
  min-width: 220px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.table-wrapper {
  overflow-x: auto;
}

#user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#user-table th,
#user-table td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
}

.table-action {
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent);
  border: 0;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.table-action.danger {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-cell img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-weight: 600;
}

.user-username {
  font-size: 12px;
  color: var(--muted);
}

.user-form {
  margin-bottom: 16px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.user-form-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.settings-feedback {
  margin-top: 20px;
  min-height: 20px;
  font-weight: 600;
  color: var(--accent);
  transition: opacity .2s;
  opacity: 0;
}

.settings-feedback.success {
  opacity: 1;
}

.settings-feedback.error {
  opacity: 1;
  color: #ef4444;
}

.btn-text {
  background: transparent;
  color: var(--accent);
  padding: 0;
  border: none;
}

.muted {
  color: var(--muted);
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}

/* Quick Search Dropdown */
.quick-search-dropdown {
  position: absolute;
  background: var(--surface);
  /* Fallback */
  background: rgba(255, 255, 255, 0.98);
  /* Almost opaque */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 1000;
  display: none;
  max-height: 400px;
  overflow-y: auto;
}

:root[data-theme='dark'] .quick-search-dropdown {
  background: rgba(30, 41, 59, 0.98);
  border-color: var(--border);
}

.quick-search-dropdown.active {
  display: block;
}

.quick-search-item {
  width: 100%;
  text-align: left;
  padding: 14px 18px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
  display: block;
}

.quick-search-item:last-child {
  border-bottom: none;
}

.quick-search-item:hover,
.quick-search-item.active {
  background: var(--bg-muted);
}

.quick-search-item .label {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 3px;
  color: var(--text);
}

.quick-search-item .desc {
  font-size: 0.8rem;
  color: var(--muted);
}

.quick-search-empty {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
}