/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --success: #10b981;
  --success-light: #ecfdf5;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

/* Login Page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.login-card .subtitle {
  color: var(--gray-500);
  margin-bottom: 32px;
}

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

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
  text-decoration: none;
  text-align: center;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  width: 100%;
  margin-top: 12px;
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

/* Error messages */
.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

.error-message.visible {
  display: block;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: var(--gray-500);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* OTP sent message */
.otp-sent-message {
  background: var(--success-light);
  color: var(--success);
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 14px;
}

/* Dashboard Layout */
.dashboard {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.2s ease, padding 0.2s ease;
}

.sidebar.collapsed {
  width: 60px;
  padding: 20px 10px;
}

.sidebar.collapsed .sidebar-header h1,
.sidebar.collapsed .sidebar-header .user-info,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-footer .btn span {
  display: none;
}

.sidebar.collapsed .nav-item {
  padding: 10px;
  text-align: center;
}

.sidebar.collapsed .sidebar-footer .btn {
  padding: 10px;
}

.sidebar-toggle {
  position: absolute;
  top: 20px;
  right: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--gray-200);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--gray-500);
  z-index: 10;
  transition: transform 0.2s ease;
}

.sidebar-toggle:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.sidebar.collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

.sidebar-header {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 20px;
  position: relative;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
}

.sidebar-header .user-info {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--gray-700);
  text-decoration: none;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 14px;
}

.nav-item:hover {
  background: var(--gray-100);
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

.nav-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding-top: 20px;
  border-top: 1px solid var(--gray-200);
}

.sidebar-footer .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
  min-width: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

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

/* Stats bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-card .label {
  font-size: 13px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  margin-top: 4px;
}

.stat-card .value.danger {
  color: var(--danger);
}

.stat-card .value.warning {
  color: var(--warning);
}

/* Article cards */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tenant groups */
.tenant-group {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.tenant-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: background-color 0.15s;
}

.tenant-group-header:hover {
  background: var(--gray-50);
}

.tenant-group.expanded .tenant-group-header {
  border-bottom-color: var(--gray-200);
}

.tenant-group-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tenant-group-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}

.tenant-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
}

.tenant-group-count.has-high {
  background: var(--danger-light);
  color: var(--danger);
}

.tenant-group-count.has-medium {
  background: var(--warning-light);
  color: var(--warning);
}

.tenant-group-toggle {
  font-size: 12px;
  color: var(--gray-400);
  transition: transform 0.2s;
}

.tenant-group.expanded .tenant-group-toggle {
  transform: rotate(180deg);
}

.tenant-group-articles {
  display: none;
  padding: 0;
}

.tenant-group.expanded .tenant-group-articles {
  display: block;
}

.tenant-group-articles .article-card {
  border-radius: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--gray-100);
}

.tenant-group-articles .article-card:last-child {
  border-bottom: none;
}

.tenant-group-articles .article-card .tenant-name {
  display: none;
}

.tenant-group-footer {
  padding: 12px 20px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-100);
}

.view-older-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.view-older-link:hover {
  text-decoration: underline;
}

.article-card {
  background: white;
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-left: 4px solid var(--gray-300);
}

.article-card.high-priority {
  border-left-color: var(--danger);
  background: var(--danger-light);
}

.article-card.medium-priority {
  border-left-color: var(--warning);
  background: var(--warning-light);
}

.article-card.dismissed {
  opacity: 0.6;
  border-left-color: var(--gray-300);
  background: var(--gray-50);
}

.dismissed-badge {
  display: inline-block;
  padding: 2px 6px;
  background: var(--gray-200);
  color: var(--gray-500);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  margin-left: 8px;
}

.article-card .article-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}

.article-card .tenant-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.article-card .article-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--gray-900);
  text-decoration: none;
  line-height: 1.4;
}

.article-card .article-title:hover {
  text-decoration: underline;
}

.article-card .article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 8px;
}

.article-card .keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.keyword-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.keyword-tag.critical {
  background: var(--danger);
  color: white;
}

.keyword-tag.high {
  background: var(--warning);
  color: white;
}

.article-card .article-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* Filters */
.filters-bar {
  background: white;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.filters-bar select,
.filters-bar input {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 14px;
}

/* Tenant table */
.tenant-table {
  width: 100%;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tenant-table th,
.tenant-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

.tenant-table th {
  background: var(--gray-50);
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tenant-table tr:last-child td {
  border-bottom: none;
}

.tenant-table tr:hover {
  background: var(--gray-50);
}

.priority-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.priority-badge.high {
  background: var(--danger-light);
  color: var(--danger);
}

.priority-badge.normal {
  background: var(--gray-100);
  color: var(--gray-700);
}

.priority-badge.low {
  background: var(--success-light);
  color: var(--success);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--gray-500);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Settings */
.settings-section {
  background: white;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  max-width: 600px;
}

.settings-section h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.settings-section .form-group {
  margin-bottom: 24px;
}

.settings-section .btn-primary {
  width: auto;
}

/* Keywords settings */
.keywords-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

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

.keyword-level {
  display: flex;
  flex-direction: column;
}

.keyword-level-label {
  font-weight: 600;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
  width: fit-content;
}

.keyword-level-label.critical {
  background: var(--danger-light);
  color: var(--danger);
}

.keyword-level-label.high {
  background: #fef3c7;
  color: #b45309;
}

.keyword-level-label.medium {
  background: #dbeafe;
  color: #1d4ed8;
}

.keyword-level-label.low {
  background: var(--gray-100);
  color: var(--gray-700);
}

.keyword-level textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

.keyword-level textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

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

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }

  .main-content {
    padding: 16px;
  }

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

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .article-card .article-header {
    flex-direction: column;
  }
}
