:root {
  --primary-color: #C22C2B;
  /* ANZ Red */
  --primary-hover: #a52423;
  --primary-light: #fef2f2;
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --danger-color: #ef4444;
  --danger-hover: #dc2626;
  --success-color: #0ea5e9;
  /* Light blue/cyan */
  --success-hover: #0284c7;
  
  --info-color: #3498db;
  --warning-color: #f59e0b;
  --success-green: #10b981;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  font-size: 16px;
  transition: background-color 0.3s ease;
}

.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 3rem 2rem;
  width: 100%;
}

header {
  padding: 1.25rem 3rem;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  margin: 0;
  letter-spacing: -0.025em;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: 2rem;
  font-weight: 500;
  transition: var(--transition);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

.nav-links a:hover {
  color: var(--primary-color);
  background: var(--primary-light);
}

.nav-links a.active {
  color: var(--primary-color);
  background: var(--primary-light);
  font-weight: 600;
}

.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2.5rem;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h2 {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="datetime-local"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(194, 44, 43, 0.2);
  background: var(--surface-color);
}

input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary-color);
  cursor: pointer;
  transition: var(--transition);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.checkbox-group label {
  margin-bottom: 0;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.mobile-filter-btn {
  display: none;
}

.filter-close-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-primary);
  cursor: pointer;
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.875rem 1.75rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  font-family: inherit;
  font-size: 1rem;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(194, 44, 43, 0.2);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px -2px rgba(194, 44, 43, 0.3);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
  transform: translateY(-2px);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: var(--success-hover);
  transform: translateY(-2px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--bg-color);
  border-color: #cbd5e1;
}

.btn-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
  flex-shrink: 0;
}
.btn-circle svg {
  width: 20px;
  height: 20px;
}

.hero-btn {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  min-width: 160px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.hero-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px -2px rgba(194, 44, 43, 0.3);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.table-responsive table {
  margin-top: 0;
  border: none;
  border-radius: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  border: 1px solid var(--border-color);
}

th,
td {
  padding: 0.75rem 1rem;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--border-color);
  min-width: 120px;
  max-width: 350px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

th {
  font-weight: 600;
  color: #ffffff;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--primary-color);
}

th[data-type="number"],
td[data-type="number"],
th[data-type="autoNumber"],
td[data-type="autoNumber"],
th[data-type="checkbox"],
td[data-type="checkbox"],
th[data-type="actions"],
td[data-type="actions"] {
  min-width: auto;
  width: 1%;
  white-space: nowrap;
}

tbody tr:nth-child(odd) {
  background-color: var(--bg-color);
}

tbody tr:nth-child(even) {
  background-color: var(--surface-color);
}

tr:hover td {
  background-color: var(--primary-light);
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.columns-builder {
  border: 1px dashed var(--border-color);
  padding: 2rem;
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
  background: #fafafa;
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}

/* Home hero */
.hero {
  text-align: center;
  margin-top: 6rem;
  margin-bottom: 6rem;
}

.hero h2 {
  font-size: 3.5rem;
  margin-bottom: 1.5rem;
  color: var(--primary-color);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero p {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 3rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.8;
}

.hero-buttons {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

.hero-btn {
  padding: 1rem 2.5rem;
  font-size: 1.125rem;
  border-radius: 12px;
  text-decoration: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(20px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2.5rem;
}

/* Two-column Layout for Admin */
.layout-container {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

.layout-container>* {
  min-width: 0;
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  /* (5 items * ~60px) + (4 gaps * 12px) = ~345px */
  max-height: 345px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.sidebar-list::-webkit-scrollbar {
  width: 6px;
}

.sidebar-list::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.sidebar-item {
  padding: 1rem 1.25rem;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-dl-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--success-color);
  padding: 0.25rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.sidebar-dl-btn:hover {
  color: var(--success-hover);
  background: var(--bg-color);
  transform: translateY(-2px);
}

.sidebar-dl-btn svg {
  fill: currentColor;
}

.sidebar-item:hover {
  border-color: var(--primary-hover);
  background: var(--surface-color);
  box-shadow: var(--shadow-sm);
  transform: translateX(4px);
}

.sidebar-item.active {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
  font-weight: 600;
}

.sidebar-add-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.75rem;
  background: var(--primary-color) !important;
  color: white !important;
  border: 1px dashed var(--primary-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 500;
  transition: var(--transition);
  margin-top: 1rem;
}

.sidebar-add-btn:hover {
  background: #a00d25 !important;
  color: white !important;
  border-color: #a00d25;
}

#adminSortTableSelect,
#sortTableSelect,
#custom_adminSortTableSelect .multiselect-btn,
#custom_sortTableSelect .multiselect-btn {
  background-color: var(--primary-color) !important;
  color: white !important;
  border-color: var(--primary-color) !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 1rem center !important;
  background-size: 16px 12px !important;
  padding-right: 2.5rem !important;
}

.dark-mode #custom_adminSortTableSelect .multiselect-btn,
.dark-mode #custom_sortTableSelect .multiselect-btn {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E") !important;
}

#adminSortTableSelect option,
#sortTableSelect option {
  background-color: var(--bg-color) !important;
  color: var(--text-primary) !important;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.columns-wrapper {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 28vh;
  /* Reduced responsive scroll max height */
  margin-bottom: 2rem;
  background: var(--surface-color);
  box-shadow: var(--shadow-sm);
}

.wireframe-column-row {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s;
}

.wireframe-column-row .row-top {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto;
  align-items: stretch;
}

border-bottom: 1px solid var(--border-color);
transition: background-color 0.2s;
}

.wireframe-column-row.dragging .row-top {
  opacity: 0.5;
  background-color: var(--bg-color);
}

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  color: var(--text-secondary);
  cursor: grab;
  border-right: 1px solid var(--border-color);
  font-size: 1.2rem;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.wireframe-column-row .row-top:hover {
  background: var(--bg-color);
}

.wireframe-column-row:last-child {
  border-bottom: none;
}

.wireframe-column-row .row-top input[type="text"],
.wireframe-column-row .row-top select {
  border: none;
  border-radius: 0;
  padding: 1.25rem 1.5rem;
  background: transparent;
  color: var(--text-primary);
  width: 100%;
  font-size: 1rem;
}

.wireframe-column-row .row-top input[type="text"]:focus,
.wireframe-column-row .row-top select:focus {
  background: var(--surface-color);
  box-shadow: inset 0 0 0 2px var(--primary-color);
}

.wireframe-column-row .row-top input[type="text"] {
  border-right: 1px solid var(--border-color);
  font-weight: 500;
}

.wireframe-column-row .row-top select {
  border-right: 1px solid var(--border-color);
  cursor: pointer;
  color: var(--text-secondary);
}

.delete-col-icon {
  background: transparent;
  border: none;
  border-left: 1px solid var(--border-color);
  color: var(--danger-color);
  cursor: pointer;
  padding: 0 1.5rem;
  font-size: 1.25rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.delete-col-icon:hover {
  color: var(--danger-hover);
  background: #fee2e2;
}

/* =========================================
   Mobile Responsiveness
   ========================================= */

@media (max-width: 992px) {
  body {
    font-size: 14px;
    overflow-x: hidden;
    /* Prevent horizontal scrolling on mobile */
  }

  .container {
    padding: 1rem 0.5rem;
    /* Even smaller padding on mobile to save space */
    width: 100%;
    overflow-x: hidden;
  }

  .workspace-layout {
    gap: 1rem;
    overflow-x: hidden;
  }

  header {
    flex-direction: row !important;
    padding: 0.75rem 1rem !important;
    gap: 0.5rem !important;
    text-align: left;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  header h1 {
    flex-shrink: 0;
    margin-right: 1rem;
    flex: 1;
  }
  
  header h1 img {
    height: 32px !important;
  }
  
  header h1 span {
    font-size: 1rem !important;
  }
  
  .mobile-menu-btn {
    display: block !important;
    z-index: 60 !important;
  }

  .nav-links {
    position: fixed !important;
    top: 0 !important;
    right: -100vw !important;
    width: 100vw !important;
    height: 100vh !important;
    background: var(--surface-color) !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    padding: 80px 20px 20px 20px !important;
    margin: 0 !important;
    gap: 1.25rem !important;
    box-shadow: none !important;
    transition: right 0.3s ease-in-out !important;
    z-index: 40 !important;
    border-top: none !important;
    display: flex !important;
  }
  
  .nav-links.active {
    right: 0 !important;
  }
  
  .nav-links a {
    margin-left: 0 !important;
    padding: 0.85rem 1rem !important;
    font-size: 1.1rem !important;
    border-radius: 8px !important;
    background: var(--bg-color) !important;
    text-align: center !important;
    border: 1px solid var(--border-color) !important;
    font-weight: 600 !important;
  }
  
  #themeToggleBtn {
    margin: 0 !important;
    width: 100% !important;
    padding: 0.85rem !important;
    background: var(--bg-color) !important;
    border-radius: 8px !important;
    border: 1px solid var(--border-color) !important;
  }
  
  #themeToggleBtn:hover, .theme-toggle:hover {
    transform: none !important;
  }
  
  #logoutBtn {
    padding: 0.85rem 1rem !important;
    font-size: 1.1rem !important;
    justify-content: center !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    background: var(--bg-color) !important;
    font-weight: 600 !important;
  }

  #tableSelectionView .card {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 1.25rem !important;
  }

  .table-list-item {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.5rem !important;
    padding-right: 3.5rem !important;
  }

  .table-list-item-right {
    text-align: left !important;
    padding-right: 0 !important;
  }

  .nav-links a {
    margin: 0 0.5rem;
    font-size: 0.9rem;
    padding: 0.5rem;
  }

  .btn,
  .form-control,
  select,
  input {
    min-height: 44px;
    /* Touch target standard */
  }

  .card {
    padding: 1.25rem;
    margin-bottom: 1.5rem;
  }

  .modal-content {
    padding: 1.25rem;
    width: 98%;
    margin: 0.5rem;
  }

  .admin-workspace-actions button {
    flex: 1;
    justify-content: center;
  }

  .admin-workspace-actions button.btn-circle,
  .btn-circle {
    flex: 0 0 46px !important;
    width: 46px !important;
    height: 46px !important;
  }
  .btn-circle svg {
    width: 22px !important;
    height: 22px !important;
  }

  .operator-controls {
    flex-direction: column !important;
  }

  .operator-controls>* {
    width: 100% !important;
  }

  .editor-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1.5rem;
  }

  .editor-header>div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }

  .editor-header>div>button {
    flex: 1;
    min-width: 120px;
  }

  .editor-header input {
    width: 100%;
    margin-right: 0;
    text-align: center;
  }

  .wireframe-column-row .row-top {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  .wireframe-column-row .row-top .drag-handle {
    order: 1 !important;
    flex: 0 0 auto !important;
    height: 48px !important;
    display: flex !important;
    align-items: center !important;
  }

  .wireframe-column-row .row-top input[type="text"] {
    order: 2 !important;
    flex: 1 1 0 !important;
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: none !important;
    height: 48px !important;
    padding: 0.5rem 1rem !important;
  }

  .wireframe-column-row .row-top select {
    order: 4 !important;
    flex: 1 0 100% !important;
    border-top: 1px solid var(--border-color) !important;
    border-right: none !important;
    border-bottom: none !important;
    border-left: none !important;
    height: 48px !important;
    padding: 0.5rem 1rem !important;
  }

  .wireframe-column-row .row-top .delete-col-icon {
    order: 3 !important;
    flex: 0 0 auto !important;
    border-left: 1px solid var(--border-color) !important;
    height: 48px !important;
  }

  .admin-sidebar-controls,
  .user-controls-row,
  .log-controls-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }

  .admin-sidebar-controls > *,
  .user-controls-row > *,
  .log-controls-row > * {
    width: 100% !important;
  }

  .user-controls-row .custom-multiselect,
  .user-controls-row #roleFilterDropdownBtn {
    width: 100% !important;
  }

  .user-controls-row #createNewUserBtn {
    margin-left: 0 !important;
  }

  .hero h2 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1.125rem;
  }

  .hero-buttons {
    flex-direction: column;
    padding: 0 1rem;
  }

  .hero-btn {
    width: 100%;
  }

  .btn {
    padding: 0.8rem 1rem;
  }

  .card {
    padding: 1.5rem;
  }
}

@media (max-width: 576px) {
  .add-option-row {
    flex-wrap: wrap !important;
  }
  .add-option-row input[type="text"] {
    flex: 1 1 100% !important;
  }
}

@media (max-width: 480px) {
  header h1 a {
    flex-direction: row !important;
    gap: 0.25rem !important;
    align-items: center !important;
  }
  header h1 img {
    height: 20px !important;
  }
  header h1 span {
    font-size: 0.85rem !important;
  }
  .pill-switch button {
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
  }
}

/* Table Responsive Wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* =========================================
   Dark Mode Styles
   ========================================= */
.dark-mode body,
body.dark-mode {
  --bg-color: #171717;
  --surface-color: #262626;
  --border-color: #404040;
  --text-primary: #f5f5f5;
  --text-secondary: #a3a3a3;
  --primary-light: rgba(194, 44, 43, 0.15);
}

.dark-mode body input[type="text"],
.dark-mode body input[type="password"],
.dark-mode body input[type="number"],
.dark-mode body select,
body.dark-mode input[type="text"],
body.dark-mode input[type="password"],
body.dark-mode input[type="number"],
body.dark-mode select {
  background: var(--bg-color);
  color: var(--text-primary);
}

.dark-mode body input[type="text"]:focus,
.dark-mode body input[type="password"]:focus,
.dark-mode body input[type="number"]:focus,
.dark-mode body select:focus,
body.dark-mode input[type="text"]:focus,
body.dark-mode input[type="password"]:focus,
body.dark-mode input[type="number"]:focus,
body.dark-mode select:focus {
  background: var(--surface-color);
}

.dark-mode body .sidebar-item,
body.dark-mode .sidebar-item {
  background: var(--bg-color);
  color: var(--text-primary);
}

.dark-mode body .sidebar-item:hover,
body.dark-mode .sidebar-item:hover {
  background: var(--surface-color);
}

.dark-mode body .sidebar-add-btn,
body.dark-mode .sidebar-add-btn {
  background: transparent;
  color: var(--text-secondary);
}

body.dark-mode .sidebar-add-btn:hover {
  background: var(--surface-color);
  color: var(--primary-color);
}

body.dark-mode th {
  background: var(--bg-color);
  color: var(--text-secondary);
}

body.dark-mode tr:hover td {
  background: var(--bg-color);
}

body.dark-mode .wireframe-column-row:hover {
  background: var(--bg-color);
}

body.dark-mode .columns-wrapper {
  background: var(--surface-color);
}

body.dark-mode .btn-outline {
  color: var(--text-primary);
  border-color: var(--border-color);
}

body.dark-mode .btn-outline:hover {
  background: var(--bg-color);
  border-color: var(--text-secondary);
}

body.dark-mode .delete-col-icon:hover {
  background: rgba(239, 68, 68, 0.15);
}

.theme-toggle {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  margin-left: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 50%;
}

.theme-toggle:hover {
  color: var(--primary-color);
  background: var(--primary-light);
  transform: rotate(15deg);
}

.sidebar-dl-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  opacity: 0.6;
  transition: var(--transition);
  padding: 0.25rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-dl-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

body.dark-mode .sidebar-dl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Operator Panel Table Cards */
.table-cards-container {
  display: flex;
  gap: 1.5rem;
  overflow-x: auto;
  padding: 1rem 0.5rem;
  margin: 0 -0.5rem;
  /* allow shadow to breathe */
}

.table-cards-container::-webkit-scrollbar {
  height: 8px;
}

.table-cards-container::-webkit-scrollbar-track {
  background: transparent;
}

.table-cards-container::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

.table-card {
  flex: 0 0 auto;
  width: 220px;
  height: 220px;
  background: var(--bg-color);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1.15rem;
  word-break: break-word;
}

.table-card:hover {
  border-color: var(--primary-color);
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
}

.table-card.active {
  border-color: var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(194, 44, 43, 0.1);
}

.table-vertical-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.table-vertical-list::-webkit-scrollbar {
  width: 6px;
}

.table-vertical-list::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: 4px;
}

.table-vertical-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.table-vertical-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.table-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.table-list-item:hover {
  border-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  background: var(--bg-color);
}

.table-list-item.active {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

.table-list-item-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.table-list-item-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* =========================================
   Dropdown (Select) Option Editor Styles
   ========================================= */
.options-editor-container {
  margin: 0;
  padding: 1.5rem;
  background-color: var(--bg-color);
  border-top: 1px solid var(--border-color);
  border-radius: 0;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.options-toggle-strip {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 24px;
  background-color: var(--surface-color);
  cursor: pointer;
  transition: background-color 0.2s;
  border-top: 1px solid var(--border-color);
}

.options-toggle-strip:hover {
  background-color: var(--bg-color);
}

.options-toggle-strip .chevron-icon {
  transition: transform 0.3s ease;
  color: var(--text-secondary);
}

.add-option-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  align-items: center;
}

.add-option-row input[type="text"] {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--input-bg);
  color: var(--text-primary);
}

.add-option-row input[type="text"]:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
  outline: none;
}

.add-option-row input[type="color"] {
  width: 45px;
  height: 41px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}

.add-option-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.add-option-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.options-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.option-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;
}

.option-item:hover {
  transform: translateY(-1px);
}

.option-item .remove-opt-btn {
  background: rgba(255, 255, 255, 0.25);
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.75rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
  line-height: 1;
}

.option-item .remove-opt-btn:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Badge for Data Tables */
.badge {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Dynamic Select Custom Styles */
select.dynamic-select {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

select.dynamic-select[style*="background-color"] {
  border-color: transparent !important;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

select.dynamic-select option {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-weight: normal;
}

/* =========================================
   Operator Board & Table Custom Scroll / Borders
   ========================================= */
.table-bordered th,
.table-bordered td {
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.table-bordered th:last-child,
.table-bordered td:last-child {
  border-right: none;
}

.table-scroll-container {
  max-height: calc(100vh - 350px);
  min-height: 400px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  background: var(--surface-color);
  position: relative;
}

.table-scroll-container table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: none;
  border-radius: 0;
}

.table-scroll-container th,
.table-scroll-container td {
  white-space: nowrap;
}

.table-scroll-container th {
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 var(--border-color);
}

/* Filter Bar styles */
.filter-card {
  padding: 1.5rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.filter-input-wrapper input {
  width: 90px;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-color);
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* Custom Dropdown Multi-Select for Dropbox options */
.custom-multiselect {
  position: relative;
  width: 200px;
  user-select: none;
}

.multiselect-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-color);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 2rem;
}

.multiselect-btn::after {
  content: "";
  border: solid var(--text-secondary);
  border-width: 0 2px 2px 0;
  display: inline-block;
  padding: 3px;
  transform: rotate(45deg);
  position: absolute;
  right: 1rem;
  top: 40%;
  transition: transform 0.2s;
}

.custom-multiselect.active .multiselect-btn::after {
  transform: rotate(-135deg);
  top: 45%;
}

.multiselect-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 99999 !important;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.5rem;
  margin-top: 0.25rem;
}

.custom-multiselect.active .multiselect-content {
  display: block;
}

.multiselect-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: background 0.15s;
}

.multiselect-item:hover {
  background: var(--bg-color);
}

.multiselect-item input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary-color);
}

.dark-mode .multiselect-content,
body.dark-mode .multiselect-content {
  background: var(--surface-color);
}

/* Sidebar filter min-max inputs row alignment */
.filters-vertical-stack .filter-input-wrapper {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  width: 100% !important;
}

.filters-vertical-stack .filter-input-wrapper input[type="number"] {
  width: 45% !important;
  min-width: 0 !important;
  flex: 1 !important;
  padding: 0.5rem 0.75rem !important;
  font-size: 0.85rem !important;
}

/* Fixed height scrollable table wrapper */
.fixed-height-table {
  height: calc(100vh - 350px) !important;
  min-height: 400px !important;
  max-height: calc(100vh - 350px) !important;
  overflow-y: auto !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

/* Operator Panel Layout (Sidebar + Workspace side-by-side) */
.workspace-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
  width: 100%;
}

@media (max-width: 992px) {

  .workspace-layout,
  .layout-container {
    grid-template-columns: 1fr;
  }
}

/* Sidebar elements layout vertical margins and gaps */
.filter-group-vertical {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.filter-group-vertical label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.filters-vertical-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.filters-vertical-stack .filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filters-vertical-stack .filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* Fix duplicate margins/borders inside table scroll container */
.table-scroll-container .table-responsive {
  margin-top: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* Global Professional Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}


/* Modern Unified Input Styles */
input.form-control, textarea.form-control {
  border-radius: 24px !important;
  padding: 0.65rem 1.25rem !important;
  border: 1px solid var(--border-color) !important;
  background-color: var(--surface-color) !important;
  color: var(--text-primary) !important;
  transition: all 0.25s ease !important;
}

input.form-control:focus, textarea.form-control:focus {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 0 3px rgba(160, 13, 37, 0.1) !important;
  outline: none;
}

/* Modern Unified Dropdown Styles */
select.form-control,
.multiselect-btn,
#roleFilterDropdownBtn {
  border-radius: 24px !important;
  padding: 0.65rem 1.25rem !important;
  padding-right: 2.5rem !important;
  border: 1px solid var(--border-color) !important;
  background-color: var(--surface-color) !important;
  color: var(--text-primary) !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 1rem center !important;
  background-size: 14px !important;
  transition: all 0.25s ease !important;
  cursor: pointer;
}

select.form-control:focus,
.multiselect-btn:focus,
#roleFilterDropdownBtn:focus {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 0 3px rgba(160, 13, 37, 0.1) !important;
  outline: none;
}

.dark-mode select.form-control,
.dark-mode .multiselect-btn,
.dark-mode #roleFilterDropdownBtn {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3E%3C/svg%3E") !important;
}

#roleFilterDropdownBtn svg {
  display: none !important;
}

.multiselect-btn::after {
  display: none !important;
}

#roleFilterDropdownMenu,
.multiselect-content {
  border-radius: 16px !important;
  padding: 0.75rem !important;
}

/* Custom Modern Checkboxes */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface-color);
  margin: 0;
  font: inherit;
  color: currentColor;
  width: 1.25em;
  height: 1.25em;
  border: 2px solid var(--text-secondary);
  border-radius: 0.25em;
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type="checkbox"]::before {
  content: "";
  width: 0.75em;
  height: 0.75em;
  transform: scale(0);
  transition: 120ms transform ease-in-out;
  box-shadow: inset 1em 1em var(--primary-color);
  background-color: var(--primary-color);
  transform-origin: center;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

input[type="checkbox"]:checked::before {
  transform: scale(1);
}

input[type="checkbox"]:checked {
  border-color: var(--primary-color);
}
/* Starred Tables Container */
.starred-tables-container {
  border: 4px solid var(--primary-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1rem 1rem 1rem;
  position: relative;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.starred-tab {
  position: absolute;
  top: -4px;
  left: -4px;
  background-color: var(--primary-color);
  color: white;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom-right-radius: var(--radius-lg);
  border-top-left-radius: var(--radius-lg);
  z-index: 10;
}

.btn-star {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.btn-star:hover {
  background-color: rgba(0,0,0,0.05);
}

.btn-star.active {
  color: #f59e0b;
}



/* ==========================================================================
   Mobile Responsiveness & UI/UX Improvements
   ========================================================================== */

@media (max-width: 768px) {
  /* Card padding reduction */
  .card {
    padding: 1rem !important;
    border-radius: var(--radius-md) !important;
  }

  /* Modal padding reduction */
  .modal-content {
    padding: 1.25rem !important;
    width: 95% !important;
    max-height: 85vh !important;
  }

  /* Buttons touch targets */
  .btn, button.btn {
    min-height: 44px !important;
    padding: 0.5rem 1rem !important;
  }
  
  /* Inputs touch targets */
  input.form-control, select.form-control, textarea.form-control {
    min-height: 44px !important;
  }

  /* Make workspace layouts full width on mobile */
  .workspace-layout,
  .layout-container {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  
  .mobile-filter-btn {
    display: flex !important;
    width: auto !important;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0 !important;
    padding: 0.4rem 0.75rem !important;
    font-size: 0.85rem !important;
    font-weight: 600;
    min-height: unset !important;
    border-radius: var(--radius-md) !important;
  }

  .filter-sidebar {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 2000 !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
    padding: 1.5rem !important;
    background: var(--surface-color) !important;
  }

  .filter-sidebar.active {
    display: block !important;
  }
  
  .filter-close-btn {
    display: block !important;
  }

  /* Fix data tables for smaller screens */
  .admin-workspace-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 1rem !important;
  }
  
  .admin-workspace-actions {
    width: 100% !important;
    justify-content: flex-start !important;
    gap: 0.5rem !important;
    flex-wrap: wrap !important;
  }
  
  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
  }
}
