/* STARTRACK DESIGN SYSTEM - styles.css */

:root {
  /* --- 1. Color Palette --- */
  /* Brand Colors */
  --primary: #4f46e5; /* Indigo 600 */
  --primary-hover: #4338ca; /* Indigo 700 */
  --primary-light: #eef2ff; /* Indigo 50 */

  /* Neutrals */
  --bg-app: #f3f4f6; /* Cool Gray 100 */
  --bg-surface: #ffffff; /* White */
  --border: #e5e7eb; /* Gray 200 */
  --text-main: #111827; /* Gray 900 */
  --text-muted: #6b7280; /* Gray 500 */

  /* Semantic / Status Colors (Crucial for StarTrack Health) */
  --status-green-bg: #d1fae5;
  --status-green-text: #065f46;
  --status-yellow-bg: #fef3c7;
  --status-yellow-text: #92400e;
  --status-red-bg: #fee2e2;
  --status-red-text: #991b1b;
  --status-blue-bg: #dbeafe;
  --status-blue-text: #1e40af;

  /* --- 2. Typography --- */
  --font-sans: system-ui, -apple-system, sans-serif;
  --font-xs: 0.75rem;
  --font-sm: 0.875rem;
  --font-base: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.5rem;
  --font-2xl: 1.875rem;

  /* --- 3. Spacing & Shape --- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --surface-subtle: #f9fafb;
  --sidebar-border: #374151;
}

/* --- Global Reset --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex; /* App Layout */
}

.app-shell {
  display: flex;
  width: 100%;
}

.main-with-sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- LAYOUT COMPONENTS --- */

/* Sidebar */
.app-sidebar {
  width: 200px;
  background-color: #1f2937; /* Dark sidebar for Admin feel */
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform 0.2s ease;
  z-index: 1200;
  font-size: var(--font-sm);
}
.app-sidebar .logo {
  font-weight: 700;
  font-size: var(--font-base);
  color: #fff;
  margin-bottom: 1.5rem;
  letter-spacing: -0.5px;
}
.app-sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: #9ca3af;
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin-bottom: 0.125rem;
  transition: all 0.2s;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-footer a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
}

.sidebar-toggle {
  background: #1f2937;
  color: #e5e7eb;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  display: none;
  z-index: 900;
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1100;
  display: none;
}


.topbar-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 900;
  display: none;
}

.mobile-topbar {
  display: none;
  padding: 0.75rem 1rem 0 1rem;
  align-items: center;
  gap: 0.75rem;
}

@media (max-width: 900px) {
  body {
    flex-direction: column;
  }
  .app-shell {
    flex-direction: column;
  }
  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1200;
    transform: translateX(-100%);
    display: flex;
  }
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-right: 0.5rem;
  }
  .sidebar-backdrop {
    display: none;
  }
  .sidebar-open .app-sidebar {
    transform: translateX(0);
  }
  .sidebar-open .sidebar-backdrop {
    display: block;
  }
  body.sidebar-open {
    overflow: hidden;
  }
  .app-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .breadcrumbs {
    margin-left: 0;
    padding-left: 0.5rem;
  }
}

.link-danger {
  color: inherit;
  font-weight: 600;
}
.link-danger:hover,
.link-danger:focus {
  color: inherit;
}
.btn-ghost.link-danger,
.btn-ghost.link-danger:hover,
.btn-ghost.link-danger:focus {
  color: inherit;
  background-color: transparent;
}
.app-sidebar nav a:hover,
.app-sidebar nav a.active {
  background-color: #374151;
  color: #fff;
}
.app-sidebar .nav-section {
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin: 1rem 0 0.375rem 0;
  font-weight: 600;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top Header */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
@media (max-width: 900px) {
  .app-header {
    justify-content: flex-start;
    padding: 1rem 1rem 1rem 1.5rem;
  }
}
.breadcrumbs {
  font-size: var(--font-sm);
  color: var(--text-muted);
}
.breadcrumbs span {
  color: var(--text-main);
  font-weight: 500;
}

/* Scrollable Content */
.content-area {
  padding: 2rem;
  overflow-y: auto;
  flex: 1;
}

/* --- ATOMIC COMPONENTS --- */

/* 1. Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: var(--font-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.2s;
  text-decoration: none;
  gap: 0.5rem;
}
.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}
.btn-secondary {
  background-color: white;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: var(--bg-app);
}
.btn-ghost {
  background-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text-main);
  background-color: rgba(0, 0, 0, 0.05);
}

/* 2. Badges (Status Indicators) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-green {
  background-color: var(--status-green-bg);
  color: var(--status-green-text);
}
.badge-yellow {
  background-color: var(--status-yellow-bg);
  color: var(--status-yellow-text);
}
.badge-red {
  background-color: var(--status-red-bg);
  color: var(--status-red-text);
}
.badge-blue {
  background-color: var(--status-blue-bg);
  color: var(--status-blue-text);
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  background-color: currentColor;
}

/* 3. Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.card-title {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-main);
}
.card-subtitle {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* 4. Avatars */
.avatar-group {
  display: flex;
  align-items: center;
  margin-left: -0.5rem;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid white;
  margin-left: -8px; /* overlap */
}
.avatar:first-child {
  margin-left: 0;
}

/* 5. Phase / Milestone / Task Hierarchy */
.phase-container {
  margin-bottom: 2rem;
}
.phase-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}
.phase-title {
  font-weight: 700;
  color: var(--text-main);
  font-size: var(--font-lg);
}

.milestone-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  overflow: hidden;
}
.milestone-header {
  background-color: #f9fafb;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.milestone-title {
  font-weight: 600;
  font-size: var(--font-sm);
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.task-list {
  padding: 0;
}
.task-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--font-sm);
}
.task-item:last-child {
  border-bottom: none;
}
.task-item:hover {
  background-color: #f9fafb;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* 6. Tabs */
.tabs {
  display: flex;
  gap: 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.tab {
  padding-bottom: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-size: var(--font-sm);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* 7. Grid Utilities */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.mt-4 {
  margin-top: 1rem;
}

/* --- APPEND TO styles.css --- */

/* 8. TYPOGRAPHY UTILITIES */
h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text-main);
  margin-bottom: 0.5rem;
  font-weight: 600;
}
h1 {
  font-size: var(--font-2xl);
}
h2 {
  font-size: var(--font-xl);
}
h3 {
  font-size: var(--font-lg);
}
p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.text-sm {
  font-size: var(--font-sm);
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.text-muted {
  color: var(--text-muted);
}

/* 9. FORMS */
.form-group {
  margin-bottom: 1.25rem;
}
.form-label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: var(--font-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input:disabled,
.form-select:disabled {
  background-color: var(--bg-app);
  cursor: not-allowed;
  color: var(--text-muted);
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.form-check input[type="hidden"] {
  display: none;
}
.form-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}
.form-check label {
  font-size: var(--font-sm);
  color: var(--text-main);
  cursor: pointer;
}

/* Auth layout */
.auth-layout {
  width: 100%;
  min-height: 100vh;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  background-color: var(--bg-app);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

/* Wider form card for management screens */
.form-card {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.abilities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem 1rem;
  align-items: flex-start;
}
.auth-header {
  margin-bottom: 1rem;
}
.auth-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.auth-links {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-size: var(--font-sm);
}

/* 10. TABLES */
.table-container {
  width: 100%;
  overflow-x: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--font-sm);
}
.table th {
  background-color: #f9fafb;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tr:hover td {
  background-color: #f9fafb;
}

.table-sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.table-sort-link:hover,
.table-sort-link:focus {
  color: var(--text-main);
  text-decoration: none;
}

.companies-index-toolbar {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.companies-index-search-form {
  flex: 1 1 30rem;
}

.companies-index-search-form,
.employees-index-search-form {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.companies-index-search-field,
.employees-index-search-field {
  flex: 1 1 18rem;
  width: auto;
  min-width: 12rem;
}

.companies-index-search-form .btn,
.companies-index-toolbar > .btn {
  min-height: 2.375rem;
  display: inline-flex;
  align-items: center;
}

.employees-index-search-card {
  margin-bottom: 1rem;
}

.companies-index-search-card {
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .companies-index-toolbar,
  .companies-index-search-form,
  .employees-index-search-form {
    width: 100%;
    justify-content: flex-start;
  }

  .companies-index-search-field,
  .employees-index-search-field {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
}

/* 11. ALERTS & CALLOUTS */
.alert {
  padding: 1rem;
  border-radius: var(--radius-md);
  border-left: 4px solid transparent;
  margin-bottom: 1rem;
  font-size: var(--font-sm);
  display: flex;
  gap: 0.75rem;
  flex-direction: column;
}
.alert ul {
  margin: 0.25rem 0 0 1rem;
  padding: 0;
  list-style: disc;
}
.alert ul li {
  margin: 0.15rem 0;
}
.alert-info {
  background-color: var(--status-blue-bg);
  color: var(--status-blue-text);
  border-left-color: var(--status-blue-text);
}
.alert-success {
  background-color: var(--status-green-bg);
  color: var(--status-green-text);
  border-left-color: var(--status-green-text);
}
.alert-warning {
  background-color: var(--status-yellow-bg);
  color: var(--status-yellow-text);
  border-left-color: var(--status-yellow-text);
}
.alert-danger {
  background-color: var(--status-red-bg);
  color: var(--status-red-text);
  border-left-color: var(--status-red-text);
}

.alert-dismissible {
  position: relative;
  padding-right: 2.5rem;
}

.alert-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 1.5rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: currentColor;
  cursor: pointer;
}

.alert-close:hover {
  background: rgba(0, 0, 0, 0.08);
}

.alert-close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

/* 12. MODALS (Simple implementation) */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  /* To hide: display: none; */
}
.modal {
  background: var(--bg-surface);
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease-out;
  max-height: calc(100vh - 2rem);
  height: min(90vh, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.modal.modal-schedule {
  max-width: 980px;
}
.modal form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
}
.modal-footer {
  padding: 1rem 1.5rem;
  background-color: #f9fafb;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

.schedule-modal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 1rem;
  align-items: start;
}

.schedule-modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.schedule-modal-form .form-group {
  margin-bottom: 0;
}

.schedule-modal-history {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.schedule-history-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 0.75rem;
}

.schedule-history-title {
  margin: 0 0 0.5rem;
  font-size: var(--font-sm);
}

.schedule-history-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.schedule-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 16rem;
  overflow: auto;
}

.schedule-history-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  padding: 0.5rem 0.625rem;
  font-size: var(--font-xs);
}

.schedule-history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.schedule-history-status {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
}

.schedule-history-item-details,
.schedule-history-item-time {
  margin-top: 0.2rem;
}

@media (max-width: 600px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 1rem;
  }

  .modal {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-md);
  }

  .modal.modal-schedule {
    max-width: 100%;
  }

  .schedule-modal-layout {
    grid-template-columns: 1fr;
  }

  .schedule-history-list {
    max-height: 12rem;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 1rem;
  }

  .map-container {
    height: 200px;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Button Variants Additions */
.btn-danger {
  background-color: #dc2626;
  color: white;
}
.btn-danger:hover {
  background-color: #b91c1c;
}
.btn-success {
  background-color: #16a34a;
  color: white;
}
.btn-success:hover {
  background-color: #15803d;
}
.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}
 .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
 }

/* 13. UTILITIES & APP-SPECIFIC HELPERS */
.stack > * + * {
  margin-top: var(--stack-space, 0.5rem);
}

.cluster {
  display: flex;
  align-items: center;
  gap: var(--cluster-gap, 0.75rem);
  flex-wrap: wrap;
}

.section-divider {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.eyebrow {
  font-size: var(--font-xs);
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 700;
}

.display-lg {
  font-size: var(--font-2xl);
}

.text-critical {
  color: var(--status-red-text);
}

.card-critical {
  border-left: 4px solid var(--status-red-text);
}

.btn-block {
  width: 100%;
}

.btn-xs {
  padding: 0.25rem 0.5rem;
  font-size: var(--font-xs);
}

.mt-lg {
  margin-top: 3rem;
}

.mb-sm {
  margin-bottom: 0.5rem;
}

.mb-md {
  margin-bottom: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  font-size: var(--font-xs);
  padding: 0.15rem 0.5rem;
  font-weight: 700;
  line-height: 1.2;
  min-width: 1.5rem;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--sidebar-border);
  color: #e5e7eb;
}

.sidebar-footer .eyebrow {
  color: #9ca3af;
}

.sidebar-footer .sidebar-identity {
  font-weight: 600;
  color: #fff;
}

.card-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.stat-value {
  font-weight: 600;
  font-size: 1.25rem;
}

.stat-subtext {
  font-size: var(--font-sm);
  font-weight: 400;
  color: var(--text-muted);
}

.section-heading {
  margin-top: 3rem;
  margin-bottom: 1rem;
}

.avatar-primary {
  background-color: var(--primary-light);
  color: var(--primary);
}

.avatar-warm {
  background-color: #fdba74;
  color: #9a3412;
}

.avatar-muted {
  background-color: #e5e7eb;
  color: #6b7280;
}

/* 14. FORM FIELDSETS */
.form-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  background-color: var(--bg-surface);
}

.form-fieldset legend {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-main);
  padding: 0 0.75rem;
  margin-left: -0.5rem;
  background-color: var(--bg-surface);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  align-items: end;
}

.form-row-3 {
  grid-template-columns: repeat(3, 1fr);
}

.form-row-4 {
  grid-template-columns: repeat(4, 1fr);
}

.form-row > .form-group {
  display: flex;
  flex-direction: column;
}

.form-row > .form-group > .form-label {
  margin-bottom: 0.375rem;
}

.form-row + .form-row {
  margin-top: 1rem;
}

.form-row + .form-group {
  margin-top: 1rem;
}

.form-fieldset .form-group {
  margin-bottom: 0;
}

.form-fieldset .form-group + .form-group {
  margin-top: 1rem;
}

.col-span-2 {
  grid-column: span 2;
}

@media (max-width: 640px) {
  .form-row,
  .form-row-3,
  .form-row-4 {
    grid-template-columns: 1fr;
  }
  .col-span-2 {
    grid-column: span 1;
  }
}

.form-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.375rem; /* Match form-input height */
}

.form-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: var(--font-sm);
  color: var(--text-main);
  height: 2.375rem; /* Match form-input height */
}

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

/* Screen reader only - visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 15. DETAIL VIEWS */
.detail-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.detail-section {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.detail-section:first-child {
  border-top: none;
  padding-top: 0;
}

.detail-section-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem 2rem;
}

.detail-item dt {
  font-size: var(--font-xs);
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.detail-item dd {
  font-size: var(--font-sm);
  color: var(--text-main);
}

.detail-item-wide {
  grid-column: span 2;
}

@media (max-width: 640px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .detail-item-wide {
    grid-column: span 1;
  }
}

.card-footer {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  margin-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Table row links */
.table td a.table-link {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
}

.table td a.table-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* 14. SITES MANAGEMENT */
.content-area:has(.sites-grid) {
  display: flex;
  flex-direction: column;
}

.sites-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.5rem;
  flex: 1;
  min-height: 0;
}

.sites-grid > .card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.selectable-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.selectable-list > turbo-frame {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.selectable-list > [data-controller="schedule-sortable"],
.selectable-list > turbo-frame > [data-controller="schedule-sortable"] {
  flex: 1;
}

.selectable-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s;
}

.selectable-item .item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.selectable-item .item-info .badge {
  margin-left: auto;
}

.selectable-item:last-child {
  border-bottom: none;
}

.selectable-item:hover {
  background-color: var(--surface-subtle);
}

.selectable-item.selected {
  background-color: var(--primary-light) !important;
  border-left: 3px solid var(--primary);
  font-weight: 500;
}

.selectable-item.inactive {
  opacity: 0.5;
}

.selectable-item.inactive .item-name {
  color: var(--text-muted);
}

.selectable-item:hover .remove-btn {
  opacity: 1;
}

.remove-btn {
  opacity: 0;
  transition: opacity 0.15s;
}

.empty-state {
  padding: 2rem;
  text-align: center;
}

.disabled-state {
  background: var(--surface-subtle);
  opacity: 0.6;
}

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

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

/* --- TOM SELECT OVERRIDES --- */
.ts-wrapper {
  border: none !important;
  padding: 0 !important;
}

.ts-wrapper.single .ts-control {
  padding: 0.625rem 0.75rem;
  font-size: var(--font-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  min-height: 2.625rem;
  line-height: 1.5;
}

/* Hide the original select when Tom Select is active */
select.tomselected {
  display: none !important;
}

.ts-wrapper.single .ts-control::after {
  border-color: var(--text-muted) transparent transparent transparent;
}

.ts-wrapper.single .ts-control .item {
  color: var(--text-main);
}

/* Hide empty items (when no real selection) */
.ts-wrapper.single .ts-control .item[data-value=""] {
  display: none;
}

/* Make input expand when no item is selected */
.ts-wrapper.single .ts-control > input {
  flex: 1;
  min-width: 100px;
}

/* Ensure placeholder is visible */
.ts-wrapper.single .ts-control > input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.ts-wrapper.single.focus .ts-control {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.ts-wrapper {
  position: relative;
}

.ts-dropdown {
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  border-top: none;
  box-shadow: var(--shadow-md);
  margin: 0 !important;
  z-index: 9999 !important;
  position: absolute !important;
  top: calc(100% - 1px) !important;
  left: 0 !important;
  right: 0 !important;
  width: auto !important;
}

.ts-wrapper.single.dropdown-active .ts-control {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom-color: transparent;
}

.ts-dropdown .ts-dropdown-content {
  max-height: 250px;
}

.ts-dropdown .optgroup-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem 0.4rem;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border);
}

.ts-dropdown .optgroup-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--status-blue-text);
  background: var(--status-blue-bg);
}

.ts-dropdown .optgroup-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.ts-dropdown .optgroup:first-child .optgroup-header {
  border-top: none;
}

.ts-dropdown .option {
  padding: 0.5rem 0.75rem;
  font-size: var(--font-sm);
}

.ts-option-entry {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.ts-option-point {
  color: var(--text-main);
  font-weight: 500;
}

.ts-option-site {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.ts-dropdown .option.active {
  background-color: var(--primary);
  color: white;
}

.ts-dropdown .option.active .ts-option-point,
.ts-dropdown .option.active .ts-option-site {
  color: white;
}

.ts-dropdown .option:hover {
  background-color: var(--primary-light);
  color: var(--text-main);
}

.ts-dropdown .option.active:hover {
  background-color: var(--primary);
  color: white;
}

.ts-wrapper .ts-control input {
  font-size: var(--font-sm);
}

.ts-wrapper .ts-control input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.ts-wrapper.single .ts-control .ts-input-placeholder {
  color: var(--text-muted);
}

.ts-selected-entry {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.ts-selected-point {
  color: var(--text-main);
}

.ts-selected-site {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* --- 16. DASHBOARD CARDS --- */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.dashboard-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}

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

.dashboard-card-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.dashboard-card-disabled:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
  transform: none;
}

.dashboard-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-md);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.dashboard-card-content {
  flex: 1;
  min-width: 0;
}

.dashboard-card-title {
  font-weight: 600;
  font-size: var(--font-base);
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.dashboard-card-count {
  font-size: var(--font-sm);
  color: var(--text-muted);
}

.dashboard-card-arrow {
  color: var(--text-muted);
  font-size: var(--font-sm);
  flex-shrink: 0;
}

.dashboard-card:hover .dashboard-card-arrow {
  color: var(--primary);
}

.dashboard-card-disabled:hover .dashboard-card-arrow {
  color: var(--text-muted);
}

/* --- 17. MAP PICKER --- */
.map-container {
  height: 250px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--bg-app);
}

.map-container .leaflet-container {
  height: 100%;
  width: 100%;
  font-family: var(--font-sans);
}

/* --- 18. SCHEDULE PAGE --- */
.schedule-toolbar .card-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.schedule-period-switch {
  display: inline-flex;
  gap: 0.5rem;
}

.schedule-month-day {
  padding: 1rem;
}

.schedule-month-day-header {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.schedule-month-day-title {
  margin: 0;
  font-size: var(--font-base);
}

.schedule-table-readonly th:nth-child(1) { width: 20%; }
.schedule-table-readonly th:nth-child(2) { width: 22%; }
.schedule-table-readonly th:nth-child(3) { width: 14%; }
.schedule-table-readonly th:nth-child(4) { width: 10%; }
.schedule-table-readonly th:nth-child(5) { width: 10%; }
.schedule-table-readonly th:nth-child(6) { width: auto; }

.schedule-toast-region {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1300;
  width: min(26rem, calc(100vw - 2rem));
  pointer-events: none;
}

.schedule-toast-region .alert {
  box-shadow: var(--shadow-md);
  margin-bottom: 0.5rem;
  pointer-events: auto;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.schedule-toast-region .alert.toast-leaving {
  opacity: 0;
  transform: translateY(-0.4rem);
}

.schedule-company-group {
  margin-bottom: 1.5rem;
}

.schedule-grid-shell {
  position: relative;
}

.schedule-grid-skeleton {
  display: none;
}

.schedule-grid-shell.is-loading > turbo-frame#schedule-grid {
  display: none;
}

.schedule-grid-shell.is-loading .schedule-grid-skeleton {
  display: block;
}

.schedule-skeleton-card {
  overflow: hidden;
}

.schedule-skeleton-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1.25fr 0.8fr 0.8fr 1fr;
  gap: 0.75rem;
  padding: 0.65rem 0;
}

.schedule-skeleton-line {
  height: 0.85rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-subtle) 0%,
    var(--bg-surface) 50%,
    var(--surface-subtle) 100%
  );
  background-size: 220% 100%;
  animation: schedule-skeleton-shimmer 1.15s linear infinite;
}

.schedule-skeleton-line--title {
  width: min(18rem, 50%);
}

.schedule-skeleton-line--short {
  width: 70%;
}

.schedule-skeleton-line--tiny {
  width: 60%;
}

@keyframes schedule-skeleton-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -20% 0; }
}

/* Schedule table container - horizontal scroll on small screens */
.schedule-table-container {
  width: 100%;
  overflow-x: auto;
}

/* Single table layout with fixed columns */
.schedule-table {
  table-layout: fixed;
  width: 100%;
  min-width: 700px; /* Ensure minimum width for horizontal scroll */
  border-collapse: collapse;
}

/* Column widths (with reorder column) */
.schedule-table th:nth-child(1) { width: 48px; }   /* drag handle */
.schedule-table th:nth-child(2) { width: 18%; }    /* posto */
.schedule-table th:nth-child(3) { width: 22%; }    /* vigia */
.schedule-table th:nth-child(4) { width: 14%; }    /* telefone */
.schedule-table th:nth-child(5) { width: 10%; }    /* entrada */
.schedule-table th:nth-child(6) { width: 10%; }    /* saída */
.schedule-table th:nth-child(7) { width: auto; }   /* status (flexible) */

/* Site group header row */
.schedule-site-row td {
  background-color: var(--surface-subtle);
  font-weight: 500;
  font-size: var(--font-sm);
  color: var(--text-muted);
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
}

.schedule-site-row td i {
  color: var(--primary);
  margin-right: 0.5rem;
}

.schedule-site-row .drag-handle {
  margin-right: 0.5rem;
}

.schedule-unassigned {
  background-color: #fffbeb;
}

.schedule-unassigned:hover td {
  background-color: #fef3c7;
}

.schedule-unassigned-cell {
  padding: 0.5rem 0.75rem;
}

.schedule-unassigned-content {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
}

.schedule-unassigned-content.has-action .schedule-unassigned-badge,
.schedule-unassigned-content.has-action .schedule-unassigned-action {
  flex: 1;
}

.schedule-unassigned-content:not(.has-action) .schedule-unassigned-badge {
  flex: 1;
}

.schedule-unassigned-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  text-align: center;
  font-weight: 600;
}

.schedule-unassigned-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
}

@media (max-width: 768px) {
  .schedule-skeleton-row {
    grid-template-columns: 1fr 1fr;
  }

  .schedule-toast-region {
    right: 1rem;
    left: 1rem;
    width: auto;
  }
}

/* --- 19. DRAG AND DROP SORTING --- */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 0.25rem;
  display: inline-flex;
  align-items: center;
}

.drag-handle:hover {
  color: var(--text-main);
}

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

/* Div-based dragging (sites_management page) */
div[data-sortable-level="company"].dragging,
div[data-sortable-level="site"].dragging,
div[data-sortable-level="sitePoint"].dragging {
  height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  pointer-events: none;
  opacity: 0;
}

/* Site level dragging (table row - schedule page) */
tr[data-sortable-level="site"].dragging {
  opacity: 0.5;
}

tr[data-sortable-level="site"].dragging td {
  background: var(--primary-light);
}

/* Rows being dragged as a group (site + its data rows) */
tr.dragging-group {
  opacity: 0.5;
}

tr.dragging-group td {
  background: var(--primary-light);
}

/* SitePoint (table row) dragging - schedule page */
tr[data-sortable-level="sitePoint"].dragging {
  opacity: 0.5;
}

tr[data-sortable-level="sitePoint"].dragging td {
  background: var(--primary-light);
}

/* Placeholder for div elements */
div.sortable-placeholder {
  background: var(--surface-subtle);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* Placeholder for table rows */
tr.sortable-placeholder {
  background: transparent;
}

tr.sortable-placeholder td,
tr.sortable-placeholder .sortable-placeholder-cell {
  background: var(--surface-subtle);
  border-top: 2px dashed var(--primary);
  border-bottom: 2px dashed var(--primary);
}

.drag-handle-cell {
  width: 64px;
  padding-left: 2.5rem !important;
}


.card-header .drag-handle {
  margin-right: 0.5rem;
}

/* 20. PAGINATION */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.pagination-info {
  font-size: var(--font-sm);
  color: var(--text-muted);
}

.pagination-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pagination-links nav.pagy {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pagination-links a,
.pagination-links span.current,
.pagination-links span.gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  font-size: var(--font-sm);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.pagination-links a {
  color: var(--text-muted);
  border: 1px solid var(--border);
  background-color: var(--bg-surface);
}

.pagination-links a:hover:not([aria-disabled="true"]) {
  color: var(--text-main);
  background-color: var(--bg-app);
  border-color: #d1d5db;
}

/* Current page - Pagy uses aria-disabled on the current page link */
.pagination-links a[aria-disabled="true"],
.pagination-links a.current,
.pagination-links span.current {
  background-color: var(--primary);
  color: white;
  border: 1px solid var(--primary);
  font-weight: 500;
  cursor: default;
  pointer-events: none;
}

.pagination-links span.gap {
  color: var(--text-muted);
  border: none;
}

/* 21. COLLAPSIBLE SECTION UTILITIES */
.hidden {
  display: none !important;
}

[data-collapsible-section-target="toggle"] span {
  display: none;
}

[data-collapsible-section-target="toggle"][data-visible="false"] span[data-show-when="false"] {
  display: inline;
}

[data-collapsible-section-target="toggle"][data-visible="true"] span[data-show-when="true"] {
  display: inline;
}

/* --- 22. SCHEDULE ACTIONS --- */
.schedule-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.schedule-action-buttons {
  display: flex;
  gap: 0.375rem;
}

.schedule-action-buttons .btn {
  white-space: nowrap;
}
