/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  background-color: #f5f5f5;
}

/* Navigation */
.main-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 50px;
  background-color: #006496;
  color: white;
}

.nav-brand {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}

.nav-brand span {
  line-height: 1;
  margin-bottom: 0;
}

.nav-logo {
  height: 30px;
  width: auto;
}

.nav-links {
  display: flex;
  gap: 20px;
}

.nav-links a {
  color: #bdc3c7;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  background-color: #004d73;
  color: white;
}

.nav-user {
  color: #90caf9;
  font-size: 13px;
  padding: 5px 10px;
  border-left: 1px solid #004d73;
  margin-left: 10px;
}

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

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

.page-header h1 {
  font-size: 24px;
  font-weight: 600;
}

/* Breadcrumb */
.breadcrumb {
  margin-bottom: 15px;
  font-size: 13px;
  color: #666;
}

.breadcrumb a {
  color: #3498db;
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* Cards */
.card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  border-bottom: 1px solid #ddd;
  background-color: #f9f9f9;
  flex-wrap: nowrap;
  min-width: max-content;
}

.card-header h1,
.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.data-table th {
  background-color: #f9f9f9;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  color: #666;
}

.data-table tr:hover {
  background-color: #fafafa;
}

.data-table.compact th,
.data-table.compact td {
  padding: 6px 10px;
  font-size: 13px;
}

.sortable {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  color: #3498db;
}

.sort-indicator {
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.5;
}

.sortable:hover .sort-indicator {
  opacity: 1;
}

.sortable.asc .sort-indicator,
.sortable.desc .sort-indicator {
  opacity: 1;
  color: #3498db;
}

/* Sortable table header */
th.sortable-header {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable-header:hover {
  background-color: #f0f0f0;
}

th.sortable-header .sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  color: #999;
  min-width: 12px;
}

th.sortable-header.sort-asc .sort-icon,
th.sortable-header.sort-desc .sort-icon {
  color: #3498db;
}

th.sortable-header.sort-asc .sort-icon::after {
  content: "▲";
}

th.sortable-header.sort-desc .sort-icon::after {
  content: "▼";
}

th.sortable-header:not(.sort-asc):not(.sort-desc) .sort-icon::after {
  content: "−";
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: white;
  color: #333;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background-color: #f5f5f5;
}

.btn-primary {
  background-color: #3498db;
  border-color: #3498db;
  color: white;
}

.btn-primary:hover {
  background-color: #2980b9;
}

.btn-danger {
  background-color: #e74c3c;
  border-color: #e74c3c;
  color: white;
}

.btn-danger:hover {
  background-color: #c0392b;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.actions {
  white-space: nowrap;
}

.actions form {
  display: inline;
}

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

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  font-size: 13px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #3498db;
}

.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.form-group small {
  display: block;
  margin-top: 4px;
  color: #888;
  font-size: 12px;
}

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

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

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding-top: 50px;
  overflow-y: auto;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 6px;
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #ddd;
}

.modal-header h2 {
  font-size: 16px;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  line-height: 1;
}

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

.modal-content form {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  padding: 15px;
  border-top: 1px solid #eee;
}

.page-info {
  color: #666;
  font-size: 13px;
}

/* Table Controls */
.table-controls {
  padding: 10px 15px;
  background-color: #f9f9f9;
  border-bottom: 1px solid #eee;
  font-size: 13px;
  color: #666;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 30px;
  color: #888;
}

.empty-state.small {
  padding: 15px;
  font-size: 13px;
}

/* Info/Warning Banners */
.info-banner {
  background-color: #e8f4fd;
  border: 1px solid #bee5eb;
  color: #0c5460;
  padding: 12px 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  font-size: 13px;
}

.info-banner a {
  color: #0c5460;
  font-weight: 500;
}

.warning-banner {
  background-color: #fff3cd;
  border: 1px solid #ffeeba;
  color: #856404;
  padding: 12px 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  font-size: 13px;
}

/* Estimate Info */
.estimate-info {
  padding: 15px;
}

.info-row {
  display: flex;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

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

.info-row .label {
  font-weight: 500;
  width: 150px;
  flex-shrink: 0;
  color: #666;
}

.info-row .value {
  flex: 1;
}

/* Edit Form */
.edit-form {
  padding: 15px;
  background-color: #f9f9f9;
  border-top: 1px solid #eee;
}

/* Hidden */
.hidden {
  display: none !important;
}

/* Tom Select Overrides */
.ts-wrapper {
  font-size: 14px;
}

.ts-wrapper.single .ts-control {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
}

.ts-wrapper.single .ts-control:hover {
  border-color: #bbb;
}

.ts-dropdown,
.ts-dropdown.single {
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100000 !important;
  position: absolute !important;
}

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

.ts-dropdown .option {
  padding: 8px 12px;
}

.ts-dropdown .option.active {
  background-color: #3498db;
  color: white;
}

/* Tree View */
.tree-view {
  padding: 15px;
}

.tree-node {
  margin-bottom: 5px;
}

.tree-node-header {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  background-color: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
  gap: 8px;
}

.tree-node-header:hover {
  background-color: #f0f0f0;
}

.tree-toggle {
  font-size: 10px;
  color: #666;
  transition: transform 0.2s;
  width: 15px;
}

.tree-node.expanded > .tree-node-header .tree-toggle {
  transform: rotate(90deg);
}


.tree-label {
  flex: 1;
  font-size: 13px;
}

.tree-label strong {
  font-weight: 600;
}

.tree-actions {
  display: flex;
  gap: 5px;
}

.tree-children {
  display: none;
  margin-left: 25px;
  padding: 10px 0 10px 15px;
  border-left: 2px solid #e0e0e0;
}

.tree-node.expanded > .tree-children {
  display: block;
}

.tree-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: #666;
  border-bottom: 1px solid #eee;
  margin-bottom: 8px;
}

.sa-details {
  padding: 8px 10px;
  background-color: #fafafa;
  border-radius: 4px;
  margin-bottom: 10px;
  font-size: 12px;
}

.sa-details .detail-row {
  display: flex;
  gap: 20px;
}

.sa-details .description {
  margin-top: 5px;
  color: #666;
}

/* Service Assignment styling */
.service-assignment > .tree-node-header {
  background-color: #e3f2fd;
  border-color: #90caf9;
}

.project > .tree-node-header {
  background-color: #f3e5f5;
  border-color: #ce93d8;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 10px;
  background-color: #e0e0e0;
  color: #666;
  margin-left: 5px;
}

.badge-custom {
  background-color: #fff3e0;
  color: #e65100;
}

.badge-info {
  background-color: #e3f2fd;
  color: #1565c0;
}

.badge-muted {
  background-color: #f5f5f5;
  color: #9e9e9e;
}

/* Cost Summary */
.cost-summary {
  padding: 15px;
}

.cost-summary h2 {
  font-size: 14px;
  margin-bottom: 15px;
}

.cost-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}

.cost-item {
  padding: 12px;
  background-color: #f9f9f9;
  border-radius: 4px;
  text-align: center;
}

.cost-item.total {
  background-color: #e8f5e9;
}

.cost-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 5px;
}

.cost-value {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

/* Settings Tabs */
.settings-tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 20px;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0;
}

.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #333;
}

.tab-btn.active {
  color: #3498db;
  border-bottom-color: #3498db;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Muted text */
.muted {
  color: #888;
}

/* Error page */
.error-page {
  text-align: center;
  padding: 50px;
}

.error-page h1 {
  font-size: 24px;
  margin-bottom: 15px;
}

.error-message {
  color: #e74c3c;
  margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .page-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .tree-children {
    margin-left: 10px;
    padding-left: 10px;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 8px;
  }
}

/* Supporting Items Styling */
.supporting-item-row {
  background-color: #f8f9fa;
}

.supporting-item-row td {
  color: #666;
  font-size: 0.9em;
}

.supporting-indicator {
  color: #6c757d;
  margin-right: 5px;
}

.supporting-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  background-color: #6c757d;
  border-radius: 3px;
  margin-right: 5px;
  text-transform: uppercase;
}
