/* ===== Wine Theme Variables ===== */
:root {
  --wine: #722f37;
  --wine-light: #9b4d56;
  --wine-dark: #5a1f28;
}

/* ===== Base ===== */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}
a { text-decoration: none; }

/* ===== Sidebar Nav ===== */
.nav-link {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,.5);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: 2px;
}
.nav-link:hover {
  background-color: rgba(255,255,255,0.05);
  color: rgba(255,255,255,.85);
  transform: translateX(2px);
}
.nav-link.active {
  background: linear-gradient(135deg, var(--wine), var(--wine-dark));
  color: #fff !important;
  box-shadow: 0 2px 12px rgba(114,47,55,0.25);
}

/* Light theme */
html:not(.dark) .nav-link { color: rgba(0,0,0,.5); }
html:not(.dark) .nav-link:hover { background-color: rgba(0,0,0,0.04); color: rgba(0,0,0,.8); }
html:not(.dark) .nav-link.active { color: #fff !important; }
html:not(.dark) #sidebar { background-color: #fff !important; border-right-color: rgba(0,0,0,.05) !important; }
html:not(.dark) #page-content { background-color: #f5f6f8 !important; }
html:not(.dark) body { background-color: #f5f6f8 !important; color: #1a1a2e !important; }
html:not(.dark) .card-tw { background-color: #fff !important; border-color: rgba(0,0,0,0.05) !important; }
html:not(.dark) .task-tracker { background: rgba(255,255,255,0.85) !important; backdrop-filter: blur(16px); border-color: rgba(0,0,0,0.08) !important; }
html:not(.dark) .task-item { background-color: rgba(0,0,0,0.02) !important; }
html:not(.dark) .kanban-card { background-color: #fff !important; border-color: rgba(0,0,0,0.05) !important; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
html:not(.dark) .kanban-column { background-color: #f0f2f5 !important; }

/* ===== Flash Alerts ===== */
.flash-alert {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  backdrop-filter: blur(8px);
  animation: flash-slide-in 0.3s ease-out;
}
@keyframes flash-slide-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.flash-success { background: rgba(34,197,94,0.1); color: #22c55e; border: 1px solid rgba(34,197,94,0.15); }
.flash-danger  { background: rgba(239,68,68,0.1); color: #ef4444; border: 1px solid rgba(239,68,68,0.15); }
.flash-warning { background: rgba(234,179,8,0.1); color: #eab308; border: 1px solid rgba(234,179,8,0.15); }
.flash-info    { background: rgba(59,130,246,0.1); color: #3b82f6; border: 1px solid rgba(59,130,246,0.15); }

/* ===== Cards ===== */
.card-tw {
  background-color: #1a1d23;
  border-radius: 0.875rem;
  border: 1px solid rgba(255,255,255,0.05);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.card-stat:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

/* ===== Tables ===== */
.table-tw { width: 100%; border-collapse: collapse; }
.table-tw th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 1rem 1.25rem;
  text-align: left;
  color: #6b7280;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.table-tw td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  vertical-align: middle;
}
.table-tw tbody tr { transition: background-color 0.15s; }
.table-tw tbody tr:hover { background-color: rgba(255,255,255,0.025); }
html:not(.dark) .table-tw th { border-bottom-color: rgba(0,0,0,0.06); color: #6b7280; }
html:not(.dark) .table-tw td { border-bottom-color: rgba(0,0,0,0.04); }
html:not(.dark) .table-tw tbody tr:hover { background-color: rgba(0,0,0,0.015); }

/* Compact table variant for results */
.table-compact th { padding: 0.5rem 0.6rem; font-size: 0.65rem; white-space: nowrap; }
.table-compact td { padding: 0.45rem 0.6rem; font-size: 0.8rem; }
.table-compact .cell-truncate {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 1280px) {
  .table-compact .cell-truncate { max-width: 200px; }
}
/* Hide low-priority columns on smaller screens */
@media (max-width: 1279px) {
  .col-hide-xl { display: none !important; }
}
@media (max-width: 1023px) {
  .col-hide-lg { display: none !important; }
}

/* Sortable */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--wine); }
th.sortable .sort-icon { font-size: 0.65rem; opacity: 0.35; margin-left: 3px; transition: opacity 0.15s; }
th.sortable:hover .sort-icon { opacity: 1; }
th.sortable[data-dir="asc"] .sort-icon,
th.sortable[data-dir="desc"] .sort-icon { opacity: 1; color: var(--wine); }

/* ===== Inputs ===== */
.input-tw {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border-radius: 0.625rem;
  border: 1px solid rgba(255,255,255,0.1);
  background-color: rgba(255,255,255,0.04);
  color: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.input-tw:focus {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px rgba(114,47,55,0.15);
  background-color: rgba(255,255,255,0.06);
}
.input-tw-sm { padding: 0.4rem 0.65rem; font-size: 0.8rem; }
.input-tw-lg { padding: 0.7rem 1.1rem; font-size: 1rem; }
html:not(.dark) .input-tw { border-color: rgba(0,0,0,0.12); background-color: #fff; }
html:not(.dark) .input-tw:focus { box-shadow: 0 0 0 3px rgba(114,47,55,0.08); background-color: #fff; }

.select-tw {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border-radius: 0.625rem;
  border: 1px solid rgba(255,255,255,0.1);
  background-color: rgba(255,255,255,0.04);
  color: inherit;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.select-tw:focus {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px rgba(114,47,55,0.15);
}
html:not(.dark) .select-tw { border-color: rgba(0,0,0,0.12); background-color: #fff; }
html:not(.dark) .select-tw:focus { box-shadow: 0 0 0 3px rgba(114,47,55,0.08); }

/* ===== Buttons ===== */
.btn-wine {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, var(--wine), var(--wine-dark));
  color: #fff;
  padding: 0.55rem 1.15rem;
  border-radius: 0.625rem;
  border: none;
  font-size: 0.875rem;
}
.btn-wine:hover {
  background: linear-gradient(135deg, var(--wine-light), var(--wine));
  box-shadow: 0 4px 15px rgba(114,47,55,0.3);
  color: #fff;
  transform: translateY(-1px);
}
.btn-wine:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.45rem 0.85rem;
  border-radius: 0.625rem;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-outline:hover { background-color: rgba(255,255,255,0.05); transform: translateY(-1px); }
html:not(.dark) .btn-outline { border-color: rgba(0,0,0,0.12); }
html:not(.dark) .btn-outline:hover { background-color: rgba(0,0,0,0.03); }

.btn-outline-success { color: #22c55e; border-color: rgba(34,197,94,0.25); }
.btn-outline-success:hover { background-color: rgba(34,197,94,0.06); }
.btn-outline-danger { color: #ef4444; border-color: rgba(239,68,68,0.25); }
.btn-outline-danger:hover { background-color: rgba(239,68,68,0.06); }
.btn-outline-primary { color: #3b82f6; border-color: rgba(59,130,246,0.25); }
.btn-outline-primary:hover { background-color: rgba(59,130,246,0.06); }
.btn-outline-warning { color: #eab308; border-color: rgba(234,179,8,0.25); }
.btn-outline-warning:hover { background-color: rgba(234,179,8,0.06); }
.btn-outline-info { color: #06b6d4; border-color: rgba(6,182,212,0.25); }
.btn-outline-info:hover { background-color: rgba(6,182,212,0.06); }

.btn-sm { padding: 0.3rem 0.55rem; font-size: 0.8rem; }

/* ===== Badges ===== */
.badge-tw {
  display: inline-flex;
  align-items: center;
  font-weight: 500;
  padding: 0.2rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}
.badge-success  { background: rgba(34,197,94,0.12); color: #22c55e; }
.badge-danger   { background: rgba(239,68,68,0.12); color: #ef4444; }
.badge-warning  { background: rgba(234,179,8,0.12); color: #eab308; }
.badge-primary  { background: rgba(59,130,246,0.12); color: #3b82f6; }
.badge-secondary { background: rgba(156,163,175,0.12); color: #9ca3af; }
.badge-wine     { background: var(--wine); color: #fff; }

/* ===== Responsive sidebar ===== */
@media (max-width: 1023px) {
  #sidebar {
    position: fixed;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #sidebar.show { transform: translateX(0); }
}

/* ===== Sidebar edge toggle (tab handle) ===== */
.sidebar-edge-btn {
  position: fixed;
  left: 260px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1051;
  width: 20px;
  height: 48px;
  border: none;
  border-radius: 0 8px 8px 0;
  background: linear-gradient(180deg, #f59e0b, #d97706);
  color: #fff;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 3px 0 12px rgba(0,0,0,0.2);
  transition: left 0.2s cubic-bezier(0.4, 0, 0.2, 1),
              width 0.15s ease,
              box-shadow 0.15s ease;
  padding: 0;
}
.sidebar-edge-btn:hover {
  width: 26px;
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  box-shadow: 3px 0 18px rgba(245,158,11,0.4);
}
.sidebar-edge-btn:active {
  width: 22px;
}
#sidebar.collapsed ~ .sidebar-edge-btn {
  left: 68px;
}
@media (max-width: 1023px) {
  .sidebar-edge-btn { display: none !important; }
}

/* ===== Collapsible sidebar (desktop) ===== */
#sidebar.collapsed {
  width: 68px !important;
  overflow-x: hidden;
}
#sidebar.collapsed .sidebar-label {
  display: none;
}
#sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 0.6rem;
}
#sidebar.collapsed .nav-link i {
  margin-right: 0;
}
#sidebar.collapsed #userDropdownBtn {
  justify-content: center;
}
#sidebar.collapsed #themeToggle {
  justify-content: center;
}
#sidebar.collapsed #themeToggle i {
  margin-right: 0;
}
#sidebar.collapsed > div:first-child {
  justify-content: center;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}
#sidebar.collapsed > div:first-child a {
  justify-content: center;
}
#sidebar.collapsed #userDropdownMenu {
  left: 68px;
  bottom: 0;
  width: 200px;
}

/* ===== Results viewport layout ===== */
.results-viewport {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 8rem);
  min-height: 400px;
}
.results-viewport .results-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.results-viewport .results-table-wrap .overflow-auto {
  height: 100%;
}
/* Sticky table header */
.table-compact thead {
  position: sticky;
  top: 0;
  z-index: 5;
  background-color: #1a1d23;
}
html:not(.dark) .table-compact thead {
  background-color: #fff;
}
@media (max-width: 1023px) {
  .results-viewport {
    height: calc(100vh - 10rem);
  }
}

/* ===== Contacts viewport layout ===== */
.contacts-viewport {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 8rem);
  min-height: 400px;
}
.contacts-viewport .contacts-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.contacts-viewport .contacts-table-wrap .overflow-auto {
  height: 100%;
}
@media (max-width: 1023px) {
  .contacts-viewport {
    height: calc(100vh - 10rem);
  }
}

/* ===== Task tracker (frosted glass) ===== */
.task-tracker {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 360px;
  z-index: 1060;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  background: rgba(26, 29, 35, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.06);
}
.task-tracker-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  border-bottom: 1px solid rgba(128,128,128,0.08);
  user-select: none;
  transition: opacity 0.15s;
}
.task-tracker-header:hover { opacity: 0.85; }
.task-tracker-body { padding: 10px 14px; max-height: 400px; overflow-y: auto; }
.task-item {
  padding: 12px;
  border-radius: 0.625rem;
  margin-bottom: 8px;
  background-color: rgba(255,255,255,0.025);
  transition: background-color 0.15s;
}
.task-item:hover { background-color: rgba(255,255,255,0.04); }
.task-item:last-child { margin-bottom: 0; }

/* ===== Kanban ===== */
.kanban-column { border-radius: 0.875rem; overflow: hidden; min-height: 400px; background-color: #15181e; }
.kanban-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 0.875rem;
}
.kanban-body { padding: 12px; min-height: 300px; transition: background-color 0.15s; }
.kanban-body.drag-over { background-color: rgba(114,47,55,0.06); }
.kanban-card {
  padding: 16px;
  border-radius: 0.75rem;
  margin-bottom: 8px;
  cursor: grab;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: #1a1d23;
  border: 1px solid rgba(255,255,255,0.05);
}
.kanban-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.2); }
.kanban-card.dragging { opacity: 0.5; transform: rotate(2deg); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128,128,128,.4); }

/* ===== Pagination ===== */
.page-btn {
  padding: 0.35rem 0.7rem;
  border-radius: 0.5rem;
  font-size: 0.82rem;
  border: 1px solid rgba(255,255,255,0.06);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.page-btn:hover { background-color: rgba(255,255,255,0.05); transform: translateY(-1px); }
.page-btn.active {
  background: linear-gradient(135deg, var(--wine), var(--wine-dark));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(114,47,55,0.25);
}
.page-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

/* ===== Checkbox / Radio ===== */
input[type="checkbox"]:checked, input[type="radio"]:checked {
  accent-color: var(--wine);
}

/* ===== Select options ===== */
.dark select option { background-color: #1a1d23; color: #e5e7eb; }
html:not(.dark) select option { background-color: #fff; color: #1a1a2e; }

/* ===== Tooltips ===== */
.has-tooltip {
  position: relative;
}
.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  padding: 4px 8px;
  border-radius: 6px;
  background: #1a1d23;
  color: #e5e7eb;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 50;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.has-tooltip:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ===== Notification bell dropdown ===== */
#notifDropdown {
  animation: notif-slide-in 0.15s ease-out;
}
@keyframes notif-slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
html:not(.dark) #notifDropdown {
  background-color: #fff;
  border-color: rgba(0,0,0,0.08);
}
html:not(.dark) .notif-item:hover {
  background-color: rgba(0,0,0,0.02) !important;
}
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
@media (max-width: 640px) {
  #notifDropdown {
    position: fixed !important;
    left: 1rem !important;
    right: 1rem !important;
    top: 60px !important;
    width: auto !important;
  }
}

/* ===== Page transitions ===== */
.page-fade-in {
  animation: page-fade 0.3s ease-out;
}
@keyframes page-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
