/*
 * SERAPO CRM - Central Theme
 * One consistent professional theme for the whole app
 */

:root {
  --sidebar-width: 200px;
  --sidebar-bg: #ffffff;
  --sidebar-hover: #f1f5f9;
  --sidebar-active-bg: #eff6ff;
  --brand: #2563eb;
  --content-bg: #fafafa;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border-color: #ececf0;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--content-bg);
  color: var(--text-main);
  font-size: 0.9rem;
}

/* ===== SIDEBAR ===== */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: var(--text-muted);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  border-right: 1px solid var(--border-color);
  transition: transform 0.25s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.app-sidebar .sidebar-brand {
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-sidebar .sidebar-brand .brand-badge {
  font-size: 0.55rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}

.app-sidebar .nav-section {
  padding: 0.75rem 1rem 0.2rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #9ca3af;
  font-weight: 700;
}

.app-sidebar .nav-link {
  color: #4b5563;
  padding: 0.35rem 0.75rem;
  margin: 0.1rem 0.5rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.75rem;
  transition: all 0.15s ease;
}

.app-sidebar .nav-link i {
  font-size: 0.9rem;
  width: 16px;
  text-align: center;
  color: #9ca3af;
}

.app-sidebar .nav-link:hover {
  background-color: var(--sidebar-hover);
  color: var(--text-main);
}

.app-sidebar .nav-link.active {
  background-color: var(--sidebar-active-bg);
  color: var(--brand);
  font-weight: 600;
}

.app-sidebar .nav-link.active i {
  color: var(--brand);
}

.app-sidebar .sidebar-footer {
  margin-top: auto;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.app-sidebar .sidebar-footer .dropdown-toggle {
  color: var(--text-main) !important;
}

/* ===== MAIN CONTENT ===== */
.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.app-topbar .page-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-main);
}

.app-content {
  padding: 1rem;
  flex: 1;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-main);
}

/* ===== CARDS ===== */
.card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: none;
}

.card-header {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  padding: 1rem 1.25rem;
  color: var(--text-main);
}

/* ===== STAT CARDS ===== */
.stat-card {
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  background: #fff;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
}

.stat-card .stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* ===== TABLES ===== */
.table {
  margin-bottom: 0;
}

.table thead th {
  background: #fafafa;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  padding: 0.7rem 1rem;
}

.table tbody td {
  vertical-align: middle;
  border-color: var(--border-color);
  padding: 0.7rem 1rem;
}

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

/* ===== BUTTONS ===== */
.btn {
  font-weight: 500;
  border-radius: 8px;
}

.btn-sm {
  border-radius: 6px;
}

.btn-primary {
  background-color: var(--brand);
  border-color: var(--brand);
}

.btn-primary:hover {
  background-color: #1d4ed8;
  border-color: #1d4ed8;
}

/* ===== FORMS ===== */
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border-color);
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 0.2rem rgba(59,130,246,0.15);
}

.form-label {
  font-weight: 600;
  font-size: 0.8rem;
  color: #334155;
}

/* ===== CHOICES.JS ===== */
.choices {
  margin-bottom: 0;
  min-width: 0;
}

.choices__inner {
  min-height: 38px;
  padding: 0.375rem 2rem 0.375rem 0.75rem;
  background-color: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: inherit;
}

.choices--sm .choices__inner {
  min-height: 31px;
  padding: 0.25rem 1.75rem 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.choices__list--single {
  padding: 0;
}

.choices__list--dropdown,
.choices__list[aria-expanded] {
  z-index: 1100;
  border-color: var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.choices__list--dropdown .choices__item,
.choices__list[aria-expanded] .choices__item {
  font-size: 0.8rem;
}

.choices__input {
  margin-bottom: 0;
  border-color: var(--border-color);
  background-color: #fff;
}

.choices.is-focused .choices__inner,
.choices.is-open .choices__inner {
  border-color: var(--brand);
  box-shadow: 0 0 0 0.2rem rgba(59,130,246,0.15);
}

.choices.is-disabled .choices__inner {
  background-color: #e9ecef;
}

/* ===== LOGIN ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--content-bg);
  padding: 1rem;
}

.login-card {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}

.login-card .login-brand {
  text-align: center;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 0.25rem;
}

/* ===== MOBILE ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1035;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .mobile-toggle {
    display: block;
  }
  .sidebar-backdrop.show {
    display: block;
  }
}

@media (max-width: 767.98px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-main,
  .app-content,
  .card,
  .card-body,
  .card-header {
    min-width: 0;
  }

  .app-content {
    padding: 0.75rem;
  }

  .app-topbar {
    min-height: 52px;
    padding: 0.25rem 0.75rem;
  }

  .mobile-toggle {
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .app-topbar .page-title {
    font-size: 0.85rem;
  }

  .btn-sm {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .form-control-sm,
  .form-select-sm,
  .choices--sm .choices__inner {
    min-height: 38px;
  }

  .badge,
  code,
  .font-monospace {
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .accordion-button {
    min-width: 0;
    flex-wrap: wrap;
    overflow-wrap: anywhere;
  }

  .accordion-button .badge {
    margin-top: 0.35rem;
  }

  pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .mobile-table-wrap {
    overflow: visible;
  }

  .mobile-card-table {
    min-width: 0 !important;
  }

  .mobile-card-table,
  .mobile-card-table tbody,
  .mobile-card-table tr,
  .mobile-card-table td {
    display: block;
    width: 100% !important;
  }

  .mobile-card-table thead {
    display: none;
  }

  .mobile-card-table tbody {
    padding: 0.75rem;
    background: #f8fafc;
  }

  .mobile-card-table tbody tr {
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
  }

  .mobile-card-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .mobile-card-table tbody tr.collapse:not(.show) {
    display: none;
  }

  .mobile-card-table tbody td {
    display: grid;
    grid-template-columns: minmax(5.75rem, 35%) minmax(0, 1fr);
    gap: 0.65rem;
    align-items: center;
    min-width: 0;
    max-width: none !important;
    padding: 0.5rem 0.65rem !important;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .mobile-card-table tbody td:last-child {
    border-bottom: 0;
  }

  .mobile-card-table tbody td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .mobile-card-table tbody td[colspan] {
    display: block;
    text-align: center !important;
  }

  .mobile-card-table tbody td[colspan]::before {
    content: none;
  }

  .mobile-card-table .text-truncate {
    max-width: 100% !important;
    overflow: visible;
    text-overflow: clip;
    white-space: normal !important;
  }

  .mobile-card-table td form,
  .mobile-card-table td .d-flex {
    min-width: 0;
    flex-wrap: wrap;
  }

  .mobile-metric-table,
  .mobile-metric-table tbody,
  .mobile-metric-table tr {
    display: block;
    width: 100% !important;
  }

  .mobile-metric-table thead {
    display: none;
  }

  .mobile-metric-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .mobile-metric-table tbody td {
    display: flex;
    min-width: 0;
    min-height: 66px;
    padding: 0.65rem !important;
    flex-direction: column;
    justify-content: center;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
  }

  .mobile-metric-table tbody td::before {
    content: attr(data-label);
    margin-bottom: 0.15rem;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .mobile-key-value-table {
    table-layout: fixed;
    width: 100%;
  }

  .mobile-key-value-table th {
    width: 36% !important;
    padding-left: 0 !important;
  }

  .mobile-key-value-table td {
    min-width: 0;
    padding-right: 0 !important;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .mobile-page-heading {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .client-wlb-list .badge {
    width: 100%;
  }

  .client-performance-card .client-performance-url {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .serp-page-heading,
  .serp-page-controls {
    width: 100%;
  }

  .serp-page-controls {
    align-items: stretch !important;
  }

  .serp-date-form {
    flex: 1 1 100%;
  }

  .serp-date-input {
    flex: 1 1 120px;
    min-width: 120px;
    width: auto !important;
  }

  .serp-results-table-wrap {
    overflow: visible;
  }

  .serp-results-table {
    min-width: 0 !important;
  }

  .serp-results-table,
  .serp-results-table tbody,
  .serp-results-table tr,
  .serp-results-table td {
    display: block;
    width: 100% !important;
  }

  .serp-results-table thead {
    display: none;
  }

  .serp-results-table tbody tr {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
  }

  .serp-results-table tbody tr:last-child {
    border-bottom: 0;
  }

  .serp-results-table tbody td {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: start;
    padding: 0.35rem 0 !important;
    border: 0;
    text-align: left !important;
  }

  .serp-results-table tbody td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .serp-provider-grid {
    gap: 0.75rem !important;
    margin: 0;
    min-width: 0;
  }

  .serp-provider-column {
    width: 100%;
    padding: 0 0 0.65rem;
    border-right: 0 !important;
    border-bottom: 1px solid var(--border-color);
  }

  .serp-provider-column:last-child {
    padding-bottom: 0;
    border-bottom: 0;
  }

  .serp-result-item {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start !important;
  }

  .serp-result-url {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .serp-final-ownership-form {
    min-width: 0;
    width: 100%;
  }

  .serp-final-controls {
    min-width: 0;
    flex-wrap: wrap;
  }

  .serp-final-ownership-form .form-select {
    width: auto !important;
    min-width: 0;
    flex: 1 1 auto;
  }

  .serp-final-ownership-form .choices {
    width: auto !important;
    min-width: 0;
    flex: 1 1 auto;
  }

  .serp-final-decision {
    margin-top: 0.25rem;
    padding: 0.5rem !important;
    border-radius: 6px;
  }

  .serp-score-cell strong {
    font-size: 0.95rem !important;
  }
}

/* ===== MISC ===== */
hr {
  border-color: var(--border-color);
  opacity: 1;
}

a {
  color: var(--brand);
}
