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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f5f7fa;
  color: #333;
  line-height: 1.6;
}

a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.header {
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: bold;
  color: #007bff;
}

.nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: #555;
  font-weight: 500;
}

.nav-link:hover { color: #007bff; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-name { font-weight: 500; }
.user-role { 
  background: #e9ecef; 
  padding: 0.125rem 0.5rem; 
  border-radius: 12px; 
  font-size: 0.85rem;
}

.inline-form { display: inline; }

.main-content {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.footer {
  text-align: center;
  padding: 2rem;
  color: #666;
  margin-top: 3rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.btn-primary { background: #007bff; color: white; }
.btn-primary:hover { background: #0056b3; }

.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #545b62; }

.btn-success { background: #28a745; color: white; }
.btn-success:hover { background: #1e7e34; }

.btn-danger { background: #dc3545; color: white; }
.btn-danger:hover { background: #c82333; }

.btn-warning { background: #ffc107; color: #212529; }
.btn-warning:hover { background: #e0a800; }

.btn-info { background: #17a2b8; color: white; }
.btn-info:hover { background: #138496; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.btn-block { width: 100%; justify-content: center; }

.btn-logout {
  background: transparent;
  border: 1px solid #ddd;
  padding: 0.375rem 0.75rem;
}
.btn-logout:hover { background: #f8f9fa; }

/* Forms */
.form-control {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: #495057;
}

.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 200px;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e9ecef;
}

.checkbox-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: normal;
}

.form-range {
  width: 100%;
}

/* Cards */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header h1 { font-size: 2rem; color: #212529; }

.subtitle { color: #6c757d; margin-top: 0.25rem; }

.form-card {
  background: white;
  border-radius: 10px;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.form-card h2 {
  margin-bottom: 1.5rem;
  color: #495057;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-card h2 small {
  font-size: 0.85rem;
  color: #6c757d;
  font-weight: normal;
}

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

.stat-card {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  font-size: 2.5rem;
  color: #007bff;
}

.stat-info h3 {
  font-size: 2rem;
  margin: 0;
  color: #212529;
}

.stat-info p {
  margin: 0;
  color: #6c757d;
  font-size: 0.9rem;
}

/* Tables */
.table-responsive { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

.data-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #495057;
}

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

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-success { background: #d4edda; color: #155724; }
.badge-secondary { background: #e2e3e5; color: #383d41; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-danger { background: #f8d7da; color: #721c24; }

.badge-role-admin { background: #007bff; color: white; }
.badge-role-manager { background: #17a2b8; color: white; }
.badge-role-viewer { background: #6c757d; color: white; }

.status {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-success { background: #d4edda; color: #155724; }
.status-failed { background: #f8d7da; color: #721c24; }

/* Pagination */
.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 2rem;
}

.pagination .page-link {
  padding: 0.5rem 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-decoration: none;
  color: #007bff;
}

.pagination .page-link.active {
  background: #007bff;
  color: white;
  border-color: #007bff;
}

/* Info Box */
.info-box {
  background: #e7f3ff;
  border-left: 4px solid #007bff;
  padding: 1.5rem;
  border-radius: 6px;
  margin-top: 2rem;
}

.info-box h3 { margin-bottom: 1rem; color: #0056b3; }
.info-box ol { margin-left: 1.5rem; }
.info-box li { margin-bottom: 0.5rem; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: #6c757d;
}

/* Utilities */
.text-preview {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mt-2 { margin-top: 2rem; }
.mb-2 { margin-bottom: 2rem; }

/* Alerts */
.alert {
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

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

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

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

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

/* Settings layouts */
.settings-page .form-card { margin-bottom: 1.5rem; }

.polling-configs .config-item {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fafbfc;
}

.config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.config-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.last-run {
  margin-left: 1rem;
  color: #6c757d;
}

.models-list, .rules-list, .users-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.model-item, .rule-item, .user-item {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.model-handle {
  cursor: grab;
  color: #adb5bd;
  margin-right: 0.5rem;
}

.model-info {
  flex: 1;
  min-width: 200px;
}

.model-info small {
  display: block;
  color: #6c757d;
  font-size: 0.85rem;
}

.model-settings {
  display: flex;
  gap: 1rem;
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

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

.action-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  transition: all 0.2s;
}

.action-item:hover {
  background: #e9ecef;
  text-decoration: none;
  color: #212529;
}

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

.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.activity-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f8f9fa;
  border-radius: 6px;
}

.activity-icon {
  font-size: 1.25rem;
  color: #007bff;
}

.activity-content {
  flex: 1;
}

.activity-content small {
  color: #6c757d;
}

/* Responsive */
@media (max-width: 768px) {
  .header-content { flex-direction: column; gap: 1rem; }
  .nav { justify-content: center; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .form-row { flex-direction: column; }
  .form-row .form-group { min-width: 100%; }
}

/* JSON in popup */
.json-old, .json-new {
  background: #f5f5f5;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: 200px;
}

.json-old { border-left: 3px solid #dc3545; }
.json-new { border-left: 3px solid #28a745; margin-top: 0.5rem; }