:root {
  --navy-900: #0a192f;
  --navy-800: #0f2238;
  --navy-700: #162f4d;
  --navy-600: #1e3d63;
  --teal-500: #22c8a2;
  --teal-400: #38e2bc;
  --teal-600: #1aa685;
  --teal-glow: rgba(34, 200, 162, 0.15);
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-light: #e2e8f0;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Sidebar */
.sidebar {
  width: 270px;
  background-color: var(--navy-800);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background-color: var(--navy-900);
}

.brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-title .teal-text {
  color: var(--teal-500);
}

.brand-subtitle {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: #94a3b8;
  font-weight: 600;
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 0.08em;
  padding: 12px 10px 4px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-item.active {
  background-color: var(--teal-glow);
  color: var(--teal-400);
  border-left: 3px solid var(--teal-500);
  font-weight: 600;
}

.nav-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background-color: rgba(34, 200, 162, 0.2);
  color: var(--teal-400);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 9999px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background-color: var(--navy-900);
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal-500), var(--navy-600));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.72rem;
  color: #94a3b8;
}

.sidebar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: #cbd5e1;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-logout:hover,
.sidebar-logout:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-logout .icon {
  width: 18px;
  height: 18px;
}

/* Main Layout */
.main-wrapper {
  margin-left: 270px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 64px;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-search {
  position: relative;
  width: 380px;
}

.topbar-search input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  background-color: var(--bg-page);
  outline: none;
  transition: border-color 0.2s;
}

.topbar-search input:focus {
  border-color: var(--teal-500);
  background-color: #fff;
  box-shadow: 0 0 0 3px var(--teal-glow);
}

.topbar-search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  width: 16px;
  height: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.content-area {
  padding: 28px;
  flex: 1;
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 14px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy-800);
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-teal {
  background-color: var(--teal-500);
  color: #ffffff;
}

.btn-teal:hover {
  background-color: var(--teal-600);
  box-shadow: 0 4px 10px rgba(34, 200, 162, 0.35);
}

.btn-navy {
  background-color: var(--navy-800);
  color: #ffffff;
}

.btn-navy:hover {
  background-color: var(--navy-700);
}

.btn-outline {
  background-color: #ffffff;
  border-color: var(--border-light);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: 4px;
}

/* Cards & Stats */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: #ffffff;
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--navy-800);
}

.stat-card.accent-teal::after {
  background: var(--teal-500);
}

.stat-card.accent-amber::after {
  background: #f59e0b;
}

.stat-card.accent-indigo::after {
  background: #6366f1;
}

.stat-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--navy-800);
  margin-top: 4px;
}

.stat-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background-color: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--navy-800);
}

.stat-icon.teal {
  background-color: var(--teal-glow);
  color: var(--teal-600);
}

/* Card Container */
.card {
  background: #ffffff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy-800);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 22px;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.86rem;
}

.table th {
  background-color: #f8fafc;
  color: #475569;
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

.table th[data-sortable],
.table th[data-sort-key] {
  cursor: pointer;
  user-select: none;
}

.table th[data-sortable]:hover,
.table th[data-sort-key]:hover {
  color: var(--navy-800);
}

.table th[data-sort-direction="asc"]::after {
  content: " ▲";
  color: var(--teal-600);
}

.table th[data-sort-direction="desc"]::after {
  content: " ▼";
  color: var(--teal-600);
}

.company-name-link {
  color: var(--navy-800);
  font-weight: 700;
  text-decoration: none;
}

.company-name-link:hover {
  color: var(--teal-600);
  text-decoration: underline;
}

.company-suggested-solution {
  max-width: 360px;
  margin-top: 3px;
  color: #64748b;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: normal;
}

.company-suggested-solution span {
  color: var(--teal-700);
  font-weight: 700;
}

.record-name-link {
  color: var(--navy-800);
  text-decoration: none;
}

.record-name-link:hover,
.record-name-link:focus-visible {
  color: var(--teal-600);
  text-decoration: underline;
}

.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:hover td {
  background-color: #fbfcfe;
}

.row-actions-cell,
.row-actions-heading {
  width: 58px;
  min-width: 58px;
  padding-left: 10px !important;
  padding-right: 10px !important;
  text-align: center;
}

.row-actions {
  position: relative;
  display: inline-flex;
}

.row-actions-trigger {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.row-actions-trigger:hover,
.row-actions-trigger[aria-expanded="true"] {
  color: var(--navy-800);
  background: #f1f5f9;
  border-color: var(--border-light);
}

.row-actions-trigger svg {
  width: 18px;
  height: 18px;
}

.row-actions-menu {
  position: fixed;
  z-index: 60;
  min-width: 140px;
  padding: 5px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  text-align: left;
}

.row-actions-menu[hidden] {
  display: none;
}

.row-actions-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  color: var(--text-primary);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
}

.row-actions-menu button:hover,
.row-actions-menu button:focus-visible {
  background: #f1f5f9;
  outline: none;
}

.row-actions-menu .row-actions-delete {
  color: #b91c1c;
}

.record-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.company-detail-content {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 16px;
}

.company-detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border-light);
}

.company-detail-tab {
  padding: 9px 13px;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.company-detail-tab[aria-selected="true"] {
  color: var(--navy-800);
  border-bottom-color: var(--teal-600, #0d9488);
}

.company-detail-tab:focus-visible {
  outline: 2px solid var(--teal-600, #0d9488);
  outline-offset: -2px;
}

.company-detail-panel {
  min-width: 0;
}

.record-detail-field {
  min-width: 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 8px;
}

.record-detail-field dt {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.record-detail-field dd {
  color: var(--text-primary);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.record-detail-wide {
  grid-column: 1 / -1;
}

.follow-up-scheduled {
  color: #92400e !important;
  font-weight: 700;
}

.follow-up-overdue {
  color: #991b1b !important;
  font-weight: 700;
}

.activity-manager-heading {
  margin: 8px 0 12px;
  color: var(--navy-800);
  font-size: 0.95rem;
}

.activity-manager-table {
  min-width: 720px;
  margin-bottom: 20px;
}

.activity-manager-table td {
  white-space: pre-wrap;
  vertical-align: top;
}

.activity-manager-status {
  min-width: 130px;
  padding: 6px 8px;
}

.activity-manager-empty {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.user-manager-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  gap: 14px;
}

.user-manager-form .form-group {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .record-details-grid {
    grid-template-columns: 1fr;
  }
}

.user-manager-submit {
  display: flex;
  align-items: end;
}

.user-manager-table {
  min-width: 1050px;
}

.user-manager-table .form-control {
  min-width: 120px;
}

.user-manager-status {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.user-manager-message,
.user-manager-errors {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 8px;
}

.user-manager-message {
  color: #065f46;
  background: #d1fae5;
}

.user-manager-errors {
  color: #991b1b;
  background: #fee2e2;
}

.form-group[hidden] {
  display: none;
}

.company-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.company-pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (max-width: 640px) {
  .company-pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-details-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: capitalize;
}

.badge-teal { background: #d1fae5; color: #065f46; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-tab:hover {
  border-color: #cbd5e1;
  color: var(--navy-800);
}

.filter-tab.active {
  background: var(--navy-800);
  color: #ffffff;
  border-color: var(--navy-800);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(2px);
  padding: 20px;
}

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

.modal-box {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 620px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-box {
  transform: translateY(0);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--navy-900);
  color: #fff;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-title .teal-text {
  color: var(--teal-400);
}

.modal-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-primary);
  background-color: #ffffff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

.form-row {
  display: flex;
  gap: 14px;
}

.form-row .form-group {
  flex: 1;
}

/* Progress bar */
.progress-bar-bg {
  height: 8px;
  background: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal-500), var(--teal-400));
  border-radius: 9999px;
  transition: width 0.3s;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--navy-900);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--teal-500);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
