/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --orange: #ea580c;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 1rem 0;
  margin-bottom: 2rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.nav a {
  color: var(--gray-600);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: background-color 0.15s;
}

.nav a:hover {
  background-color: var(--gray-100);
  color: var(--gray-900);
}

/* Login page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: white;
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}

.login-box h1 {
  margin-bottom: 1.5rem;
  text-align: center;
  color: var(--gray-900);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--gray-700);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background-color: var(--gray-300);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}

.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 600;
}

/* Tables */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

th {
  background-color: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: 0.875rem;
}

tr:hover {
  background-color: var(--gray-50);
}

.keyword-row-expanded {
  background-color: var(--gray-50);
}

.keyword-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  padding: 0;
  text-align: left;
}

.keyword-toggle:hover {
  color: var(--primary);
}

.keyword-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border: 1px solid var(--gray-300);
  border-radius: 9999px;
  color: var(--gray-600);
  font-size: 0.875rem;
  line-height: 1;
}

.keyword-chart-row:hover {
  background-color: white;
}

.keyword-chart-row td {
  padding: 0;
  background-color: white;
}

.inline-keyword-chart {
  padding: 1.25rem 1.5rem 1.5rem 3rem;
  border-bottom: 1px solid var(--gray-200);
}

.inline-keyword-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.inline-keyword-chart-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.inline-keyword-chart-header p {
  color: var(--gray-500);
  font-size: 0.875rem;
}

.inline-keyword-chart-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.inline-chart-days {
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--gray-300);
}

.inline-chart-status {
  color: var(--gray-500);
  padding: 2rem;
  text-align: center;
}

.inline-chart-container {
  height: 260px;
  margin-bottom: 0;
}

/* Position badges */
.position {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.875rem;
}

.position-top10 {
  background-color: #dcfce7;
  color: #166534;
}

.position-11-20 {
  background-color: #fef9c3;
  color: #854d0e;
}

.position-21-50 {
  background-color: #ffedd5;
  color: #9a3412;
}

.position-51-100 {
  background-color: #fee2e2;
  color: #991b1b;
}

.position-notfound {
  background-color: var(--gray-200);
  color: var(--gray-600);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-600);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.hidden {
  display: none !important;
}

/* Alerts */
.alert {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.alert-error {
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background-color: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Client cards for dashboard */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.client-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.client-card:hover {
  box-shadow: var(--shadow-md);
}

.client-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.25rem;
}

.client-card h3 {
  font-size: 1.125rem;
  margin-bottom: 0;
}

.client-domain {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 0.75rem;
}

.client-stats {
  display: flex;
  gap: 1.5rem;
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* Visibility badge */
.visibility-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.visibility-score {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1;
}

/* Health indicators */
.health-indicator {
  font-size: 0.875rem;
  font-weight: bold;
  line-height: 1;
}

.health-up {
  color: var(--success);
}

.health-down {
  color: var(--danger);
}

.health-stable {
  color: var(--gray-400);
}

.health-neutral {
  color: var(--gray-300);
}

/* Actions column */
.actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  padding: 0.5rem;
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray-600);
  transition: background-color 0.15s, color 0.15s;
}

.btn-icon:hover {
  background-color: var(--gray-100);
  color: var(--gray-900);
}

.btn-icon.danger:hover {
  background-color: #fee2e2;
  color: var(--danger);
  border-color: #fecaca;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--gray-500);
}

.empty-state p {
  margin-bottom: 1rem;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.breadcrumb a {
  color: var(--gray-500);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
}

.breadcrumb span {
  color: var(--gray-400);
}

/* Chart container */
.chart-container {
  position: relative;
  height: 300px;
  margin-bottom: 2rem;
}

/* URL display */
.url-found {
  font-size: 0.75rem;
  color: var(--gray-500);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Position change indicators */
.change-up {
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.25rem;
}

.change-down {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.25rem;
}

.change-same {
  color: var(--gray-400);
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

/* Sortable table headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  background-color: var(--gray-100);
}

th.sortable .sort-icon {
  display: inline-block;
  width: 1rem;
  margin-left: 0.25rem;
  opacity: 0.3;
}

th.sortable .sort-icon::after {
  content: '⇅';
}

th.sortable.sort-asc .sort-icon,
th.sortable.sort-desc .sort-icon {
  opacity: 1;
}

th.sortable.sort-asc .sort-icon::after {
  content: '↑';
}

th.sortable.sort-desc .sort-icon::after {
  content: '↓';
}

/* Textarea */
textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Notes list */
.note-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.75rem;
  border-bottom: 1px solid var(--gray-100);
}

.note-item:last-child {
  border-bottom: none;
}

.note-content {
  flex: 1;
}

.note-date {
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.25rem;
}

.note-description {
  color: var(--gray-600);
  font-size: 0.875rem;
}

.note-actions {
  margin-left: 1rem;
}
